Marsyas  0.5.0-beta1
/Users/jleben/code/marsyas/src/marsyas/Thread.h
Go to the documentation of this file.
00001 /***************************************************/
00012 /***************************************************/
00013 
00014 #if !defined(__THREAD_H)
00015 #define __THREAD_H
00016 
00017 
00018 #include <marsyas/common_header.h>
00019 #include <marsyas/common_source.h>
00020 
00021 #if (defined(MARSYAS_LINUX) || defined(MARSYAS_CYGWIN) || defined(MARSYAS_MACOSX))
00022 #include <pthread.h>
00023 #define THREAD_TYPE
00024 typedef pthread_t THREAD_HANDLE;
00025 typedef void * THREAD_RETURN;
00026 typedef void * (*THREAD_FUNCTION)(void *);
00027 typedef pthread_mutex_t MUTEX;
00028 #endif
00029 
00030 
00031 
00032 #if defined(MARSYAS_WIN32)
00033 
00034 #define _WINSOCKAPI_
00035 
00036 #ifndef NOMINMAX
00037 #define NOMINMAX
00038 #endif
00039 
00040 #include <windows.h>
00041 #include <process.h>
00042 #define THREAD_TYPE __stdcall
00043 typedef unsigned long THREAD_HANDLE;
00044 typedef unsigned THREAD_RETURN;
00045 typedef unsigned (__stdcall *THREAD_FUNCTION)(void *);
00046 typedef CRITICAL_SECTION MUTEX;
00047 
00048 #endif
00049 
00050 
00051 #if defined(MARSYAS_MINGW)
00052 
00053 #define _WINSOCKAPI_
00054 
00055 #ifndef NOMINMAX
00056 #define NOMINMAX
00057 #endif
00058 
00059 #include <windows.h>
00060 #include <process.h>
00061 #define THREAD_TYPE __stdcall
00062 typedef unsigned long THREAD_HANDLE;
00063 typedef unsigned THREAD_RETURN;
00064 typedef unsigned (__stdcall *THREAD_FUNCTION)(void *);
00065 typedef CRITICAL_SECTION MUTEX;
00066 
00067 #endif
00068 
00069 
00070 namespace Marsyas
00071 {
00072 
00073 class Thread
00074 {
00075 public:
00077   Thread();
00078 
00080   ~Thread();
00081 
00083 
00087   bool start( THREAD_FUNCTION routine, void * ptr = NULL );
00088 
00090 
00096   bool wait( long milliseconds = -1 );
00097 
00099   static void test(void);
00100 
00101 protected:
00102 
00103   THREAD_HANDLE thread;
00104 
00105 };
00106 
00107 class Mutex
00108 {
00109 public:
00111   Mutex();
00112 
00114   ~Mutex();
00115 
00117   void lock(void);
00118 
00120   void unlock(void);
00121 
00122 protected:
00123 
00124   MUTEX mutex;
00125 
00126 };
00127 
00128 }//namespace Marsyas
00129 
00130 #endif // defined(__THREAD_H)