lthread.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. /** BEGIN COPYRIGHT BLOCK
  2. * This Program is free software; you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation; version 2 of the License.
  5. *
  6. * This Program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with
  11. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  12. * Place, Suite 330, Boston, MA 02111-1307 USA.
  13. *
  14. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  15. * right to link the code of this Program with code not covered under the GNU
  16. * General Public License ("Non-GPL Code") and to distribute linked combinations
  17. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  18. * permitted under this exception must only link to the code of this Program
  19. * through those well defined interfaces identified in the file named EXCEPTION
  20. * found in the source code files (the "Approved Interfaces"). The files of
  21. * Non-GPL Code may instantiate templates or use macros or inline functions from
  22. * the Approved Interfaces without causing the resulting work to be covered by
  23. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  24. * additions to the list of Approved Interfaces. You must obey the GNU General
  25. * Public License in all respects for all of the Program code and other code used
  26. * in conjunction with the Program except the Non-GPL Code covered by this
  27. * exception. If you modify this file, you may extend this exception to your
  28. * version of the file, but you are not obligated to do so. If you do not wish to
  29. * provide this exception without modification, you must delete this exception
  30. * statement from your version and license this file solely under the GPL without
  31. * exception.
  32. *
  33. *
  34. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  35. * Copyright (C) 2005 Red Hat, Inc.
  36. * All rights reserved.
  37. * END COPYRIGHT BLOCK **/
  38. #ifdef HAVE_CONFIG_H
  39. # include <config.h>
  40. #endif
  41. /* lthread.h - ldap threads header file */
  42. #ifndef _LTHREAD_H
  43. #define _LTHREAD_H
  44. #if defined( THREAD_SUNOS4_LWP )
  45. /***********************************
  46. * *
  47. * thread definitions for sunos4 *
  48. * *
  49. ***********************************/
  50. #define _THREAD
  51. #include <lwp/lwp.h>
  52. #include <lwp/stackdep.h>
  53. typedef void *(*VFP)();
  54. /* thread attributes and thread type */
  55. typedef int pthread_attr_t;
  56. typedef thread_t pthread_t;
  57. /* default attr states */
  58. #define pthread_mutexattr_default NULL
  59. #define pthread_condattr_default NULL
  60. /* thread state - joinable or not */
  61. #define PTHREAD_CREATE_JOINABLE 0
  62. #define PTHREAD_CREATE_DETACHED 1
  63. /* thread scope - who is in scheduling pool */
  64. #define PTHREAD_SCOPE_PROCESS 0
  65. #define PTHREAD_SCOPE_SYSTEM 1
  66. /* mutex attributes and mutex type */
  67. typedef int pthread_mutexattr_t;
  68. typedef mon_t pthread_mutex_t;
  69. /* mutex and condition variable scope - process or system */
  70. #define PTHREAD_SHARE_PRIVATE 0
  71. #define PTHREAD_SHARE_PROCESS 1
  72. /* condition variable attributes and condition variable type */
  73. typedef int pthread_condattr_t;
  74. typedef struct lwpcv {
  75. int lcv_created;
  76. cv_t lcv_cv;
  77. } pthread_cond_t;
  78. #else /* end sunos4 */
  79. #if defined( THREAD_SUNOS5_LWP )
  80. /***********************************
  81. * *
  82. * thread definitions for sunos5 *
  83. * *
  84. ***********************************/
  85. #define _THREAD
  86. #include <thread.h>
  87. #include <synch.h>
  88. typedef void *(*VFP)();
  89. /* sunos5 threads are preemptive */
  90. #define PTHREAD_PREEMPTIVE 1
  91. /* thread attributes and thread type */
  92. typedef int pthread_attr_t;
  93. typedef thread_t pthread_t;
  94. /* default attr states */
  95. #define pthread_mutexattr_default NULL
  96. #define pthread_condattr_default NULL
  97. /* thread state - joinable or not */
  98. #define PTHREAD_CREATE_JOINABLE 0
  99. #define PTHREAD_CREATE_DETACHED THR_DETACHED
  100. /* thread scope - who is in scheduling pool */
  101. #define PTHREAD_SCOPE_PROCESS 0
  102. #define PTHREAD_SCOPE_SYSTEM THR_BOUND
  103. /* mutex attributes and mutex type */
  104. typedef int pthread_mutexattr_t;
  105. typedef mutex_t pthread_mutex_t;
  106. /* mutex and condition variable scope - process or system */
  107. #define PTHREAD_SHARE_PRIVATE USYNC_THREAD
  108. #define PTHREAD_SHARE_PROCESS USYNC_PROCESS
  109. /* condition variable attributes and condition variable type */
  110. typedef int pthread_condattr_t;
  111. typedef cond_t pthread_cond_t;
  112. #else /* end sunos5 */
  113. #if defined( THREAD_MIT_PTHREADS )
  114. /***********************************
  115. * *
  116. * definitions for mit pthreads *
  117. * *
  118. ***********************************/
  119. #define _THREAD
  120. #include <pthread.h>
  121. #else /* end mit pthreads */
  122. #if defined( THREAD_AIX_PTHREADS )
  123. /***********************************
  124. * *
  125. * definitions for aix pthreads *
  126. * *
  127. ***********************************/
  128. #define _THREAD
  129. #include <pthread.h>
  130. typedef void *(*VFP)(void *);
  131. /* thread state - joinable or not */
  132. #define PTHREAD_CREATE_JOINABLE 0
  133. /* default attr states */
  134. #define pthread_mutexattr_default NULL
  135. #define pthread_condattr_default NULL
  136. #else /* aix pthreads */
  137. #if defined( THREAD_HP_DCE_PTHREADS )
  138. /**************************************
  139. * *
  140. * definitions for HP dce pthreads *
  141. * *
  142. **************************************/
  143. #define _THREAD
  144. typedef void *(*VFP)();
  145. #include <pthread.h>
  146. /* dce threads are preemptive */
  147. #define PTHREAD_PREEMPTIVE 1
  148. /* pthread_kill() is a noop on HP */
  149. #define PTHREAD_KILL_IS_NOOP 1
  150. /* thread state - joinable or not */
  151. #define PTHREAD_CREATE_JOINABLE 0
  152. #define PTHREAD_CREATE_DETACHED 1
  153. #define pthread_attr_init( a ) pthread_attr_create( a )
  154. #define pthread_attr_destroy( a ) pthread_attr_delete( a )
  155. #define pthread_attr_setdetachstate( a, b ) \
  156. pthread_attr_setdetach_np( a, b )
  157. /*
  158. * HP's DCE threads implementation passes a (pthread_attr_t *)
  159. * for the second argument. So, we need to fake things a bit.
  160. * hpdce_pthread_create_detached() is in thread.c. Note that we
  161. * create threads and detach them. If you need to create a joinable
  162. * thread, you need to call hpdce_pthread_create_joinable() directly.
  163. */
  164. #define pthread_create( a, b, c, d ) \
  165. hpdce_pthread_create_detached( a, b, c, d )
  166. int
  167. hpdce_pthread_create_joinable( pthread_t *tid, pthread_attr_t *attr,
  168. VFP func, void *arg );
  169. int hpdce_pthread_create_detached( pthread_t *tid, pthread_attr_t *attr,
  170. VFP func, void *arg );
  171. #else /* HP dce pthreads */
  172. #if defined( THREAD_DCE_PTHREADS )
  173. /***********************************
  174. * *
  175. * definitions for dce pthreads *
  176. * *
  177. ***********************************/
  178. #define _THREAD
  179. typedef void *(*VFP)();
  180. #include <pthread.h>
  181. /* dce threads are preemptive */
  182. #define PTHREAD_PREEMPTIVE 1
  183. /* thread state - joinable or not */
  184. #ifndef PTHREAD_CREATE_JOINABLE
  185. #define PTHREAD_CREATE_JOINABLE 0
  186. #endif
  187. #ifndef PTHREAD_CREATE_DETACHED
  188. #define PTHREAD_CREATE_DETACHED 1
  189. #endif
  190. #define pthread_attr_init( a ) pthread_attr_create( a )
  191. #define pthread_attr_destroy( a ) pthread_attr_delete( a )
  192. #define pthread_attr_setdetachstate( a, b ) \
  193. pthread_attr_setdetach_np( a, b )
  194. #if defined( OSF1 )
  195. /* pthread_create's second parameter is passed by value, not by reference.
  196. * To work around this, call another function instead:
  197. */
  198. #define pthread_create( a, b, c, d ) std_pthread_create( a, b, c, d )
  199. extern int
  200. std_pthread_create (pthread_t *tid,
  201. pthread_attr_t *attr,
  202. pthread_startroutine_t func,
  203. pthread_addr_t arg); /* defined in thread.c */
  204. /* OSF1 doesn't support pthread_kill() */
  205. #define PTHREAD_KILL_IS_NOOP 1
  206. #endif /* OSF1 */
  207. #else /* dce pthreads */
  208. #if defined( THREAD_SGI_SPROC )
  209. /***********************************
  210. * *
  211. * thread definitions for sgi irix *
  212. * *
  213. ***********************************/
  214. #define _THREAD
  215. #include <sys/types.h>
  216. #include <sys/signal.h>
  217. #include <sys/procset.h>
  218. #include <sys/prctl.h>
  219. #include <ulocks.h>
  220. typedef void *(*VFP)(void *);
  221. /* sgi threads are preemptive */
  222. #define PTHREAD_PREEMPTIVE 1
  223. /* thread attributes and thread type */
  224. typedef int pthread_attr_t;
  225. typedef pid_t pthread_t;
  226. /* default attr states */
  227. #define pthread_mutexattr_default 0
  228. #define pthread_condattr_default 0
  229. /* thread state - joinable or not */
  230. #define PTHREAD_CREATE_JOINABLE 0
  231. #define PTHREAD_CREATE_DETACHED 1
  232. /* thread scope - who is in scheduling pool */
  233. #define PTHREAD_SCOPE_PROCESS 0
  234. #define PTHREAD_SCOPE_SYSTEM 1
  235. /* mutex attributes and mutex type */
  236. typedef int pthread_mutexattr_t;
  237. typedef int pthread_mutex_t;
  238. /* mutex and condition variable scope - process or system */
  239. #define PTHREAD_SHARE_PRIVATE 0
  240. #define PTHREAD_SHARE_PROCESS 1
  241. /* condition variable attributes and condition variable type */
  242. typedef int pthread_condattr_t;
  243. struct irix_cv_waiter {
  244. pid_t icvw_pid;
  245. struct irix_cv_waiter *icvw_next;
  246. };
  247. typedef struct irix_cv {
  248. pthread_mutex_t icv_mutex;
  249. pthread_mutex_t *icv_waitermutex;
  250. struct irix_cv_waiter *icv_waiterq;
  251. } pthread_cond_t;
  252. #else
  253. #if defined( WIN32_KERNEL_THREADS )
  254. /***********************************
  255. * *
  256. * thread definitions for Win32 *
  257. * *
  258. ***********************************/
  259. #define _THREAD
  260. #include <windows.h>
  261. #include <process.h>
  262. #include "ldap.h"
  263. #include "ldaplog.h"
  264. typedef void (*VFP)(void *);
  265. /* Win32 threads are preemptive */
  266. #define PTHREAD_PREEMPTIVE 1
  267. /* thread attributes and thread type */
  268. typedef int pthread_attr_t;
  269. typedef HANDLE pthread_t;
  270. /* default attr states */
  271. #define pthread_mutexattr_default 0
  272. #define pthread_condattr_default 0
  273. /* thread state - joinable or not */
  274. #define PTHREAD_CREATE_JOINABLE 0
  275. #define PTHREAD_CREATE_DETACHED 1
  276. /* thread scope - who is in scheduling pool */
  277. #define PTHREAD_SCOPE_PROCESS 0
  278. #define PTHREAD_SCOPE_SYSTEM 1
  279. /* mutex attributes and mutex type */
  280. typedef int pthread_mutexattr_t;
  281. typedef HANDLE pthread_mutex_t;
  282. /* mutex and condition variable scope - process or system */
  283. #define PTHREAD_SHARE_PRIVATE 0
  284. #define PTHREAD_SHARE_PROCESS 1
  285. /* condition variable attributes and condition variable type */
  286. typedef int pthread_condattr_t;
  287. /* simulated condition variable */
  288. struct win32_cv_waiter {
  289. pthread_t icvw_pthread;
  290. struct win32_cv_waiter *icvw_next;
  291. };
  292. typedef struct win32_cv {
  293. pthread_mutex_t icv_mutex;
  294. pthread_mutex_t *icv_waitermutex;
  295. struct win32_cv_waiter *icv_waiterq;
  296. } pthread_cond_t;
  297. #endif /* NATIVE_WIN32_THREADS */
  298. #endif /* sgi sproc */
  299. #endif /* dce pthreads */
  300. #endif /* hp dce pthreads */
  301. #endif /* aix pthreads */
  302. #endif /* mit pthreads */
  303. #endif /* sunos5 */
  304. #endif /* sunos4 */
  305. #ifndef _THREAD
  306. /***********************************
  307. * *
  308. * thread definitions for no *
  309. * underlying library support *
  310. * *
  311. ***********************************/
  312. typedef void *(*VFP)();
  313. /* thread attributes and thread type */
  314. typedef int pthread_attr_t;
  315. typedef int pthread_t;
  316. /* default attr states */
  317. #define pthread_mutexattr_default NULL
  318. #define pthread_condattr_default NULL
  319. /* thread state - joinable or not */
  320. #define PTHREAD_CREATE_JOINABLE 0
  321. #define PTHREAD_CREATE_DETACHED 0
  322. /* thread scope - who is in scheduling pool */
  323. #define PTHREAD_SCOPE_PROCESS 0
  324. #define PTHREAD_SCOPE_SYSTEM 0
  325. /* mutex attributes and mutex type */
  326. typedef int pthread_mutexattr_t;
  327. typedef int pthread_mutex_t;
  328. /* mutex and condition variable scope - process or system */
  329. #define PTHREAD_SHARE_PRIVATE 0
  330. #define PTHREAD_SHARE_PROCESS 0
  331. /* condition variable attributes and condition variable type */
  332. typedef int pthread_condattr_t;
  333. typedef int pthread_cond_t;
  334. #endif /* no threads support */
  335. /* POSIX standard pthread function declarations: */
  336. int pthread_attr_init( pthread_attr_t *attr );
  337. int pthread_attr_destroy( pthread_attr_t *attr );
  338. int pthread_attr_getdetachstate( pthread_attr_t *attr, int *detachstate );
  339. int pthread_attr_setdetachstate( pthread_attr_t *attr, int detachstate );
  340. int pthread_create( pthread_t *tid, pthread_attr_t *attr, VFP func, void *arg );
  341. void pthread_yield();
  342. void pthread_exit();
  343. int pthread_kill( pthread_t tid, int sig );
  344. #if defined( hpux ) || defined( OSF1 ) || defined( AIXV4 ) /* <thread.h> declares pthread_join */
  345. #else
  346. int pthread_join( pthread_t tid, int *status );
  347. #endif
  348. #if defined( hpux ) || defined( OSF1 ) /* <thread.h> declares pthread_mutex_init */
  349. #else
  350. int pthread_mutex_init( pthread_mutex_t *mp, pthread_mutexattr_t *attr );
  351. #endif
  352. int pthread_mutex_destroy( pthread_mutex_t *mp );
  353. int pthread_mutex_lock( pthread_mutex_t *mp );
  354. int pthread_mutex_unlock( pthread_mutex_t *mp );
  355. int pthread_mutex_trylock( pthread_mutex_t *mp );
  356. #if defined( hpux ) || defined( OSF1 ) /* <thread.h> declares pthread_cond_init */
  357. #else
  358. int pthread_cond_init( pthread_cond_t *cv, pthread_condattr_t *attr );
  359. #endif
  360. int pthread_cond_destroy( pthread_cond_t *cv );
  361. int pthread_cond_wait( pthread_cond_t *cv, pthread_mutex_t *mp );
  362. int pthread_cond_signal( pthread_cond_t *cv );
  363. int pthread_cond_broadcast( pthread_cond_t *cv );
  364. #endif /* _LTHREAD_H */