lthread.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  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. /* lthread.h - ldap threads header file */
  39. #ifndef _LTHREAD_H
  40. #define _LTHREAD_H
  41. #if defined( THREAD_SUNOS4_LWP )
  42. /***********************************
  43. * *
  44. * thread definitions for sunos4 *
  45. * *
  46. ***********************************/
  47. #define _THREAD
  48. #include <lwp/lwp.h>
  49. #include <lwp/stackdep.h>
  50. typedef void *(*VFP)();
  51. /* thread attributes and thread type */
  52. typedef int pthread_attr_t;
  53. typedef thread_t pthread_t;
  54. /* default attr states */
  55. #define pthread_mutexattr_default NULL
  56. #define pthread_condattr_default NULL
  57. /* thread state - joinable or not */
  58. #define PTHREAD_CREATE_JOINABLE 0
  59. #define PTHREAD_CREATE_DETACHED 1
  60. /* thread scope - who is in scheduling pool */
  61. #define PTHREAD_SCOPE_PROCESS 0
  62. #define PTHREAD_SCOPE_SYSTEM 1
  63. /* mutex attributes and mutex type */
  64. typedef int pthread_mutexattr_t;
  65. typedef mon_t pthread_mutex_t;
  66. /* mutex and condition variable scope - process or system */
  67. #define PTHREAD_SHARE_PRIVATE 0
  68. #define PTHREAD_SHARE_PROCESS 1
  69. /* condition variable attributes and condition variable type */
  70. typedef int pthread_condattr_t;
  71. typedef struct lwpcv {
  72. int lcv_created;
  73. cv_t lcv_cv;
  74. } pthread_cond_t;
  75. #else /* end sunos4 */
  76. #if defined( THREAD_SUNOS5_LWP )
  77. /***********************************
  78. * *
  79. * thread definitions for sunos5 *
  80. * *
  81. ***********************************/
  82. #define _THREAD
  83. #include <thread.h>
  84. #include <synch.h>
  85. typedef void *(*VFP)();
  86. /* sunos5 threads are preemptive */
  87. #define PTHREAD_PREEMPTIVE 1
  88. /* thread attributes and thread type */
  89. typedef int pthread_attr_t;
  90. typedef thread_t pthread_t;
  91. /* default attr states */
  92. #define pthread_mutexattr_default NULL
  93. #define pthread_condattr_default NULL
  94. /* thread state - joinable or not */
  95. #define PTHREAD_CREATE_JOINABLE 0
  96. #define PTHREAD_CREATE_DETACHED THR_DETACHED
  97. /* thread scope - who is in scheduling pool */
  98. #define PTHREAD_SCOPE_PROCESS 0
  99. #define PTHREAD_SCOPE_SYSTEM THR_BOUND
  100. /* mutex attributes and mutex type */
  101. typedef int pthread_mutexattr_t;
  102. typedef mutex_t pthread_mutex_t;
  103. /* mutex and condition variable scope - process or system */
  104. #define PTHREAD_SHARE_PRIVATE USYNC_THREAD
  105. #define PTHREAD_SHARE_PROCESS USYNC_PROCESS
  106. /* condition variable attributes and condition variable type */
  107. typedef int pthread_condattr_t;
  108. typedef cond_t pthread_cond_t;
  109. #else /* end sunos5 */
  110. #if defined( THREAD_MIT_PTHREADS )
  111. /***********************************
  112. * *
  113. * definitions for mit pthreads *
  114. * *
  115. ***********************************/
  116. #define _THREAD
  117. #include <pthread.h>
  118. #else /* end mit pthreads */
  119. #if defined( THREAD_AIX_PTHREADS )
  120. /***********************************
  121. * *
  122. * definitions for aix pthreads *
  123. * *
  124. ***********************************/
  125. #define _THREAD
  126. #include <pthread.h>
  127. typedef void *(*VFP)(void *);
  128. /* thread state - joinable or not */
  129. #define PTHREAD_CREATE_JOINABLE 0
  130. /* default attr states */
  131. #define pthread_mutexattr_default NULL
  132. #define pthread_condattr_default NULL
  133. #else /* aix pthreads */
  134. #if defined( THREAD_HP_DCE_PTHREADS )
  135. /**************************************
  136. * *
  137. * definitions for HP dce pthreads *
  138. * *
  139. **************************************/
  140. #define _THREAD
  141. typedef void *(*VFP)();
  142. #include <pthread.h>
  143. /* dce threads are preemptive */
  144. #define PTHREAD_PREEMPTIVE 1
  145. /* pthread_kill() is a noop on HP */
  146. #define PTHREAD_KILL_IS_NOOP 1
  147. /* thread state - joinable or not */
  148. #define PTHREAD_CREATE_JOINABLE 0
  149. #define PTHREAD_CREATE_DETACHED 1
  150. #define pthread_attr_init( a ) pthread_attr_create( a )
  151. #define pthread_attr_destroy( a ) pthread_attr_delete( a )
  152. #define pthread_attr_setdetachstate( a, b ) \
  153. pthread_attr_setdetach_np( a, b )
  154. /*
  155. * HP's DCE threads implementation passes a (pthread_attr_t *)
  156. * for the second argument. So, we need to fake things a bit.
  157. * hpdce_pthread_create_detached() is in thread.c. Note that we
  158. * create threads and detach them. If you need to create a joinable
  159. * thread, you need to call hpdce_pthread_create_joinable() directly.
  160. */
  161. #define pthread_create( a, b, c, d ) \
  162. hpdce_pthread_create_detached( a, b, c, d )
  163. int
  164. hpdce_pthread_create_joinable( pthread_t *tid, pthread_attr_t *attr,
  165. VFP func, void *arg );
  166. int hpdce_pthread_create_detached( pthread_t *tid, pthread_attr_t *attr,
  167. VFP func, void *arg );
  168. #else /* HP dce pthreads */
  169. #if defined( THREAD_DCE_PTHREADS )
  170. /***********************************
  171. * *
  172. * definitions for dce pthreads *
  173. * *
  174. ***********************************/
  175. #define _THREAD
  176. typedef void *(*VFP)();
  177. #include <pthread.h>
  178. /* dce threads are preemptive */
  179. #define PTHREAD_PREEMPTIVE 1
  180. /* thread state - joinable or not */
  181. #ifndef PTHREAD_CREATE_JOINABLE
  182. #define PTHREAD_CREATE_JOINABLE 0
  183. #endif
  184. #ifndef PTHREAD_CREATE_DETACHED
  185. #define PTHREAD_CREATE_DETACHED 1
  186. #endif
  187. #define pthread_attr_init( a ) pthread_attr_create( a )
  188. #define pthread_attr_destroy( a ) pthread_attr_delete( a )
  189. #define pthread_attr_setdetachstate( a, b ) \
  190. pthread_attr_setdetach_np( a, b )
  191. #if defined( OSF1 )
  192. /* pthread_create's second parameter is passed by value, not by reference.
  193. * To work around this, call another function instead:
  194. */
  195. #define pthread_create( a, b, c, d ) std_pthread_create( a, b, c, d )
  196. extern int
  197. std_pthread_create (pthread_t *tid,
  198. pthread_attr_t *attr,
  199. pthread_startroutine_t func,
  200. pthread_addr_t arg); /* defined in thread.c */
  201. /* OSF1 doesn't support pthread_kill() */
  202. #define PTHREAD_KILL_IS_NOOP 1
  203. #endif /* OSF1 */
  204. #else /* dce pthreads */
  205. #if defined( THREAD_SGI_SPROC )
  206. /***********************************
  207. * *
  208. * thread definitions for sgi irix *
  209. * *
  210. ***********************************/
  211. #define _THREAD
  212. #include <sys/types.h>
  213. #include <sys/signal.h>
  214. #include <sys/procset.h>
  215. #include <sys/prctl.h>
  216. #include <ulocks.h>
  217. typedef void *(*VFP)(void *);
  218. /* sgi threads are preemptive */
  219. #define PTHREAD_PREEMPTIVE 1
  220. /* thread attributes and thread type */
  221. typedef int pthread_attr_t;
  222. typedef pid_t pthread_t;
  223. /* default attr states */
  224. #define pthread_mutexattr_default 0
  225. #define pthread_condattr_default 0
  226. /* thread state - joinable or not */
  227. #define PTHREAD_CREATE_JOINABLE 0
  228. #define PTHREAD_CREATE_DETACHED 1
  229. /* thread scope - who is in scheduling pool */
  230. #define PTHREAD_SCOPE_PROCESS 0
  231. #define PTHREAD_SCOPE_SYSTEM 1
  232. /* mutex attributes and mutex type */
  233. typedef int pthread_mutexattr_t;
  234. typedef int pthread_mutex_t;
  235. /* mutex and condition variable scope - process or system */
  236. #define PTHREAD_SHARE_PRIVATE 0
  237. #define PTHREAD_SHARE_PROCESS 1
  238. /* condition variable attributes and condition variable type */
  239. typedef int pthread_condattr_t;
  240. struct irix_cv_waiter {
  241. pid_t icvw_pid;
  242. struct irix_cv_waiter *icvw_next;
  243. };
  244. typedef struct irix_cv {
  245. pthread_mutex_t icv_mutex;
  246. pthread_mutex_t *icv_waitermutex;
  247. struct irix_cv_waiter *icv_waiterq;
  248. } pthread_cond_t;
  249. #else
  250. #if defined( WIN32_KERNEL_THREADS )
  251. /***********************************
  252. * *
  253. * thread definitions for Win32 *
  254. * *
  255. ***********************************/
  256. #define _THREAD
  257. #include <windows.h>
  258. #include <process.h>
  259. #include "ldap.h"
  260. #include "ldaplog.h"
  261. typedef void (*VFP)(void *);
  262. /* Win32 threads are preemptive */
  263. #define PTHREAD_PREEMPTIVE 1
  264. /* thread attributes and thread type */
  265. typedef int pthread_attr_t;
  266. typedef HANDLE pthread_t;
  267. /* default attr states */
  268. #define pthread_mutexattr_default 0
  269. #define pthread_condattr_default 0
  270. /* thread state - joinable or not */
  271. #define PTHREAD_CREATE_JOINABLE 0
  272. #define PTHREAD_CREATE_DETACHED 1
  273. /* thread scope - who is in scheduling pool */
  274. #define PTHREAD_SCOPE_PROCESS 0
  275. #define PTHREAD_SCOPE_SYSTEM 1
  276. /* mutex attributes and mutex type */
  277. typedef int pthread_mutexattr_t;
  278. typedef HANDLE pthread_mutex_t;
  279. /* mutex and condition variable scope - process or system */
  280. #define PTHREAD_SHARE_PRIVATE 0
  281. #define PTHREAD_SHARE_PROCESS 1
  282. /* condition variable attributes and condition variable type */
  283. typedef int pthread_condattr_t;
  284. /* simulated condition variable */
  285. struct win32_cv_waiter {
  286. pthread_t icvw_pthread;
  287. struct win32_cv_waiter *icvw_next;
  288. };
  289. typedef struct win32_cv {
  290. pthread_mutex_t icv_mutex;
  291. pthread_mutex_t *icv_waitermutex;
  292. struct win32_cv_waiter *icv_waiterq;
  293. } pthread_cond_t;
  294. #endif /* NATIVE_WIN32_THREADS */
  295. #endif /* sgi sproc */
  296. #endif /* dce pthreads */
  297. #endif /* hp dce pthreads */
  298. #endif /* aix pthreads */
  299. #endif /* mit pthreads */
  300. #endif /* sunos5 */
  301. #endif /* sunos4 */
  302. #ifndef _THREAD
  303. /***********************************
  304. * *
  305. * thread definitions for no *
  306. * underlying library support *
  307. * *
  308. ***********************************/
  309. typedef void *(*VFP)();
  310. /* thread attributes and thread type */
  311. typedef int pthread_attr_t;
  312. typedef int pthread_t;
  313. /* default attr states */
  314. #define pthread_mutexattr_default NULL
  315. #define pthread_condattr_default NULL
  316. /* thread state - joinable or not */
  317. #define PTHREAD_CREATE_JOINABLE 0
  318. #define PTHREAD_CREATE_DETACHED 0
  319. /* thread scope - who is in scheduling pool */
  320. #define PTHREAD_SCOPE_PROCESS 0
  321. #define PTHREAD_SCOPE_SYSTEM 0
  322. /* mutex attributes and mutex type */
  323. typedef int pthread_mutexattr_t;
  324. typedef int pthread_mutex_t;
  325. /* mutex and condition variable scope - process or system */
  326. #define PTHREAD_SHARE_PRIVATE 0
  327. #define PTHREAD_SHARE_PROCESS 0
  328. /* condition variable attributes and condition variable type */
  329. typedef int pthread_condattr_t;
  330. typedef int pthread_cond_t;
  331. #endif /* no threads support */
  332. /* POSIX standard pthread function declarations: */
  333. int pthread_attr_init( pthread_attr_t *attr );
  334. int pthread_attr_destroy( pthread_attr_t *attr );
  335. int pthread_attr_getdetachstate( pthread_attr_t *attr, int *detachstate );
  336. int pthread_attr_setdetachstate( pthread_attr_t *attr, int detachstate );
  337. int pthread_create( pthread_t *tid, pthread_attr_t *attr, VFP func, void *arg );
  338. void pthread_yield();
  339. void pthread_exit();
  340. int pthread_kill( pthread_t tid, int sig );
  341. #if defined( hpux ) || defined( OSF1 ) || defined( AIXV4 ) /* <thread.h> declares pthread_join */
  342. #else
  343. int pthread_join( pthread_t tid, int *status );
  344. #endif
  345. #if defined( hpux ) || defined( OSF1 ) /* <thread.h> declares pthread_mutex_init */
  346. #else
  347. int pthread_mutex_init( pthread_mutex_t *mp, pthread_mutexattr_t *attr );
  348. #endif
  349. int pthread_mutex_destroy( pthread_mutex_t *mp );
  350. int pthread_mutex_lock( pthread_mutex_t *mp );
  351. int pthread_mutex_unlock( pthread_mutex_t *mp );
  352. int pthread_mutex_trylock( pthread_mutex_t *mp );
  353. #if defined( hpux ) || defined( OSF1 ) /* <thread.h> declares pthread_cond_init */
  354. #else
  355. int pthread_cond_init( pthread_cond_t *cv, pthread_condattr_t *attr );
  356. #endif
  357. int pthread_cond_destroy( pthread_cond_t *cv );
  358. int pthread_cond_wait( pthread_cond_t *cv, pthread_mutex_t *mp );
  359. int pthread_cond_signal( pthread_cond_t *cv );
  360. int pthread_cond_broadcast( pthread_cond_t *cv );
  361. #endif /* _LTHREAD_H */