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(__linux__)
28 #include <bits/pthreadtypes.h>
29 #elif defined(__APPLE__)
30 #include <sys/_pthread/_pthread_types.h>
35 #define THREAD_ONCE_INIT PTHREAD_ONCE_INIT
40#ifndef __DCL_OBJECT_H__
43#ifndef __DCL_STRING_H__
88 bool started()
const {
return __threadId != 0; }
93 thread_t thread()
const {
return __threadId; }
98 const String& name()
const {
return __name; }
124 static void* startRoutine(
void* _pThread);
125#elif defined(__WINNT__)
127 static DWORD WINAPI startRoutine(
void* _pThread);
134 static void sleep(
unsigned int _mills);
228 static
void crtLock(const
void* _p);
241 enum { READ_FD_INDEX = 0 };
243#elif defined(__WINNT__)
249 int handle() {
return __fds[READ_FD_INDEX]; }
250#elif defined(__WINNT__)
251 HANDLE handle() {
return __hEvent; }
265 bool wait(
unsigned int _milliseconds =
INFINITE);
266 bool isWaiting() {
return __bWaiting; }
268 volatile bool __bWaiting;
275 pthread_mutex_t __mutex;
276#elif defined(__WINNT__)
277 CRITICAL_SECTION __cs;
283 Mutex(DWORD _dwSpinCount);
296#if __DCL_PTHREAD && !defined(__APPLE__)
300 pthread_spinlock_t __spinLock;
301 volatile pthread_t __locker;
304 SpinLock(
bool _pshared =
false);
309 pthread_t locker()
const {
313#elif defined(__WINNT__)
314 class DCLCAPI SpinLock :
public Mutex
321#if __DCL_PTHREAD || (defined(__WINNT__) && _WIN32_WINNT >= 0x0600)
326 pthread_rwlock_t __rwlock;
356 pthread_cond_t __cond;
357#elif defined(__WINNT__)
358 #if _WIN32_WINNT >= 0x0600
359 CONDITION_VARIABLE __cond;
369#if __DCL_PTHREAD || (defined(__WINNT__) && _WIN32_WINNT >= 0x0600)
379#if defined(__WINNT__) && _WIN32_WINNT >= 0x0600
380 bool wait(ReadWriteLock& _lock,
bool shared,
unsigned int _milliseconds =
INFINITE);
384 volatile bool __bWaiting;
387#if __DCL_PTHREAD && !defined(__APPLE__)
391 pthread_barrier_t __barrier;
394 Barrier(
unsigned int _count);
400 template<
typename TYPE>
417template<
typename TYPE>
429template<
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