00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef _DECAF_INTERNAL_UTIL_CONCURRENT_PLATFORMTHREAD_H_
00019 #define _DECAF_INTERNAL_UTIL_CONCURRENT_PLATFORMTHREAD_H_
00020
00021 #include <decaf/util/Config.h>
00022
00023 #include <decaf/internal/util/concurrent/ThreadingTypes.h>
00024
00025 #include <vector>
00026
00027 namespace decaf {
00028 namespace internal {
00029 namespace util {
00030 namespace concurrent {
00031
00032 struct ThreadHandle;
00033
00034 class DECAF_API PlatformThread {
00035 private:
00036
00037 PlatformThread();
00038 PlatformThread(const PlatformThread&);
00039 PlatformThread& operator= (const PlatformThread&);
00040
00041 public:
00042
00051 static void createMutex(decaf_mutex_t* mutex);
00052
00053 static void lockMutex(decaf_mutex_t mutex);
00054
00055 static bool tryLockMutex(decaf_mutex_t mutex);
00056
00057 static void unlockMutex(decaf_mutex_t mutex);
00058
00059 static void destroyMutex(decaf_mutex_t mutex);
00060
00061 public:
00062
00063 static void createRWMutex(decaf_rwmutex_t* mutex);
00064
00065 static void readerLockMutex(decaf_rwmutex_t mutex);
00066 static void writerLockMutex(decaf_rwmutex_t mutex);
00067
00068 static bool tryReaderLockMutex(decaf_rwmutex_t mutex);
00069 static bool tryWriterLockMutex(decaf_rwmutex_t mutex);
00070
00071 static void unlockRWMutex(decaf_rwmutex_t mutex);
00072
00073 static void destroyRWMutex(decaf_rwmutex_t mutex);
00074
00075 public:
00076
00077 static void createCondition(decaf_condition_t* condition);
00078
00079 static void notify(decaf_condition_t condition);
00080
00081 static void notifyAll(decaf_condition_t condition);
00082
00083 static void waitOnCondition(decaf_condition_t condition, decaf_mutex_t mutex);
00084
00088 static bool waitOnCondition(decaf_condition_t condition, decaf_mutex_t mutex,
00089 long long mills, int nanos);
00090
00091 static void interruptibleWaitOnCondition(decaf_condition_t condition,
00092 decaf_mutex_t mutex,
00093 CompletionCondition& complete);
00094
00098 static bool interruptibleWaitOnCondition(decaf_condition_t condition, decaf_mutex_t mutex,
00099 long long mills, int nanos, CompletionCondition& complete);
00100
00101 static void destroyCondition(decaf_condition_t condition);
00102
00103 public:
00104
00117 static void initPriorityMapping(int maxPriority, std::vector<int>& mapping);
00118
00119 static void createNewThread(decaf_thread_t* handle, threadMainMethod, void* threadArg,
00120 int priority, long long stackSize, long long* threadId);
00121
00122 static void detachThread(decaf_thread_t handle);
00123
00124 static void detachOSThread(decaf_thread_t handle);
00125
00126 static void joinThread(decaf_thread_t handle);
00127
00128 static void exitThread();
00129
00130 static decaf_thread_t getCurrentThread();
00131
00132 static decaf_thread_t getSafeOSThreadHandle();
00133
00134 static long long getCurrentThreadId();
00135
00136 static int getPriority(decaf_thread_t thread);
00137
00138 static void setPriority(decaf_thread_t thread, int priority);
00139
00140 static long long getStackSize(decaf_thread_t thread);
00141
00142 static void setStackSize(decaf_thread_t thread, long long stackSize);
00143
00148 static void yeild();
00149
00150 public:
00151
00152 static void createTlsKey(decaf_tls_key* key);
00153
00154 static void destroyTlsKey(decaf_tls_key key);
00155
00156 static void* getTlsValue(decaf_tls_key tlsKey);
00157
00158 static void setTlsValue(decaf_tls_key tlsKey, void* value);
00159
00160 };
00161
00162 }}}}
00163
00164 #endif