Bayonne2 / Common C++ 2 Framework
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
thread.h
Go to the documentation of this file.
1 // Copyright (C) 1999-2005 Open Source Telecom Corporation.
2 // Copyright (C) 2006-2010 David Sugar, Tycho Softworks.
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 //
18 // As a special exception, you may use this file as part of a free software
19 // library without restriction. Specifically, if other files instantiate
20 // templates or use macros or inline functions from this file, or you compile
21 // this file and link it with other files to produce an executable, this
22 // file does not by itself cause the resulting executable to be covered by
23 // the GNU General Public License. This exception does not however
24 // invalidate any other reasons why the executable file might be covered by
25 // the GNU General Public License.
26 //
27 // This exception applies only to the code released under the name GNU
28 // Common C++. If you copy code from other releases into a copy of GNU
29 // Common C++, as the General Public License permits, the exception does
30 // not apply to the code that you add in this way. To avoid misleading
31 // anyone as to the status of such modified files, you must delete
32 // this exception notice from them.
33 //
34 // If you write modifications of your own for GNU Common C++, it is your choice
35 // whether to permit this exception to apply to your modifications.
36 // If you do not wish that, delete this exception notice.
37 //
38 
44 #ifndef CCXX_THREAD_H_
45 #define CCXX_THREAD_H_
46 
47 #include <cc++/config.h>
48 
49 #ifndef CCXX_STRING_H_
50 #include <cc++/string.h>
51 #endif
52 
53 #ifndef WIN32
54 #define CCXX_POSIX
55 #endif // !WIN32
56 
57 #include <ctime>
58 
59 #ifndef WIN32
60 #include <pthread.h>
61 #endif // !WIN32
62 
63 #undef CCXX_USE_WIN32_ATOMIC
64 #ifndef WIN32
65 #include <time.h>
66 #include <signal.h>
67 #include <unistd.h>
68 
69 #ifdef _THR_UNIXWARE
70 #undef PTHREAD_MUTEXTYPE_RECURSIVE
71 #endif
72 
73 typedef pthread_t cctid_t;
74 typedef unsigned long timeout_t;
75 
76 /*
77 #if defined(__CYGWIN32__)
78 __declspec(dllimport) long __stdcall InterlockedIncrement(long *);
79 __declspec(dllimport) long __stdcall InterlockedDecrement(long *);
80 __declspec(dllimport) long __stdcall InterlockedExchange(long *, long);
81 #define CCXX_USE_WIN32_ATOMIC 1
82 #endif
83 */
84 
85 #else // WIN32
86 typedef DWORD cctid_t;
87 typedef DWORD timeout_t;
88 
89 #define MAX_SEM_VALUE 1000000
90 #define CCXX_USE_WIN32_ATOMIC 1
91 
92 #endif // !WIN32
93 
94 #ifdef HAVE_GCC_CXX_BITS_ATOMIC
95 #include <ios>
96 #endif
97 
98 #ifdef CCXX_NAMESPACES
99 namespace ost {
100 #ifdef __BORLANDC__
101 # if __BORLANDC__ >= 0x0560
102 using std::time_t;
103 using std::tm;
104 # endif
105 #endif
106 #endif
107 
108 #ifdef HAVE_GCC_CXX_BITS_ATOMIC
109 using namespace __gnu_cxx;
110 #endif
111 
114 
115 #define TIMEOUT_INF ~((timeout_t) 0)
116 
117 #define ENTER_CRITICAL enterMutex();
118 #define LEAVE_CRITICAL leaveMutex();
119 #define ENTER_DEFERRED setCancel(cancelDeferred);
120 #define LEAVE_DEFERRED setCancel(cancelImmediate);
121 
122 #ifndef WIN32
123 // These macros override common functions with thread-safe versions. In
124 // particular the common "libc" sleep() has problems since it normally
125 // uses SIGARLM (as actually defined by "posix"). The pthread_delay and
126 // usleep found in libpthread are gaurenteed not to use SIGALRM and offer
127 // higher resolution. psleep() is defined to call the old process sleep.
128 
129 #undef sleep
130 #define psleep(x) (sleep)(x)
131 
132 #ifdef signal
133 #undef signal
134 #endif
135 
136 #endif // !WIN32
137 
138 #undef Yield
139 
142 
187 {
188 private:
189  static bool _debug;
191 #ifndef WIN32
192 #ifndef PTHREAD_MUTEXTYPE_RECURSIVE
193  int volatile _level;
194  Thread *volatile _tid;
195 #endif
196  /*
197  * Pthread mutex object. This is protected rather than private
198  * because some mixed mode pthread operations require a mutex as
199  * well as their primary pthread object. A good example of this
200  * is the Event class, as waiting on a conditional object must be
201  * associated with an accessable mutex. An alternative would be
202  * to make such classes "friend" classes of the Mutex.
203  */
204  pthread_mutex_t _mutex;
205 #else // WIN32
206 
207 # if defined(MUTEX_UNDERGROUND_WIN32_MUTEX) && defined(MUTEX_UNDERGROUND_WIN32_CRITICALSECTION)
208 # error "Can't determine underground for Mutex"
209 # endif
210 
211 #ifdef MUTEX_UNDERGROUND_WIN32_MUTEX
212  HANDLE _mutex;
213 #endif
214 #ifdef MUTEX_UNDERGROUND_WIN32_CRITICALSECTION
215  CRITICAL_SECTION _criticalSection;
216 #endif
217 
218 #endif // WIN32
219 
220 public:
226  Mutex(const char *name = NULL);
227 
233  virtual ~Mutex();
234 
240  static void setDebug(bool mode)
241  {_debug = mode;};
242 
248  inline void nameMutex(const char *name)
249  {_name = name;};
250 
258  void enterMutex(void);
259 
263  inline void enter(void)
264  {enterMutex();};
265 
269  inline void leave(void)
270  {leaveMutex();};
271 
277  inline bool test(void)
278  {return tryEnterMutex();};
279 
290  bool tryEnterMutex(void);
291 
302  void leaveMutex(void);
303 };
304 
329 {
330 private:
332 public:
338  MutexLock( Mutex& _mutex ) : mutex( _mutex )
339  { mutex.enterMutex(); }
340 
344  // this should be not-virtual
346  { mutex.leaveMutex(); }
347 };
348 
358 {
359 private:
360 #ifdef HAVE_PTHREAD_RWLOCK
361  pthread_rwlock_t _lock;
362 #else
364 #endif
365 
366 public:
370  ThreadLock();
371 
375  virtual ~ThreadLock();
376 
380  void readLock(void);
381 
385  void writeLock(void);
386 
392  bool tryReadLock(void);
393 
399  bool tryWriteLock(void);
400 
404  void unlock(void);
405 };
406 
428 {
429 private:
431 
432 public:
438  ReadLock( ThreadLock& _tl ) : tl( _tl )
439  { tl.readLock(); }
443  // this should be not-virtual
445  { tl.unlock(); }
446 };
447 
469 {
470 private:
472 
473 public:
479  WriteLock( ThreadLock& _tl ) : tl( _tl )
480  { tl.writeLock(); }
484  // this should be not-virtual
486  { tl.unlock(); }
487 };
488 
489 
500 {
501 private:
502  volatile int counter;
503 
504 public:
510  MutexCounter(const char *id = NULL);
511 
519  MutexCounter(int initial, const char *id = NULL);
520 
521  friend __EXPORT int operator++(MutexCounter &mc);
522  friend __EXPORT int operator--(MutexCounter &mc);
523 };
524 
536 {
537 #ifndef CCXX_USE_WIN32_ATOMIC
538 private:
539 #if defined(HAVE_ATOMIC_AIX)
540  volatile int counter;
541 #elif defined(HAVE_GCC_BITS_ATOMIC)
542  volatile _Atomic_word counter;
543 #elif defined(HAVE_GCC_CXX_BITS_ATOMIC)
544  volatile _Atomic_word counter;
545 // __gnu_cxx::_Atomic_word counter;
546 #elif defined(HAVE_ATOMIC)
547  atomic_t atomic;
548 #else
549  volatile int counter;
550  pthread_mutex_t _mutex;
551 #endif
552 
553 public:
557  AtomicCounter();
558 
564  AtomicCounter(int value);
565 
566  ~AtomicCounter();
567 
568  int operator++(void);
569  int operator--(void);
570  int operator+=(int change);
571  int operator-=(int change);
572  int operator+(int change);
573  int operator-(int change);
574  int operator=(int value);
575  bool operator!(void);
576  operator int();
577 #else
578 private:
579  long atomic;
580 
581 public:
582  inline AtomicCounter()
583  {atomic = 0;};
584 
585  inline AtomicCounter(int value)
586  {atomic = value;};
587 
588  inline int operator++(void)
589  {return InterlockedIncrement(&atomic);};
590 
591  inline int operator--(void)
592  {return InterlockedDecrement(&atomic);};
593 
594  int operator+=(int change);
595 
596  int operator-=(int change);
597 
598  inline int operator+(int change)
599  {return atomic + change;};
600 
601  inline int operator-(int change)
602  {return atomic - change;};
603 
604  inline int operator=(int value)
605  {return InterlockedExchange(&atomic, value);};
606 
607  inline bool operator!(void)
608  {return (atomic == 0) ? true : false;};
609 
610  inline operator int()
611  {return atomic;};
612 #endif
613 };
614 
615 #ifndef WIN32
616 
637 {
638 private:
639  pthread_cond_t _cond;
640  pthread_mutex_t _mutex;
641 
642 public:
648  Conditional(const char *id = NULL);
649 
653  virtual ~Conditional();
654 
660  void signal(bool broadcast);
661 
668  bool wait(timeout_t timer = 0, bool locked = false);
669 
676  void enterMutex(void);
677 
686  inline void lock(void)
687  {enterMutex();};
688 
699  bool tryEnterMutex(void);
700 
701  inline bool test(void)
702  {return tryEnterMutex();};
703 
709  void leaveMutex(void);
710 
711  inline void unlock(void)
712  {return leaveMutex();};
713 };
714 #endif
715 
734 {
735 private:
736 #ifndef WIN32
737  unsigned _count, _waiters;
738  pthread_mutex_t _mutex;
739  pthread_cond_t _cond;
740 #else
741  HANDLE semObject;
742 #endif // !WIN32
743 
744 public:
753  Semaphore(unsigned resource = 0);
754 
761  virtual ~Semaphore();
762 
778  bool wait(timeout_t timeout = 0);
779 
791  void post(void);
792 
793 #ifndef WIN32
794 
802  void force_unlock_after_cancellation();
803 
804 #endif // WIN32
805 
806  // FIXME: how implement getValue for posix compatibility ?
807  // not portable...
808 #if 0
809 
814  int getValue(void);
815 #endif
816 };
817 
838 {
839 private:
841 
842 public:
846  SemaphoreLock( Semaphore& _sem ) : sem( _sem )
847  { sem.wait(); }
851  // this should be not-virtual
853  { sem.post(); }
854 };
855 
870 {
871 private:
872 #ifndef WIN32
873  pthread_mutex_t _mutex;
874  pthread_cond_t _cond;
875  bool _signaled;
876  int _count;
877 #else
878  HANDLE cond;
879 #endif
880 
881 public:
882  Event();
883 
884  virtual ~Event();
885 
892  void reset(void);
893 
897  void signal(void);
898 
907  bool wait(timeout_t timer);
908  bool wait(void);
909 };
910 
911 
1094 {
1095 public:
1099  typedef enum Throw {
1102  throwException
1103  } Throw;
1104 
1108  typedef enum Cancel {
1109  cancelInitial=0,
1110  cancelDeferred=1,
1113  cancelManual,
1115  cancelDefault=cancelDeferred
1117  } Cancel;
1118 
1122  typedef enum Suspend {
1124  suspendDisable
1125  } Suspend;
1126 
1127 #ifndef WIN32
1128 
1129 friend class PosixThread;
1130 #endif
1131 
1132 friend class DummyThread;
1133 private:
1134  friend class Cancellation;
1135  friend class postream_type;
1136  friend class Slog;
1137 
1139  static Thread* _main;
1140 
1144 
1145  // private data
1146  friend class ThreadImpl;
1147  class ThreadImpl* priv;
1148 
1149 public:
1150  static Thread *get(void);
1151 
1152 private:
1153 #ifdef WIN32
1154  static unsigned __stdcall Execute(Thread *th);
1155 #endif
1156 
1157  // close current thread, free all and call Notify
1158  void close();
1159 
1160 private:
1161  char _name[32];
1162  static size_t _autostack;
1163 
1164 #ifdef WIN32
1165  DWORD waitHandle(HANDLE obj, timeout_t timeout);
1166 #endif
1167 
1168 protected:
1176  void setName(const char *text);
1177 
1187  virtual void run(void) = 0;
1188 
1210  virtual void final(void);
1211 
1223  virtual void initial(void);
1224 
1234  virtual void* getExtended(void);
1235 
1243  virtual void notify(Thread*);
1244 
1250  void exit(void);
1251 
1255  void sync(void);
1256 
1260  bool testCancel(void);
1261 
1271  void setCancel(Cancel mode);
1272 
1280  void setSuspend(Suspend mode);
1281 
1290  void terminate(void);
1291 
1295  inline void clrParent(void)
1296  {_parent = NULL;};
1297 
1298 public:
1307  Thread(bool isMain);
1308 
1320  Thread(int pri = 0, size_t stack = 0);
1321 
1322 #ifndef WIN32
1323 
1331  Thread(const Thread &th);
1332 #endif
1333 
1340  virtual ~Thread();
1341 
1347  static void setStack(size_t size = 0)
1348  {_autostack = size;};
1349 
1359  static void sleep(timeout_t msec);
1360 
1365  static void yield(void);
1366 
1379  int start(Semaphore *start = 0);
1380 
1389  int detach(Semaphore *start = 0);
1390 
1397  inline Thread *getParent(void)
1398  {return _parent;};
1399 
1406  void suspend(void);
1407 
1411  void resume(void);
1412 
1419  inline Cancel getCancel(void)
1420  {return _cancel;};
1421 
1428  bool isRunning(void) const;
1429 
1435  bool isDetached(void) const;
1436 
1440  void join(void);
1441 
1448  bool isThread(void) const;
1449 
1455  cctid_t getId(void) const;
1456 
1463  const char *getName(void) const
1464  {return _name;};
1465 
1471  static Throw getException(void);
1472 
1478  static void setException(Throw mode);
1479 
1486  friend inline void operator++(Thread &th)
1487  {if (th._start) th._start->post();};
1488 
1489  friend inline void operator--(Thread &th)
1490  {if (th._start) th._start->wait();};
1491 
1492 #ifdef WIN32
1493  bool isCancelled() const;
1494 
1495  static DWORD waitThread(HANDLE hRef, timeout_t timeout);
1496 #endif
1497 
1505  static Cancel enterCancel(void);
1506 
1512  static void exitCancel(Cancel cancel);
1513 };
1514 
1525 {
1526 private:
1528 
1529 public:
1530  Cancellation(Thread::Cancel cancel);
1531  ~Cancellation();
1532 };
1533 
1534 #if !defined(WIN32) && !defined(__MINGW32__)
1535 typedef int signo_t;
1536 
1537 class PosixThread: public Thread
1538 {
1539 private:
1540 #ifndef WIN32
1541 
1542  friend class ThreadImpl;
1543  friend class Thread;
1544 #endif
1545 #ifndef CCXX_SIG_THREAD_ALARM
1547  static Mutex _arm;
1548 #endif
1549 
1550  time_t _alarm;
1551  static void signalThread(Thread* th,signo_t signo);
1552 protected:
1553 
1560  inline void signalParent(signo_t signo)
1561  { signalThread(_parent,signo); };
1562 
1569  inline void signalMain(signo_t signo)
1570  { signalThread(_main,signo);};
1571 
1576  virtual void onTimer(void);
1577 
1582  virtual void onHangup(void);
1583 
1588  virtual void onException(void);
1589 
1594  virtual void onDisconnect(void);
1595 
1600  virtual void onPolling(void);
1601 
1608  virtual void onSignal(int);
1609 
1622  void setTimer(timeout_t timer, bool periodic = false);
1623 
1630  timeout_t getTimer(void) const;
1631 
1637  void endTimer(void);
1638 
1639 #if defined(HAVE_SIGWAIT) || defined(HAVE_SIGWAIT2)
1640 
1646  void waitSignal(signo_t signo);
1647 #endif
1648 
1655  void setSignal(int signo, bool active);
1656 
1663  pthread_attr_t *getPthreadAttrPtr(void);
1664 
1669  pthread_t getPthreadId(void);
1670 
1671 public:
1672 
1673  PosixThread(int pri = 0, size_t stack = 0);
1674 
1680  inline void signalThread(int signo)
1681  {signalThread(this, signo);};
1682 
1689  static void sigInstall(int signo);
1690 };
1691 #endif
1692 
1708 {
1709 private:
1710 #ifndef WIN32
1711  pthread_key_t key;
1712  typedef void (*TDestruct)(void*);
1713  friend class ThreadImpl;
1714  ThreadKey(TDestruct destruct);
1715 #else
1716  DWORD key;
1717 #endif
1718 
1719 public:
1723  ThreadKey();
1724 
1728  virtual ~ThreadKey();
1729 
1737  void *getKey(void);
1738 
1746  void setKey(void *);
1747 };
1748 
1760 {
1761 #ifndef WIN32
1762  struct timeval timer;
1763 #else
1764  DWORD timer;
1765 #endif
1766  bool active;
1767 
1768 public:
1775  TimerPort();
1776 
1785  void setTimer(timeout_t timeout = 0);
1786 
1796  void incTimer(timeout_t timeout);
1797 
1807  void decTimer(timeout_t timeout);
1808 
1813  void sleepTimer(void);
1814 
1820  void endTimer(void);
1821 
1833  timeout_t getTimer(void) const;
1834 
1844  timeout_t getElapsed(void) const;
1845 };
1846 
1847 
1848 
1849 // FIXME: not in win32 implementation
1850 #if !defined(WIN32)
1851 
1852 // FIXME: private declaration ???
1853 struct timespec *getTimeout(struct timespec *spec, timeout_t timeout);
1854 
1855 #if !defined(__CYGWIN32__) && !defined(__MINGW32__)
1856 void wait(signo_t signo);
1857 #endif
1858 
1859 #endif // !WIN32
1860 
1861 #ifdef USE_POLL
1862 
1870 class Poller
1871 {
1872 private:
1873  int nufds;
1874  pollfd *ufds;
1875 
1876 public:
1877  Poller();
1878 
1879  virtual ~Poller();
1880 
1888  pollfd *getList(int cnt);
1889 
1895  inline pollfd *getList(void)
1896  {return ufds;};
1897 };
1898 #endif
1899 
1900 inline Thread *getThread(void)
1901  {return Thread::get();}
1902 
1933 {
1934 private:
1935  static Mutex timeLock;
1936 
1937 protected:
1938  inline static void lock(void)
1939  {timeLock.enterMutex();}
1940 
1941  inline static void unlock(void)
1942  {timeLock.leaveMutex();}
1943 
1944 public:
1945  static time_t getTime(time_t *tloc = NULL);
1946  static time_t time(time_t *tloc)
1947  { return getTime(tloc); };
1948 
1949  static int getTimeOfDay(struct timeval *tp);
1950  static int gettimeofday(struct timeval *tp, struct timezone *)
1951  { return getTimeOfDay(tp); };
1952 
1953  static struct tm *getLocalTime(const time_t *clock, struct tm *result);
1954  static struct tm *locatime(const time_t *clock, struct tm *result)
1955  { return getLocalTime(clock, result); };
1956 
1957  static struct tm *getGMTTime(const time_t *clock, struct tm *result);
1958  static struct tm *gmtime(const time_t *clock, struct tm *result)
1959  { return getGMTTime(clock, result);};
1960 };
1961 
1962 #ifndef HAVE_LOCALTIME_R
1963 
1964 inline struct tm *localtime_r(const time_t *t, struct tm *b)
1965  {return SysTime::getLocalTime(t, b);};
1966 inline char *ctime_r(const time_t *t, char *buf)
1967  {return ctime(t);};
1968 inline struct tm *gmtime_r(const time_t *t, struct tm *b) \
1969 {return SysTime::getGMTTime(t, b);};
1970 inline char *asctime_r(const struct tm *tm, char *b) \
1971  {return asctime(tm);};
1972 
1973 #endif
1974 
1975 #ifdef CCXX_NAMESPACES
1976 }
1977 #endif
1978 
1979 #endif
1980 
Thread * _parent
Definition: thread.h:1141
static struct tm * getLocalTime(const time_t *clock, struct tm *result)
bool test(void)
Definition: thread.h:701
The SemaphoreLock class is used to protect a section of code through a semaphore so that only x insta...
Definition: thread.h:837
Thread * getThread(void)
Definition: thread.h:1900
static void lock(void)
Definition: thread.h:1938
void lock(void)
In the future we will use lock in place of enterMutex since the conditional composite is not a recurs...
Definition: thread.h:686
time_t _alarm
Definition: thread.h:1550
int _count
Definition: thread.h:876
void unlock(void)
Definition: thread.h:711
Mutex & mutex
Definition: thread.h:331
Common C++ generic string class.
class __EXPORT Thread
Definition: thread.h:112
static Thread * _main
Definition: thread.h:1139
int volatile _level
Definition: thread.h:193
void post(void)
Posting to a semaphore increments its current value and releases the first thread waiting for the sem...
int HANDLE
Definition: serial.h:60
pthread_mutex_t _mutex
Definition: thread.h:550
Mutex mutex
Definition: thread.h:363
String _name
Definition: thread.h:190
MutexLock(Mutex &_mutex)
Acquire the mutex.
Definition: thread.h:338
struct tm * localtime_r(const time_t *t, struct tm *b)
Definition: thread.h:1964
int signo_t
Definition: thread.h:1535
pthread_cond_t _cond
Definition: thread.h:739
pthread_key_t key
Definition: thread.h:1711
static void unlock(void)
Definition: thread.h:1941
A semaphore is generally used as a synchronization object between multiple threads or to protect a li...
Definition: thread.h:733
unsigned _waiters
Definition: thread.h:737
void signalThread(int signo)
Delivers a Posix signal to the current thread.
Definition: thread.h:1680
Semaphore joinSem
Definition: thread.h:1138
The Mutex class is used to protect a section of code so that at any given time only a single thread c...
Definition: thread.h:186
friend void operator++(Thread &th)
Signal the semaphore that the specified thread is waiting for before beginning execution.
Definition: thread.h:1486
Thread * getParent(void)
Gets the pointer to the Thread class which created the current thread object.
Definition: thread.h:1397
static struct tm * gmtime(const time_t *clock, struct tm *result)
Definition: thread.h:1958
Cancel
How work cancellation.
Definition: thread.h:1108
class __EXPORT ThreadKey
Definition: thread.h:113
pthread_t cctid_t
Definition: thread.h:73
bool test(void)
Future abi will use enter/leave/test members.
Definition: thread.h:277
ignore cancellation
Definition: thread.h:1112
This class allows the creation of a thread context unique "pointer" that can be set and retrieved and...
Definition: thread.h:1707
This is a generic and portable string class.
Definition: string.h:77
void clrParent(void)
clear parent thread relationship.
Definition: thread.h:1295
static Thread * get(void)
A conditional variable synchcronization object for one to one and one to many signal and control even...
Definition: thread.h:636
void wait(signo_t signo)
unsigned long timeout_t
Definition: thread.h:74
A class to automatically set the thread cancellation mode of a member function.
Definition: thread.h:1524
friend class PosixThread
Definition: thread.h:1129
The Mutex Counter is a counter variable which can safely be incremented or decremented by multiple th...
Definition: thread.h:499
ThreadLock & tl
Definition: thread.h:471
ReadLock(ThreadLock &_tl)
Wait for read access.
Definition: thread.h:438
void signalParent(signo_t signo)
In the Posix version of Common C++, this can be used to send a signal into the parent thread of the c...
Definition: thread.h:1560
void nameMutex(const char *name)
Enable setting of mutex name for deadlock debug.
Definition: thread.h:248
static int gettimeofday(struct timeval *tp, struct timezone *)
Definition: thread.h:1950
struct tm * gmtime_r(const time_t *t, struct tm *b)
Definition: thread.h:1968
static time_t time(time_t *tloc)
Definition: thread.h:1946
void enter(void)
Future abi will use enter/leave/test members.
Definition: thread.h:263
~ReadLock()
Post the semaphore automatically.
Definition: thread.h:444
char * ctime_r(const time_t *t, char *buf)
Definition: thread.h:1966
void signalMain(signo_t signo)
In the Posix version of Common C++, this can be used to send a signal into the main application threa...
Definition: thread.h:1569
Thread *volatile _tid
Definition: thread.h:194
~SemaphoreLock()
Post the semaphore automatically.
Definition: thread.h:852
class __EXPORT Event
Definition: thread.h:141
volatile int counter
Definition: thread.h:549
Throw
How to raise error.
Definition: thread.h:1099
pthread_cond_t _cond
Definition: thread.h:874
pthread_mutex_t _mutex
Definition: thread.h:873
The ThreadLock class impliments a thread rwlock for optimal reader performance on systems which have ...
Definition: thread.h:357
Suspend
How work suspend.
Definition: thread.h:1122
static void setDebug(bool mode)
Enable or disable deadlock debugging.
Definition: thread.h:240
pthread_cond_t _cond
Definition: thread.h:639
Cancel getCancel(void)
Used to retrieve the cancellation mode in effect for the selected thread.
Definition: thread.h:1419
friend void operator--(Thread &th)
Definition: thread.h:1489
volatile int counter
Definition: thread.h:502
#define __EXPORT
Definition: audio2.h:51
throw object that cause error (throw this)
Definition: thread.h:1101
class ThreadImpl * priv
Definition: thread.h:1147
~MutexLock()
Release the mutex automatically.
Definition: thread.h:345
The slog class is used to stream messages to the system's logging facility (syslogd).
Definition: slog.h:104
Every thread of execution in an application is created by instantiating an object of a class derived ...
Definition: thread.h:1093
The Event class implements a feature originally found in the WIN32 API; event notification.
Definition: thread.h:869
struct timespec * getTimeout(struct timespec *spec, timeout_t timeout)
Semaphore & sem
Definition: thread.h:840
static size_t _autostack
Definition: thread.h:1162
class __EXPORT Conditional
Definition: thread.h:140
static void setStack(size_t size=0)
Set base stack limit before manual stack sizes have effect.
Definition: thread.h:1347
static struct tm * getGMTTime(const time_t *clock, struct tm *result)
continue without throwing error
Definition: thread.h:1100
void leave(void)
Future abi will use enter/leave/test members.
Definition: thread.h:269
bool wait(timeout_t timeout=0)
Wait is used to keep a thread held until the semaphore counter is greater than 0. ...
Thread::Cancel prior
Definition: thread.h:1527
The WriteLock class is used to protect a section of code through a ThreadLock for "write" access to t...
Definition: thread.h:468
pthread_mutex_t _mutex
Definition: thread.h:204
The ReadLock class is used to protect a section of code through a ThreadLock for "read" access to the...
Definition: thread.h:427
Timer ports are used to provide synchronized timing events when managed under a "service thread" such...
Definition: thread.h:1759
pthread_mutex_t _mutex
Definition: thread.h:738
This class is used to access non-reentrant date and time functions in the standard C library...
Definition: thread.h:1932
char * asctime_r(const struct tm *tm, char *b)
Definition: thread.h:1970
exit befor cancellation
Definition: thread.h:1111
WriteLock(ThreadLock &_tl)
Wait for write access.
Definition: thread.h:479
~WriteLock()
Post the semaphore automatically.
Definition: thread.h:485
SemaphoreLock(Semaphore &_sem)
Wait for the semaphore.
Definition: thread.h:846
bool active
Definition: thread.h:1766
const char * getName(void) const
Get the name string for this thread, to use in debug messages.
Definition: thread.h:1463
static struct tm * locatime(const time_t *clock, struct tm *result)
Definition: thread.h:1954
The AtomicCounter class offers thread-safe manipulation of an integer counter.
Definition: thread.h:535
static Mutex _arm
Definition: thread.h:1547
static Mutex timeLock
Definition: thread.h:1935
pthread_mutex_t _mutex
Definition: thread.h:640
bool _signaled
Definition: thread.h:875
The MutexLock class is used to protect a section of code so that at any given time only a single thre...
Definition: thread.h:328
Semaphore * _start
Definition: thread.h:1143
static bool _debug
Definition: thread.h:189
suspend enabled
Definition: thread.h:1123
static PosixThread * _timer
Definition: thread.h:1546
Cancel _cancel
Definition: thread.h:1142
ThreadLock & tl
Definition: thread.h:430