#include <mtasker.hh>
Collaboration diagram for MTasker< EventKey, EventVal >:
Public Types | |
typedef void | tfunc_t (void *) |
type of the pointer that starts a thread | |
Public Member Functions | |
MTasker (size_t stacksize=8192) | |
Constructor. | |
int | waitEvent (const EventKey &key, EventVal *val=0, unsigned int timeout=0) |
puts a thread to sleep waiting until a specified event arrives | |
void | yield () |
yields control to the kernel or other threads | |
int | sendEvent (const EventKey &key, const EventVal *val=0) |
reports that an event took place for which threads may be waiting | |
void | getEvents (std::vector< EventKey > &events) |
gives access to the list of Events threads are waiting for | |
void | makeThread (tfunc_t *start, void *val) |
launches a new thread | |
bool | schedule () |
needs to be called periodically so threads can run and housekeeping can be performed | |
bool | noProcesses () |
returns true if there are no processes | |
unsigned int | numProcesses () |
returns the number of processes running | |
int | getTid () |
Returns the current Thread ID (tid). |
EventKey | Type of the key with which events are to be identified. Defaults to int. |
EventVal | Type of the content or value of an event. Defaults to int. Cannot be set to void. |
Definition at line 16 of file mtasker.hh.
|
Constructor with a small default stacksize. If any of your threads exceeds this stack, your application will crash. This limit applies solely to the stack, the heap is not limited in any way. If threads need to allocate a lot of data, the use of new/delete is suggested. Definition at line 46 of file mtasker.hh. |
|
The kernel can call this to get a list of Events threads are waiting for. This is very useful to setup 'select' or 'poll' or 'aio' events needed to satisfy these requests. getEvents clears the events parameter before filling it.
Definition at line 287 of file mtasker.cc. |
|
Processes can call this to get a numerical representation of their current thread ID. This can be useful for logging purposes. Definition at line 308 of file mtasker.cc. |
|
The kernel can call this to make a new thread, which starts at the function start and gets passed the val void pointer.
Definition at line 202 of file mtasker.cc. References MTasker< EventKey, EventVal >::tfunc_t. |
|
Call this to check if no processes are running anymore
Definition at line 265 of file mtasker.cc. |
|
Call this to perhaps limit activities if too many threads are running
Definition at line 274 of file mtasker.cc. |
|
The kernel should call this function every once in a while. It makes sense to call this function if you:
Definition at line 231 of file mtasker.cc. |
|
From the kernel loop, sendEvent can be called to report that something occured for which there may be waiters.
Definition at line 177 of file mtasker.cc. |
|
Threads can call waitEvent to register that they are waiting on an event with a certain key. If so desidered, the event can carry data which is returned in val in case that is non-zero. Furthermore, a timeout can be specified in seconds. Only one thread can be waiting on a key, results of trying to have more threads waiting on the same key are undefined.
Definition at line 146 of file mtasker.cc. |
|
Hands over control to the kernel, allowing other processes to run, or events to arrive Definition at line 165 of file mtasker.cc. |