1#ifndef __DCL_THREAD_H__
2#define __DCL_THREAD_H__ 20110109
4#ifndef __DCL_CONFIG_H__
12 #define THREAD_ONCE_INIT PTHREAD_ONCE_INIT
17 #error "Required windows.h, See dcl/_windows.h"
22 #define THREAD_ONCE_INIT INIT_ONCE_STATIC_INIT
27 #if defined(__ANDROID__)
28 #include <bits/pthread_types.h>
29 #elif !defined(__DEFINED_pthread_t) && defined(__linux__)
30 #include <bits/pthreadtypes.h>
31 #elif defined(__APPLE__)
32 #include <sys/_pthread/_pthread_types.h>
37 #define THREAD_ONCE_INIT PTHREAD_ONCE_INIT
42#ifndef __DCL_OBJECT_H__
45#ifndef __DCL_STRING_H__
90 bool started()
const {
return __threadId != 0; }
95 thread_t thread()
const {
return __threadId; }
100 const String& name()
const {
return __name; }
126 static void* startRoutine(
void* _pThread);
127#elif defined(__WINNT__)
129 static DWORD WINAPI startRoutine(
void* _pThread);
136 static void sleep(
unsigned int _mills);
230 static
void crtLock(const
void* _p);
243 enum { READ_FD_INDEX = 0 };
245#elif defined(__WINNT__)
251 int handle() {
return __fds[READ_FD_INDEX]; }
252#elif defined(__WINNT__)
253 HANDLE handle() {
return __hEvent; }
267 bool wait(
unsigned int _milliseconds =
INFINITE);
268 bool isWaiting() {
return __bWaiting; }
270 volatile bool __bWaiting;
277 pthread_mutex_t __mutex;
278#elif defined(__WINNT__)
279 CRITICAL_SECTION __cs;
285 Mutex(DWORD _dwSpinCount);
298#if __DCL_PTHREAD && !defined(__APPLE__)
302 pthread_spinlock_t __spinLock;
303 volatile pthread_t __locker;
306 SpinLock(
bool _pshared =
false);
311 pthread_t locker()
const {
315#elif defined(__WINNT__)
316 class DCLCAPI SpinLock :
public Mutex
323#if __DCL_PTHREAD || (defined(__WINNT__) && _WIN32_WINNT >= 0x0600)
328 pthread_rwlock_t __rwlock;
358 pthread_cond_t __cond;
359#elif defined(__WINNT__)
360 #if _WIN32_WINNT >= 0x0600
361 CONDITION_VARIABLE __cond;
371#if __DCL_PTHREAD || (defined(__WINNT__) && _WIN32_WINNT >= 0x0600)
381#if defined(__WINNT__) && _WIN32_WINNT >= 0x0600
382 bool wait(ReadWriteLock& _lock,
bool shared,
unsigned int _milliseconds =
INFINITE);
386 volatile bool __bWaiting;
389#if __DCL_PTHREAD && !defined(__APPLE__)
393 pthread_barrier_t __barrier;
396 Barrier(
unsigned int _count);
402 template<
typename TYPE>
419template<
typename TYPE>
431template<
typename TYPE>
#define DECLARE_CLASSINFO(class_name)
pthread_key_t thread_key_t
pthread_once_t thread_once_t
virtual String toString() const
bool wait(Mutex &_mutex, unsigned int _milliseconds=INFINITE)
static void crtLock(const void *_p)
static long incrementAndGet(volatile long &_n)
static void crtUnlock(const void *_p)
static void sleep(unsigned int _mills)
static long decrementAndGet(volatile long &_n)
static Thread * getSelfThread()
SingleLock< SpinLock > SingleLockSpin
SingleLock< Mutex > SingleLockMutex