DCL 3.7.4
Loading...
Searching...
No Matches
Thread.cpp
Go to the documentation of this file.
1#include <dcl/Config.h>
2
3#ifdef __WINNT__
4 #include <windows.h>
5 #include <VersionHelpers.h> // IsWindowsVistaOrGreater
6#else
7 #include <sys/ioctl.h>
8 #include <sys/poll.h>
9 #include <sys/time.h>
10 #include <unistd.h>
11#endif
12#ifdef __sun__
13 #include <sys/filio.h> // FIONREAD
14#endif
15
16#if __DCL_PTHREAD
17 #include <pthread.h>
18 #include <sched.h> // sched_yield
19#endif
20
21#include <dcl/Exception.h>
22#include <dcl/Thread.h>
23
24#if __DCL_HAVE_THIS_FILE__
25#undef __THIS_FILE__
26static const char_t __THIS_FILE__[] = __T("dcl/Thread.cpp");
27#endif
28
29__DCL_BEGIN_NAMESPACE
30
32
33String Thread::toString() const
34{
35 StringBuilder r = className() + __T(":");
36 if (__name.isEmpty())
37 r += __T("(noname)");
38 return r;
39}
40
41Thread::Thread(const char_t* _name /*= NULL*/)
42{
43#ifdef __WINNT__
44 __hThread = NULL;
45#endif
46
47 __threadId = 0;
48 if (_name)
49 __name = _name;
50}
51
52#if __DCL_PTHREAD
53 #define __key_t pthread_key_t
54 #define __key_create(key) pthread_key_create(&key, NULL)
55 #define __key_delete(key) pthread_key_delete(key)
56 #define __key_get(key) pthread_getspecific(key)
57 #define __key_set(key, value) pthread_setspecific(key, value)
58 #define __key_set_success(key, value) pthread_setspecific(key, value) == 0
59#elif defined(__WINNT__)
60 #define __key_t DWORD
61 #define __key_create(key) key = TlsAlloc()
62 #define __key_delete(key) TlsFree(key)
63 #define __key_get(key) TlsGetValue(key)
64 #define __key_set(key, value) TlsSetValue(key, value)
65 #define __key_set_success(key, value) TlsSetValue(key, value) == TRUE
66#endif
67
68static __key_t __keySelfThread = (__key_t) -1;
69
70void Thread::start()
72{
73 __DCL_ASSERT(__keySelfThread != (__key_t)-1);
74
75#if __DCL_PTHREAD
76 int n = pthread_create(
77 &__threadId,
78 (pthread_attr_t*)NULL,
79 Thread::startRoutine, (void*)this
80 );
81 if (n != 0)
82 throw new SysError(n);
83#elif defined(__WINNT__)
84 DWORD id = 0;
85 __hThread = CreateThread(
86 NULL, // __in LPSECURITY_ATTRIBUTES lpThreadAttributes,
87 0, // default __in SIZE_T dwStackSize,
88 startRoutine, // __in LPTHREAD_START_ROUTINE lpStartAddress,
89 (LPVOID) this, // __in LPVOID lpParameter,
90 0, // run immediate __in DWORD dwCreationFlags,
91 &id // __out LPDWORD lpThreadId
92 );
93 __threadId = id;
94 if (__hThread == NULL)
95 throw new SysError(GetLastError());
96#endif
97}
98
100{
101 return __key_set_success(__keySelfThread, this);
102}
103
105{
106 __DCL_ASSERT(__keySelfThread != (__key_t)-1);
107 return (Thread*) __key_get(__keySelfThread);
108}
109
110#if __DCL_PTHREAD
111void*
112#elif defined(__WINNT__)
113DWORD
114#endif
115Thread::startRoutine(void* _pThread)
116{
117 int r = -1;
118 Thread* pThread = (Thread*) _pThread;
119 try {
120 if (pThread->init())
121 r = pThread->run();
122 }
123 catch (Exception* cause) {
124 __DCL_TRACE2(__T("Thread execution fail! [%ls] %ls\n"),
125 pThread->toString().data(), cause->toStringAll().data());
126 cause->destroy();
127 }
128#if __DCL_PTHREAD
129 return (void*)(size_t)r;
130#elif defined(__WINNT__)
131 return (DWORD)r;
132#endif
133}
134
135int Thread::join()
136{
137#if __DCL_PTHREAD
138 void* r;
139 pthread_join(__threadId, &r);
140#elif defined(__WINNT__)
141 DWORD r = 0;
142 WaitForSingleObject(__hThread, INFINITE);
143 GetExitCodeThread(__hThread, &r);
144 CloseHandle(__hThread);
145 __hThread = NULL;
146#endif
147
148 __threadId = 0;
149 return (int)(size_t)r;
150}
151
152void Thread::sleep(unsigned int _mills)
153{
154#if __DCL_PTHREAD
155 /*
156 ::sleep(_milliseconds / 1000);
157 ::usleep((_milliseconds % 1000) * 1000);
158 */
159 poll(NULL, 0, _mills);
160#elif defined(__WINNT__)
161 Sleep(_mills);
162#endif
163}
164
166{
167#if __DCL_PTHREAD
168 // pthread_yield(); deprecated
169 sched_yield();
170#elif defined(__WINNT__)
171 SwitchToThread();
172#endif
173}
174
176{
177#if __DCL_PTHREAD
178 return pthread_self();
179#elif defined(__WINNT__)
180 return GetCurrentThreadId();
181#endif
182}
183
184void Thread::once(thread_once_t& _onceControl, initRoutine _initRoutine)
185{
186 __DCL_ASSERT_PARAM(_initRoutine != NULL);
187#if __DCL_PTHREAD
188 pthread_once(&_onceControl, _initRoutine);
189#elif defined(__WINNT__)
190 InitOnceExecuteOnce(&_onceControl, (PINIT_ONCE_FN)_initRoutine, NULL, NULL);
191#endif
192}
193
194thread_key_t Thread::keyCreate() __DCL_THROWS1(SysError*)
195{
196#if __DCL_PTHREAD
197 thread_key_t rKey;
198 int failed = pthread_key_create(&rKey, NULL);
199 if (failed)
200 throw new SysError(failed);
201 return rKey;
202#elif defined(__WINNT__)
203 thread_key_t rKey = TlsAlloc();
204 if (rKey == TLS_OUT_OF_INDEXES)
205 throw new SysError(GetLastError());
206 return rKey;
207#endif
208}
209
210void Thread::keyDelete(thread_key_t _key) __DCL_THROWS1(SysError*)
211{
212#if __DCL_PTHREAD
213 int failed = pthread_key_delete(_key);
214 if (failed)
215 throw new SysError(failed);
216#elif defined(__WINNT__)
217 if (!TlsFree(_key))
218 throw new SysError(GetLastError());
219#endif
220}
221void Thread::keySetValue(thread_key_t _key, void* _value) __DCL_THROWS1(SysError*)
222{
223#if __DCL_PTHREAD
224 int failed = pthread_setspecific(_key, _value);
225 if (failed)
226 throw new SysError(failed);
227#elif defined(__WINNT__)
228 if (!TlsSetValue(_key, _value))
229 throw new SysError(GetLastError());
230#endif
231}
232void* Thread::keyGetValue(thread_key_t _key) __DCL_THROWS1(SysError*)
233{
234#if __DCL_PTHREAD
235 return pthread_getspecific(_key);
236#elif defined(__WINNT__)
237 void* p = TlsGetValue(_key);
238 if (p == NULL && GetLastError() != ERROR_SUCCESS)
239 throw new SysError(GetLastError());
240 return p;
241#endif
242}
243
244#if __DCL_PTHREAD
245#if defined(__APPLE__)
246 #define __lock_t pthread_mutex_t
247 #define __init(lock) pthread_mutex_init(&lock, NULL)
248 #define __destroy(lock) pthread_mutex_destroy(&lock)
249 #define __lock(lock) pthread_mutex_lock(&lock)
250 #define __unlock(lock) pthread_mutex_unlock(&lock)
251#else
252 #define __lock_t pthread_spinlock_t
253 #define __init(lock) pthread_spin_init(&lock, PTHREAD_PROCESS_PRIVATE)
254 #define __destroy(lock) pthread_spin_destroy(&lock)
255 #define __lock(lock) pthread_spin_lock(&lock)
256 #define __unlock(lock) pthread_spin_unlock(&lock)
257#endif
258#elif defined(__WINNT__)
259 #define __lock_t CRITICAL_SECTION
260 #define __init(lock) InitializeCriticalSectionAndSpinCount(&lock, INFINITE)
261 #define __destroy(lock) DeleteCriticalSection(&lock)
262 #define __lock(lock) EnterCriticalSection(&lock)
263 #define __unlock(lock) LeaveCriticalSection(&lock)
264#endif
265
266#define __LOCK_COUNT 7
267static __lock_t __lock[__LOCK_COUNT];
268
269void Thread::crtLock(const void* _p)
270{
271 __lock_t& lock = __lock[(size_t) _p % __LOCK_COUNT];
272 __lock(lock);
273}
274
275void Thread::crtUnlock(const void* _p)
276{
277 __lock_t& lock = __lock[(size_t) _p % __LOCK_COUNT];
278 __unlock(lock);
279}
280
281#if __DCL_PTHREAD
282long Thread::incrementAndGet(volatile long& _n)
283{
284 __lock_t& lock = __lock[((size_t)&_n) % __LOCK_COUNT];
285 __lock(lock);
286 long n = ++(_n);
287 __unlock(lock);
288 return n;
289}
290
291long Thread::decrementAndGet(volatile long& _n)
292{
293 __lock_t& lock = __lock[((size_t)&_n) % __LOCK_COUNT];
294 __lock(lock);
295 long n = --(_n);
296 __unlock(lock);
297 return n;
298}
299
300long long Thread::incrementAndGet(volatile long long& _n)
301{
302 __lock_t& lock = __lock[((size_t)&_n) % __LOCK_COUNT];
303 __lock(lock);
304 long long n = ++(_n);
305 __unlock(lock);
306 return n;
307}
308
309long long Thread::decrementAndGet(volatile long long& _n)
310{
311 __lock_t& lock = __lock[((size_t)&_n) % __LOCK_COUNT];
312 __lock(lock);
313 long long n = --(_n);
314 __unlock(lock);
315 return n;
316}
317#elif defined(__WINNT__)
318long Thread::incrementAndGet(volatile long& _n)
319{
320 return InterlockedIncrement(&_n);
321}
322
323long Thread::decrementAndGet(volatile long& _n)
324{
325 return InterlockedDecrement(&_n);
326}
327
328long long Thread::decrementAndGet(volatile long long& _n)
329{
330 return InterlockedDecrement64(&_n);
331}
332
333long long Thread::incrementAndGet(volatile long long& _n)
334{
335 return InterlockedIncrement64(&_n);
336}
337#endif
338
340{
341 __key_create(__keySelfThread);
342
343 for (int i = 0; i < __LOCK_COUNT; i++)
344 __init(__lock[i]);
345}
346
348{
349 __key_delete(__keySelfThread);
350
351 for (int i = 0; i < __LOCK_COUNT; i++)
352 __destroy(__lock[i]);
353}
354
355Thread::Event::Event()
356{
357 __bWaiting = false;
358
359#if __DCL_PTHREAD
360 __DCL_VERIFY(pipe(__fds) == 0);
361#elif defined(__WINNT__)
362 __DCL_VERIFY(__hEvent = CreateEvent(
363 NULL, // lpEventAttributes
364 FALSE, // bManualReset
365 FALSE, // bInitialState
366 NULL // lpName
367 )
368 );
369#endif
370}
371
372Thread::Event::~Event()
373{
374#if __DCL_PTHREAD
375 __DCL_VERIFY(close(__fds[0]) == 0);
376 __DCL_VERIFY(close(__fds[1]) == 0);
377#elif defined(__WINNT__)
378 __DCL_VERIFY(CloseHandle(__hEvent) != FALSE);
379#endif
380}
381
382void Thread::Event::set()
383{
384#if __DCL_PTHREAD
385 char c = '1';
386 __DCL_VERIFY(write(__fds[1], &c, sizeof(c)) == sizeof(c));
387#elif defined(__WINNT__)
388 __DCL_VERIFY(SetEvent(__hEvent) != FALSE);
389#endif
390}
391
392void Thread::Event::reset()
393{
394#if __DCL_PTHREAD
395 int nbytes = 0;
396 ioctl(__fds[READ_FD_INDEX], FIONREAD, &nbytes);
397 while (nbytes > 0) {
398 char buf[100];
399 int n = read(__fds[0], buf, nbytes < 100 ? nbytes : 100);
400 if (n > 0)
401 nbytes -= n;
402 else {
403 // 0: read all, -1:error
404 break;
405 }
406 }
407#elif defined(__WINNT__)
408 __DCL_VERIFY(ResetEvent(__hEvent) != FALSE);
409#endif
410}
411
412bool Thread::Event::wait(unsigned int _milliseconds)
413{
414 bool r = true;
415 __bWaiting = true;
416#if __DCL_PTHREAD
417 struct pollfd pfd;
418 pfd.fd = __fds[READ_FD_INDEX];
419 pfd.events = POLLIN;
420 pfd.revents = 0;
421
422 int n = poll(&pfd, 1, _milliseconds);
423 if (n <= 0) {
424 r = false;
425 __DCL_ASSERT(n == 0);
426 errno = ETIMEDOUT;
427 }
428#elif defined(__WINNT__)
429 switch(WaitForSingleObject(__hEvent, _milliseconds)) {
430 case WAIT_OBJECT_0:
431 break;
432 case WAIT_TIMEOUT:
433 r = false;
434 SetLastError(ERROR_TIMEOUT);
435 break;
436 default :
437 r = false;
438 __DCL_ASSERT(false);
439 }
440
441#endif
442 __bWaiting = false;
443 return r;
444}
445
446#ifdef __WINNT__
447Thread::Mutex::Mutex(DWORD _dwSpinCount)
448{
449 InitializeCriticalSectionAndSpinCount(&__cs, _dwSpinCount);
450}
451#endif
452
454{
455 __locker = 0;
456#if __DCL_PTHREAD
457 __DCL_VERIFY(pthread_mutex_init(&__mutex, NULL) == 0);
458#elif defined(__WINNT__)
459 InitializeCriticalSection(&__cs);
460#endif
461}
462
464{
465#if __DCL_PTHREAD
466 __DCL_VERIFY(pthread_mutex_destroy(&__mutex) == 0);
467#elif defined(__WINNT__)
468 DeleteCriticalSection(&__cs);
469#endif
470}
471
473{
474#if __DCL_PTHREAD
475 __DCL_VERIFY(pthread_mutex_lock(&__mutex) == 0);
476#elif defined(__WINNT__)
477 EnterCriticalSection(&__cs);
478#endif
479 __locker = Thread::self();
480}
481
483{
484 bool r = false;
485#if __DCL_PTHREAD
486 int r_ = pthread_mutex_trylock(&__mutex);
487 __DCL_ASSERT(r_ != EINVAL);
488 __DCL_ASSERT(r_ == 0 || r_ == EBUSY);
489 r = r_ == 0;
490#elif defined(__WINNT__)
491 r = TryEnterCriticalSection(&__cs) == TRUE;
492#endif
493 if (r) {
494 __locker = Thread::self();
495 }
496 return r;
497}
498
500{
501 __DCL_ASSERT(__locker == Thread::self());
502 __locker = 0;
503#if __DCL_PTHREAD
504 __DCL_VERIFY(pthread_mutex_unlock(&__mutex) == 0);
505#elif defined(__WINNT__)
506 LeaveCriticalSection(&__cs);
507#endif
508}
509
510#if __DCL_PTHREAD && !defined(__APPLE__)
511Thread::SpinLock::SpinLock(bool _pshared /* = false */)
512{
513 __locker = 0;
514 __DCL_VERIFY(pthread_spin_init(&__spinLock,
515 _pshared ? PTHREAD_PROCESS_SHARED : PTHREAD_PROCESS_PRIVATE
516 ) == 0);
517}
518
519Thread::SpinLock::~SpinLock()
520{
521 __DCL_VERIFY(pthread_spin_destroy(&__spinLock) == 0);
522}
523
524void Thread::SpinLock::lock()
525{
526 __DCL_VERIFY(pthread_spin_lock(&__spinLock) == 0);
527 __locker = Thread::self();
528}
529
530bool Thread::SpinLock::tryLock()
531{
532 int r_ = pthread_spin_trylock(&__spinLock);
533 __DCL_ASSERT(r_ != EINVAL);
534 __DCL_ASSERT(r_ == 0 || r_ == EBUSY);
535 bool r = r_ == 0;
536 if (r) {
537 __locker = Thread::self();
538 }
539 return r;
540}
541
542void Thread::SpinLock::unlock()
543{
544 __DCL_ASSERT(__locker == Thread::self());
545 __locker = 0;
546 __DCL_VERIFY(pthread_spin_unlock(&__spinLock) == 0);
547}
548#endif // __DCL_PTHREAD
549
550#if __DCL_PTHREAD || (defined(__WINNT__) && _WIN32_WINNT >= 0x0600)
551Thread::ReadWriteLock::ReadWriteLock()
552{
553#if __DCL_PTHREAD
554 __DCL_VERIFY(pthread_rwlock_init(&__rwlock, NULL) == 0);
555#else
556 InitializeSRWLock(&__srwlock);
557#endif
558}
559
560Thread::ReadWriteLock::~ReadWriteLock()
561{
562#if __DCL_PTHREAD
563 __DCL_VERIFY(pthread_rwlock_destroy(&__rwlock) == 0);
564#endif
565}
566
567void Thread::ReadWriteLock::readLock()
568{
569#if __DCL_PTHREAD
570 __DCL_VERIFY(pthread_rwlock_rdlock(&__rwlock) == 0);
571#else
572 AcquireSRWLockShared(&__srwlock);
573#endif
574}
575
576void Thread::ReadWriteLock::writeLock()
577{
578#if __DCL_PTHREAD
579 __DCL_VERIFY(pthread_rwlock_wrlock(&__rwlock) == 0);
580#else
581 AcquireSRWLockExclusive(&__srwlock);
582#endif
583}
584
585#if __DCL_PTHREAD
586bool Thread::ReadWriteLock::tryReadLock()
587{
588 int r = pthread_rwlock_tryrdlock(&__rwlock);
589 __DCL_ASSERT(r != EINVAL);
590 __DCL_ASSERT(r == 0 || r == EBUSY);
591 return r == 0;
592}
593
594bool Thread::ReadWriteLock::tryWriteLock()
595{
596 int r = pthread_rwlock_trywrlock(&__rwlock);
597 __DCL_ASSERT(r != EINVAL);
598 __DCL_ASSERT(r == 0 || r == EBUSY);
599 return r == 0;
600}
601
602void Thread::ReadWriteLock::unlock()
603{
604 __DCL_VERIFY(::pthread_rwlock_unlock(&__rwlock) == 0);
605}
606#else
607void Thread::ReadWriteLock::readUnlock()
608{
609 ReleaseSRWLockShared(&__srwlock);
610}
611void Thread::ReadWriteLock::writeUnlock()
612{
613 ReleaseSRWLockExclusive(&__srwlock);
614}
615#endif // __DCL_PTHREAD
616#endif // __DCL_PTHREAD || (defined(__WINNT__) && _WIN32_WINNT >= 0x0600)
617
619{
620 __bWaiting = false;
621#if __DCL_PTHREAD
622 __DCL_VERIFY(pthread_cond_init(&__cond, NULL) == 0);
623#elif defined(__WINNT__) && _WIN32_WINNT >= 0x0600
624 // Windows Vista, Windows Server 2008
625 __DCL_ASSERT(IsWindowsVistaOrGreater());
626 InitializeConditionVariable(&__cond);
627#endif
628
629}
630
632{
633#if __DCL_PTHREAD
634 __DCL_VERIFY(pthread_cond_destroy(&__cond) == 0);
635#endif
636}
637
639{
640#if __DCL_PTHREAD
641 __DCL_VERIFY(pthread_cond_signal(&__cond) == 0);
642#elif defined(__WINNT__)
643 #if _WIN32_WINNT >= 0x0600
644 WakeConditionVariable(&__cond);
645 #else
646 __cond.set();
647 #endif
648#endif
649}
650
651#if __DCL_PTHREAD || (defined(__WINNT__) && _WIN32_WINNT >= 0x0600)
652void Thread::CondVar::broadcast()
653{
654#if __DCL_PTHREAD
655 __DCL_VERIFY(pthread_cond_broadcast(&__cond) == 0);
656#elif defined(__WINNT__)
657 WakeAllConditionVariable(&__cond);
658#endif
659}
660#endif
661
662bool Thread::CondVar::wait(Mutex& _mutex, unsigned int _milliseconds)
663{
664 bool r = true;
665 __bWaiting = true;
666#if __DCL_PTHREAD
667 // INFINITE == -1
668 if (_milliseconds == (unsigned int) INFINITE) {
669 __DCL_VERIFY(pthread_cond_wait(&__cond, (pthread_mutex_t*)&_mutex) == 0);
670 r = true;
671 }
672 else {
673 // millisoconds 1/1000
674 // microseconds 1/1000000
675 // nanoseconds 1/1000000000
676 struct timeval tv;
677 struct timezone tz;
678 struct timespec ts;
679 __DCL_VERIFY(gettimeofday(&tv, &tz) == 0);
680 ts.tv_sec = tv.tv_sec + (_milliseconds / 1000);
681 ts.tv_nsec = (tv.tv_usec * 1000) + ((_milliseconds % 1000) * 1000000);
682 int n = pthread_cond_timedwait(&__cond, (pthread_mutex_t*)&_mutex, &ts);
683 if (n != 0) {
684 r = false;
685 __DCL_ASSERT(n == ETIMEDOUT);
686 errno = n;
687 }
688 }
689#elif defined(__WINNT__)
690 #if _WIN32_WINNT >= 0x0600
691 if (!SleepConditionVariableCS(&__cond,
692 (CRITICAL_SECTION*)&_mutex, _milliseconds)) {
693 r = false;
694 __DCL_ASSERT(GetLastError() == ERROR_TIMEOUT);
695 }
696 #else
697 _mutex.unlock();
698 r = __cond.wait(INFINITE);
699 _mutex.lock();
700 if (r)
701 __cond.reset();
702 #endif
703#endif
704
705 __bWaiting = false;
706 return r;
707}
708
709#if defined(__WINNT__) && _WIN32_WINNT >= 0x0600
710bool Thread::CondVar::wait(ReadWriteLock& _lock, bool _shared, unsigned int _milliseconds)
711{
712 bool r = true;
713 __bWaiting = true;
714 if (!SleepConditionVariableSRW(&__cond, (SRWLOCK *)&_lock,
715 _shared ? CONDITION_VARIABLE_LOCKMODE_SHARED : 0, _milliseconds)) {
716 r = false;
717 __DCL_ASSERT(GetLastError() == ERROR_TIMEOUT);
718 }
719 __bWaiting = false;
720 return r;
721}
722#endif
723
724#if __DCL_PTHREAD && !defined(__APPLE__)
725Thread::Barrier::Barrier(unsigned int _count)
726{
727 __DCL_VERIFY(pthread_barrier_init(&__barrier, NULL, _count) == 0);
728}
729
730Thread::Barrier::~Barrier()
731{
732 __DCL_VERIFY(pthread_barrier_destroy(&__barrier) == 0);
733}
734
735void Thread::Barrier::wait()
736{
737 __DCL_VERIFY(pthread_barrier_wait(&__barrier) == 0);
738}
739
740#endif
741
742__DCL_END_NAMESPACE
#define __THIS_FILE__
Definition _trace.h:14
#define NULL
Definition Config.h:312
wchar_t char_t
Definition Config.h:247
#define __DCL_THROWS1(e)
Definition Config.h:152
#define TRUE
#define FALSE
IOException *size_t r
Definition MediaInfo.cpp:82
#define __DCL_ASSERT_PARAM(expr)
Definition Object.h:409
#define __DCL_VERIFY(expr)
Definition Object.h:396
#define __DCL_ASSERT(expr)
Definition Object.h:394
#define IMPLEMENT_CLASSINFO(class_name, base_class_name)
Definition Object.h:245
#define __T(str)
Definition Object.h:60
pthread_t thread_t
Definition Object.h:27
#define __DCL_TRACE2(fmt, arg1, arg2)
Definition Object.h:400
void __cleanupThreadEnvironment()
Definition Thread.cpp:347
#define __LOCK_COUNT
Definition Thread.cpp:266
void __initializeThreadEnvironment()
Definition Thread.cpp:339
pthread_key_t thread_key_t
Definition Thread.h:37
#define INFINITE
Definition Thread.h:34
pthread_once_t thread_once_t
Definition Thread.h:36
virtual void destroy()
Definition Exception.cpp:74
String toStringAll() const
Definition Exception.cpp:45
virtual String toString() const
Definition Object.cpp:187
String className() const
Definition Object.cpp:163
bool wait(Mutex &_mutex, unsigned int _milliseconds=INFINITE)
Definition Thread.cpp:662
void unlock()
Definition Thread.cpp:499
void lock()
Definition Thread.cpp:472
bool tryLock()
Definition Thread.cpp:482
static void crtLock(const void *_p)
Definition Thread.cpp:269
static long incrementAndGet(volatile long &_n)
static void crtUnlock(const void *_p)
Definition Thread.cpp:275
static void yield()
Definition Thread.cpp:165
static void sleep(unsigned int _mills)
Definition Thread.cpp:152
static thread_t self()
Definition Thread.cpp:175
virtual bool init()
Definition Thread.cpp:99
static long decrementAndGet(volatile long &_n)
static Thread * getSelfThread()
Definition Thread.cpp:104
virtual int run()=0