3 * Copyright 1998,1999 The OpenLDAP Foundation, Redwood City, California, USA
6 * Redistribution and use in source and binary forms are permitted only
7 * as authorized by the OpenLDAP Public License. A copy of this
8 * license is available at http://www.OpenLDAP.org/license.html or
9 * in file LICENSE in the top-level directory of the distribution.
11 /* ldap_pvt_thread.h - ldap threads header file NG */
13 #ifndef _LDAP_PVT_THREAD_H
14 #define _LDAP_PVT_THREAD_H
16 #include "ldap_cdefs.h"
18 #if defined( HAVE_PTHREADS )
19 /**********************************
21 * definitions for POSIX Threads *
23 **********************************/
32 typedef pthread_t ldap_pvt_thread_t;
33 typedef pthread_mutex_t ldap_pvt_thread_mutex_t;
34 typedef pthread_cond_t ldap_pvt_thread_cond_t;
36 #if defined( _POSIX_REENTRANT_FUNCTIONS ) || \
37 defined( _POSIX_THREAD_SAFE_FUNCTIONS ) || \
38 defined( _POSIX_THREADSAFE_FUNCTIONS )
39 #define HAVE_REENTRANT_FUNCTIONS 1
42 #if defined( HAVE_PTHREAD_GETCONCURRENCY ) || \
43 defined( HAVE_THR_GETCONCURRENCY )
44 #define HAVE_GETCONCURRENCY 1
47 #if defined( HAVE_PTHREAD_SETCONCURRENCY ) || \
48 defined( HAVE_THR_SETCONCURRENCY )
49 #define HAVE_SETCONCURRENCY 1
54 #elif defined ( HAVE_MACH_CTHREADS )
55 /**********************************
57 * definitions for Mach CThreads *
59 **********************************/
61 #include <mach/cthreads.h>
65 typedef cthread_t ldap_pvt_thread_t;
66 typedef struct mutex ldap_pvt_thread_mutex_t;
67 typedef struct condition ldap_pvt_thread_cond_t;
71 #elif defined( HAVE_GNU_PTH )
72 /***********************************
74 * thread definitions for GNU Pth *
76 ***********************************/
82 typedef pth_t ldap_pvt_thread_t;
83 typedef pth_mutex_t ldap_pvt_thread_mutex_t;
84 typedef pth_cond_t ldap_pvt_thread_cond_t;
89 #elif defined( HAVE_THR )
90 /********************************************
92 * thread definitions for Solaris LWP (THR) *
94 ********************************************/
101 typedef thread_t ldap_pvt_thread_t;
102 typedef mutex_t ldap_pvt_thread_mutex_t;
103 typedef cond_t ldap_pvt_thread_cond_t;
105 #define HAVE_REENTRANT_FUNCTIONS 1
107 #ifdef HAVE_THR_GETCONCURRENCY
108 #define HAVE_GETCONCURRENCY 1
110 #ifdef HAVE_THR_SETCONCURRENCY
111 #define HAVE_SETCONCURRENCY 1
116 #elif defined( HAVE_LWP )
117 /*************************************
119 * thread definitions for SunOS LWP *
121 *************************************/
124 #include <lwp/stackdep.h>
128 typedef thread_t ldap_pvt_thread_t;
129 typedef mon_t ldap_pvt_thread_mutex_t;
130 struct ldap_pvt_thread_lwp_cv {
134 typedef struct ldap_pvt_thread_lwp_cv ldap_pvt_thread_cond_t;
136 #define HAVE_REENTRANT_FUNCTIONS 1
140 /* If we're in the NT env at all, we want these defs, threaded or not */
141 #elif defined(WINNT) || defined(_WINNT) /* HAVE_NT_THREADS */
145 #define WIN32_LEAN_AND_MEAN
149 typedef unsigned long ldap_pvt_thread_t;
150 typedef HANDLE ldap_pvt_thread_mutex_t;
151 typedef HANDLE ldap_pvt_thread_cond_t;
157 /***********************************
159 * thread definitions for no *
160 * underlying library support *
162 ***********************************/
170 typedef int ldap_pvt_thread_t;
171 typedef int ldap_pvt_thread_mutex_t;
172 typedef int ldap_pvt_thread_cond_t;
176 #endif /* no threads support */
183 # define LDAP_F_PRE extern __declspec(LIBLDAP_DECL)
185 # define LDAP_F_PRE extern
190 ldap_pvt_thread_initialize LDAP_P(( void ));
193 ldap_pvt_thread_destroy LDAP_P(( void ));
195 LDAP_F( unsigned int )
196 ldap_pvt_thread_sleep LDAP_P(( unsigned int s ));
198 #ifdef HAVE_GETCONCURRENCY
200 ldap_pvt_thread_get_concurrency LDAP_P(( void ));
203 #ifdef HAVE_SETCONCURRENCY
204 # ifndef LDAP_THREAD_CONCURRENCY
205 /* three concurrent threads should be enough */
206 # define LDAP_THREAD_CONCURRENCY 3
209 ldap_pvt_thread_set_concurrency LDAP_P(( int ));
212 #define LDAP_PVT_THREAD_CREATE_JOINABLE 0
213 #define LDAP_PVT_THREAD_CREATE_DETACHED 1
216 ldap_pvt_thread_create LDAP_P((
217 ldap_pvt_thread_t * thread,
219 void *(*start_routine)( void * ),
223 ldap_pvt_thread_exit LDAP_P(( void *retval ));
226 ldap_pvt_thread_join LDAP_P(( ldap_pvt_thread_t thread, void **status ));
229 ldap_pvt_thread_kill LDAP_P(( ldap_pvt_thread_t thread, int signo ));
232 ldap_pvt_thread_yield LDAP_P(( void ));
235 ldap_pvt_thread_cond_init LDAP_P(( ldap_pvt_thread_cond_t *cond ));
238 ldap_pvt_thread_cond_destroy LDAP_P(( ldap_pvt_thread_cond_t *cond ));
241 ldap_pvt_thread_cond_signal LDAP_P(( ldap_pvt_thread_cond_t *cond ));
244 ldap_pvt_thread_cond_broadcast LDAP_P(( ldap_pvt_thread_cond_t *cond ));
247 ldap_pvt_thread_cond_wait LDAP_P((
248 ldap_pvt_thread_cond_t *cond,
249 ldap_pvt_thread_mutex_t *mutex ));
252 ldap_pvt_thread_mutex_init LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
255 ldap_pvt_thread_mutex_destroy LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
258 ldap_pvt_thread_mutex_lock LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
261 ldap_pvt_thread_mutex_trylock LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
264 ldap_pvt_thread_mutex_unlock LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
266 typedef struct ldap_pvt_thread_rdwr_var {
267 ldap_pvt_thread_mutex_t ltrw_mutex;
268 ldap_pvt_thread_cond_t ltrw_read; /* wait for read */
269 ldap_pvt_thread_cond_t ltrw_write; /* wait for write */
271 #define LDAP_PVT_THREAD_RDWR_VALID 0x0bad
276 } ldap_pvt_thread_rdwr_t;
279 ldap_pvt_thread_rdwr_init LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
282 ldap_pvt_thread_rdwr_destroy LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
285 ldap_pvt_thread_rdwr_rlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
288 ldap_pvt_thread_rdwr_rtrylock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
291 ldap_pvt_thread_rdwr_runlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
294 ldap_pvt_thread_rdwr_wlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
297 ldap_pvt_thread_rdwr_wtrylock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
300 ldap_pvt_thread_rdwr_wunlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
304 ldap_pvt_thread_rdwr_readers LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
307 ldap_pvt_thread_rdwr_writers LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
310 ldap_pvt_thread_rdwr_active LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
311 #endif /* LDAP_DEBUG */
313 #define LDAP_PVT_THREAD_EINVAL EINVAL
314 #define LDAP_PVT_THREAD_EBUSY EINVAL
318 #endif /* _LDAP_THREAD_H */