00001
00016 #include "thread.h"
00017 #include "mem/memory.cpp"
00018
00019 #ifndef _CORE_THREAD_CPP_
00020 #define _CORE_THREAD_CPP_
00021
00022 static const char thdid[] = "\100$ Free Agent: thread.cpp, v 0.1 2002/05/29 red0x Exp $";
00023
00029 Thread::Thread()
00030 {
00031 p_mutex = NULL;
00032 agent_new(&p_mutex);
00033 {assert(p_mutex != NULL);}
00034 pthread_mutex_init(p_mutex, NULL);
00035 }
00036
00042 Thread::~Thread()
00043 {
00044 {assert(p_mutex != NULL);}
00045 pthread_mutex_destroy(p_mutex);
00046 }
00047
00056 int Thread::Start(void * arg)
00057 {
00058 Arg(arg);
00059 int code = pthread_create(&a_thread, NULL, (void *(*) (void *))
00060 Thread::EntryPoint, (void *) this);
00061 return code;
00062 }
00063
00072 int Thread::Run(void * arg)
00073 {
00074 Setup();
00075 Execute(arg);
00076 return 0;
00077 }
00078
00079
00090 void *Thread::EntryPoint(void *pthis)
00091 {
00092 Thread * pt = (Thread*)pthis;
00093 pt->Run(pt->Arg());
00094 return pt;
00095 }
00096
00103 void Thread::Setup()
00104 {
00105
00106 }
00107
00114 void Thread::Execute(void* arg)
00115 {
00116
00117 }
00118
00123 void Thread::Lock()
00124 {
00125 pthread_mutex_lock(p_mutex);
00126 }
00127
00132 void Thread::Unlock()
00133 {
00134 pthread_mutex_unlock(p_mutex);
00135 }
00136 #endif