00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "mxthread.h"
00017
00018
00019 namespace mx
00020 {
00021
00022 int thread_exec(void *ptr)
00023 {
00024 mxThread *thread_pointer = (mxThread*) ptr;
00025 return thread_pointer->threadExec();
00026 }
00027
00028 int thread_execute(void *data)
00029 {
00030
00031 mxExec *e = (mxExec*)data;
00032 return e->threadExec();
00033 }
00034
00035
00036 mxMutex::mxMutex()
00037 {
00038 m = SDL_CreateMutex();
00039 }
00040
00041 mxMutex::~mxMutex()
00042 {
00043 if(m)
00044 SDL_DestroyMutex(m);
00045 }
00046
00047 int mxMutex::lockMutex()
00048 {
00049 return SDL_mutexP(m);
00050 }
00051
00052 int mxMutex::unlockMutex()
00053 {
00054
00055 return SDL_mutexV(m);
00056 }
00057
00058 mxThread::mxThread()
00059 {
00060 thread_identifier = 0;
00061 }
00062
00063 mxThread::~mxThread()
00064 {
00065 threadStop();
00066
00067 }
00068
00069 void mxThread::threadRun()
00070 {
00071 thread_identifier = SDL_CreateThread(thread_exec, (void*)this);
00072
00073 }
00074
00075 void mxThread::threadStop()
00076 {
00077
00078 if(thread_identifier != 0)
00079 SDL_KillThread(thread_identifier);
00080
00081 thread_identifier = 0;
00082
00083 }
00084
00085 void mxThread::threadWait()
00086 {
00087
00088 if(thread_identifier != 0)
00089 SDL_WaitThread(thread_identifier, 0);
00090
00091 }
00092
00093
00094
00095
00096
00097
00098 }
00099
00100
00101