2 * Copyright 1998,1999 The OpenLDAP Foundation, Redwood City, California, USA
5 * Redistribution and use in source and binary forms are permitted only
6 * as authorized by the OpenLDAP Public License. A copy of this
7 * license is available at http://www.OpenLDAP.org/license.html or
8 * in file LICENSE in the top-level directory of the distribution.
10 /* ldap_pvt_thread.h - ldap threads header file NG */
12 #ifndef _LDAP_PVT_THREAD_H
13 #define _LDAP_PVT_THREAD_H
15 #include "ldap_cdefs.h"
17 #if defined( HAVE_PTHREADS )
18 /**********************************
20 * definitions for POSIX Threads *
22 **********************************/
31 typedef pthread_t ldap_pvt_thread_t;
32 typedef pthread_mutex_t ldap_pvt_thread_mutex_t;
33 typedef pthread_cond_t ldap_pvt_thread_cond_t;
35 #if defined( _POSIX_REENTRANT_FUNCTIONS ) || \
36 defined( _POSIX_THREAD_SAFE_FUNCTIONS ) || \
37 defined( _POSIX_THREADSAFE_FUNCTIONS )
38 #define HAVE_REENTRANT_FUNCTIONS 1
41 #if defined( HAVE_PTHREAD_GETCONCURRENCY ) || \
42 defined( HAVE_THR_GETCONCURRENCY )
43 #define HAVE_GETCONCURRENCY 1
46 #if defined( HAVE_PTHREAD_SETCONCURRENCY ) || \
47 defined( HAVE_THR_SETCONCURRENCY )
48 #define HAVE_SETCONCURRENCY 1
53 #elif defined ( HAVE_MACH_CTHREADS )
54 /**********************************
56 * definitions for Mach CThreads *
58 **********************************/
60 #include <mach/cthreads.h>
64 typedef cthread_t ldap_pvt_thread_t;
65 typedef struct mutex ldap_pvt_thread_mutex_t;
66 typedef struct condition ldap_pvt_thread_cond_t;
70 #elif defined( HAVE_THR )
71 /********************************************
73 * thread definitions for Solaris LWP (THR) *
75 ********************************************/
82 typedef thread_t ldap_pvt_thread_t;
83 typedef mutex_t ldap_pvt_thread_mutex_t;
84 typedef cond_t ldap_pvt_thread_cond_t;
86 #define HAVE_REENTRANT_FUNCTIONS 1
88 #ifdef HAVE_THR_GETCONCURRENCY
89 #define HAVE_GETCONCURRENCY 1
91 #ifdef HAVE_THR_SETCONCURRENCY
92 #define HAVE_SETCONCURRENCY 1
97 #elif defined( HAVE_LWP )
98 /*************************************
100 * thread definitions for SunOS LWP *
102 *************************************/
105 #include <lwp/stackdep.h>
109 typedef thread_t ldap_pvt_thread_t;
110 typedef mon_t ldap_pvt_thread_mutex_t;
115 typedef struct lwpcv ldap_pvt_thread_cond_t;
117 #define HAVE_REENTRANT_FUNCTIONS 1
121 #elif HAVE_NT_THREADS
128 typedef HANDLE ldap_pvt_thread_t;
129 typedef HANDLE ldap_pvt_thread_mutex_t;
130 typedef HANDLE ldap_pvt_thread_cond_t;
136 /***********************************
138 * thread definitions for no *
139 * underlying library support *
141 ***********************************/
149 typedef int ldap_pvt_thread_t;
150 typedef int ldap_pvt_thread_mutex_t;
151 typedef int ldap_pvt_thread_cond_t;
155 #endif /* no threads support */
158 # define HAVE_THREADS 1
165 ldap_pvt_thread_initialize LDAP_P(( void ));
168 ldap_pvt_thread_sleep LDAP_P(( unsigned int s ));
170 #ifdef HAVE_GETCONCURRENCY
172 ldap_pvt_thread_get_concurrency LDAP_P(( void ));
174 #ifdef HAVE_SETCONCURRENCY
175 # ifndef LDAP_THREAD_CONCURRENCY
176 /* three concurrent threads should be enough */
177 # define LDAP_THREAD_CONCURRENCY 3
180 ldap_pvt_thread_set_concurrency LDAP_P(( int ));
183 #define LDAP_PVT_THREAD_CREATE_JOINABLE 0
184 #define LDAP_PVT_THREAD_CREATE_DETACHED 1
187 ldap_pvt_thread_create LDAP_P((
188 ldap_pvt_thread_t * thread,
190 void *(*start_routine)( void * ),
194 ldap_pvt_thread_exit LDAP_P(( void *retval ));
197 ldap_pvt_thread_join LDAP_P(( ldap_pvt_thread_t thread, void **status ));
200 ldap_pvt_thread_kill LDAP_P(( ldap_pvt_thread_t thread, int signo ));
203 ldap_pvt_thread_yield LDAP_P(( void ));
206 ldap_pvt_thread_cond_init LDAP_P(( ldap_pvt_thread_cond_t *cond ));
209 ldap_pvt_thread_cond_destroy LDAP_P(( ldap_pvt_thread_cond_t *cond ));
212 ldap_pvt_thread_cond_signal LDAP_P(( ldap_pvt_thread_cond_t *cond ));
215 ldap_pvt_thread_cond_broadcast LDAP_P(( ldap_pvt_thread_cond_t *cond ));
218 ldap_pvt_thread_cond_wait LDAP_P((
219 ldap_pvt_thread_cond_t *cond,
220 ldap_pvt_thread_mutex_t *mutex ));
223 ldap_pvt_thread_mutex_init LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
226 ldap_pvt_thread_mutex_destroy LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
229 ldap_pvt_thread_mutex_lock LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
232 ldap_pvt_thread_mutex_trylock LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
235 ldap_pvt_thread_mutex_unlock LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
237 typedef struct ldap_pvt_thread_rdwr_var {
238 ldap_pvt_thread_mutex_t ltrw_mutex;
239 ldap_pvt_thread_cond_t ltrw_read; /* wait for read */
240 ldap_pvt_thread_cond_t ltrw_write; /* wait for write */
242 #define LDAP_PVT_THREAD_RDWR_VALUE 0x0bad
247 } ldap_pvt_thread_rdwr_t;
250 ldap_pvt_thread_rdwr_init LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
252 ldap_pvt_thread_rdwr_destroy LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
254 ldap_pvt_thread_rdwr_rlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
256 ldap_pvt_thread_rdwr_rtrylock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
258 ldap_pvt_thread_rdwr_runlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
260 ldap_pvt_thread_rdwr_wlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
262 ldap_pvt_thread_rdwr_wtrylock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
264 ldap_pvt_thread_rdwr_wunlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
268 ldap_pvt_thread_rdwr_readers LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
270 ldap_pvt_thread_rdwr_writers LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
272 ldap_pvt_thread_rdwr_active LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
273 #endif /* LDAP_DEBUG */
275 #define LDAP_PVT_THREAD_EINVAL EINVAL
276 #define LDAP_PVT_THREAD_EBUSY EINVAL
280 #endif /* _LDAP_THREAD_H */