#include <thread.h>
Inheritance diagram for Thread::

Public Methods | |
| Thread () | |
| virtual | ~Thread () |
| int | Start (void *arg) |
Protected Methods | |
| int | Run (void *arg) |
| virtual void | Setup () |
| virtual void | Execute (void *) |
| void* | Arg () const |
| void | Arg (void *a) |
| void | Mutex (pthread_mutex_t *a) |
| pthread_mutex_t* | Mutex () const |
| virtual void | Lock () |
| virtual void | Unlock () |
Static Protected Methods | |
| void* | EntryPoint (void *) |
Private Attributes | |
| pthread_t | a_thread |
| void* | Arg_ |
| pthread_mutex_t* | p_mutex |
Mutex sharing
Definition at line 32 of file thread.h.
|
|
Default constructor If you overload this, Make sure your class calls Thread() to setup the mutex. Definition at line 29 of file thread.cpp. Referenced by myThread::myThread().
00030 {
00031 p_mutex = NULL;
00032 agent_new(&p_mutex);
00033 {assert(p_mutex != NULL);}
00034 pthread_mutex_init(p_mutex, NULL);
00035 }
|
|
|
Default destructor Overload this, but include the following code in your destructor Definition at line 42 of file thread.cpp. 00043 {
00044 {assert(p_mutex != NULL);}
00045 pthread_mutex_destroy(p_mutex);
00046 }
|
|
|
Set the current argument (casted to void*)
Definition at line 53 of file thread.h. 00053 {Arg_ = a;}
|
|
|
Return the current argument casted to void*
Definition at line 47 of file thread.h. Referenced by EntryPoint(), and Start().
00047 {return Arg_;}
|
|
|
Function called from Start Takes a Thread pointer as argument NOTE: Don't EVER CALL THIS. Start will call this
Definition at line 90 of file thread.cpp. |
|
|
Actual thread code Overload this in your thread, or it wont do anything Reimplemented in myThread. Definition at line 114 of file thread.cpp. Referenced by Run().
00115 {
00116 // Your code goes here
00117 }
|
|
|
Lock the mutex associated with this thread
Definition at line 123 of file thread.cpp. 00124 {
00125 pthread_mutex_lock(p_mutex);
00126 }
|
|
|
Return the current mutex (for mutex sharing)
Definition at line 63 of file thread.h. 00063 {return p_mutex;}
|
|
|
Set the mutex (for mutex sharing)
Definition at line 58 of file thread.h. 00058 {p_mutex = a;}
|
|
|
Default entrypoint for threads Calls Setyp and Execute(arg)
Definition at line 72 of file thread.cpp. Referenced by EntryPoint().
|
|
|
Handle the setup of your thread Overload this in your thread, or it wont do anything Reimplemented in myThread. Definition at line 103 of file thread.cpp. Referenced by Run().
00104 {
00105 // Do any setup here
00106 }
|
|
|
Start the thread running in its own context Pass any argument you want as a void *, but make sure your thread knows how to handle it.
Definition at line 56 of file thread.cpp. Referenced by main().
00057 {
00058 Arg(arg); // store user data
00059 int code = pthread_create(&a_thread, NULL, (void *(*) (void *))
00060 Thread::EntryPoint, (void *) this);
00061 return code;
00062 }
|
|
|
Unlock the mutex associated with this thread
Definition at line 132 of file thread.cpp. 00133 {
00134 pthread_mutex_unlock(p_mutex);
00135 }
|
|
|
Argument storage |
|
|
|
|
|
Mutex for locking |
1.2.8.1 written by Dimitri van Heesch,
© 1997-2001