00001 00005 #ifndef RAZORBACK_THREAD_H 00006 #define RAZORBACK_THREAD_H 00007 00008 #include <razorback/visibility.h> 00009 #include <razorback/types.h> 00010 #include <razorback/lock.h> 00011 #include <razorback/api.h> 00012 #ifdef _MSC_VER 00013 typedef DWORD rzb_thread_t; 00014 #else //_MSC_VER 00015 #include <pthread.h> 00016 typedef pthread_t rzb_thread_t; 00017 #endif //_MSC_VER 00018 00019 #ifdef __cplusplus 00020 extern "C" { 00021 #endif 00022 00026 struct Thread 00027 { 00028 #ifdef _MSC_VER 00029 HANDLE hThread; 00030 #endif //_MSC_VER 00031 rzb_thread_t iThread; 00032 struct Mutex * mMutex; 00033 bool bRunning; 00034 void *pUserData; 00035 char *sName; 00036 struct RazorbackContext *pContext; 00037 void (*mainFunction) (struct Thread *); 00038 bool bShutdown; 00039 int refs; 00040 //void (*interrupt)(struct Thread *); ///< Cancellation handler for a blocking function. 00041 }; 00042 00050 SO_PUBLIC extern struct Thread *Thread_Launch (void (*function) (struct Thread *), 00051 void *userData, char *name, 00052 struct RazorbackContext *context); 00053 00059 SO_PUBLIC extern struct RazorbackContext * Thread_ChangeContext(struct Thread *thread, 00060 struct RazorbackContext *context); 00061 00066 SO_PUBLIC extern struct RazorbackContext * Thread_GetContext(struct Thread *p_pThread); 00067 00071 SO_PUBLIC extern struct RazorbackContext * Thread_GetCurrentContext(void); 00072 00076 SO_PUBLIC extern void Thread_Destroy (struct Thread *thread); 00077 00082 SO_PUBLIC extern bool Thread_IsRunning (struct Thread *thread); 00083 00088 SO_PUBLIC extern bool Thread_IsStopped (struct Thread *thread); 00089 00093 SO_PUBLIC extern void Thread_Join(struct Thread *thread); 00097 SO_PUBLIC extern void Thread_Interrupt(struct Thread *thread); 00101 SO_PUBLIC extern void Thread_Stop (struct Thread *thread); 00102 SO_PUBLIC extern void Thread_StopAndJoin (struct Thread *thread); 00103 SO_PUBLIC extern void Thread_InterruptAndJoin (struct Thread *thread); 00106 SO_PUBLIC extern void Thread_Yield(void); 00107 00111 SO_PUBLIC extern uint32_t Thread_getCount (void); 00112 00115 SO_PUBLIC extern struct Thread *Thread_GetCurrent(void); 00118 SO_PUBLIC extern rzb_thread_t Thread_GetCurrentId(void); 00119 00120 SO_PUBLIC extern int Thread_KeyCmp(void *a, void *id); 00121 SO_PUBLIC extern int Thread_Cmp(void *a, void *b); 00122 00123 #ifdef __cplusplus 00124 } 00125 #endif 00126 #endif // RAZORBACK_THREAD_H