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.
12 /* thr_posix.c - wrapper around posix and posixish thread implementations.
17 #if defined( HAVE_PTHREADS )
21 #include "ldap_pvt_thread.h"
25 # define LDAP_PVT_THREAD_ATTR_DEFAULT pthread_attr_default
26 # define LDAP_PVT_THREAD_CONDATTR_DEFAULT pthread_condattr_default
27 # define LDAP_PVT_THREAD_MUTEXATTR_DEFAULT pthread_mutexattr_default
29 # define LDAP_PVT_THREAD_ATTR_DEFAULT NULL
30 # define LDAP_PVT_THREAD_CONDATTR_DEFAULT NULL
31 # define LDAP_PVT_THREAD_MUTEXATTR_DEFAULT NULL
36 ldap_pvt_thread_initialize( void )
38 #if defined( LDAP_THREAD_CONCURRENCY ) && HAVE_PTHREAD_SETCONCURRENCY
39 ldap_pvt_thread_set_concurrency( LDAP_THREAD_CONCURRENCY );
45 ldap_pvt_thread_destroy( void )
50 #ifdef HAVE_PTHREAD_SETCONCURRENCY
52 ldap_pvt_thread_set_concurrency(int n)
54 #ifdef HAVE_PTHREAD_SETCONCURRENCY
55 return pthread_setconcurrency( n );
56 #elif HAVE_THR_SETCONCURRENCY
57 return pthread_setconcurrency( n );
64 #ifdef HAVE_PTHREAD_GETCONCURRENCY
66 ldap_pvt_thread_get_concurrency(void)
68 #ifdef HAVE_PTHREAD_GETCONCURRENCY
69 return pthread_getconcurrency();
70 #elif HAVE_THR_GETCONCURRENCY
71 return pthread_getconcurrency();
79 ldap_pvt_thread_create( ldap_pvt_thread_t * thread,
81 void *(*start_routine)( void * ),
84 int rtn = pthread_create( thread, LDAP_PVT_THREAD_ATTR_DEFAULT,
88 #ifdef HAVE_PTHREADS_FINAL
89 pthread_detach( *thread );
91 pthread_detach( thread );
98 ldap_pvt_thread_exit( void *retval )
100 pthread_exit( retval );
104 ldap_pvt_thread_join( ldap_pvt_thread_t thread, void **thread_return )
106 #if !defined( HAVE_PTHREADS_FINAL )
108 if (thread_return==NULL)
109 thread_return=&dummy;
111 return pthread_join( thread, thread_return );
115 ldap_pvt_thread_kill( ldap_pvt_thread_t thread, int signo )
117 #ifdef HAVE_PTHREAD_KILL
118 return pthread_kill( thread, signo );
120 /* pthread package with DCE */
121 if (kill( getpid(), signo )<0)
128 ldap_pvt_thread_yield( void )
130 #ifdef _POSIX_THREAD_IS_GNU_PTH
134 #elif HAVE_SCHED_YIELD
135 return sched_yield();
137 #elif HAVE_PTHREAD_YIELD
150 ldap_pvt_thread_cond_init( ldap_pvt_thread_cond_t *cond )
152 return pthread_cond_init( cond, LDAP_PVT_THREAD_CONDATTR_DEFAULT );
156 ldap_pvt_thread_cond_destroy( ldap_pvt_thread_cond_t *cond )
158 return pthread_cond_destroy( cond );
162 ldap_pvt_thread_cond_signal( ldap_pvt_thread_cond_t *cond )
164 return pthread_cond_signal( cond );
168 ldap_pvt_thread_cond_broadcast( ldap_pvt_thread_cond_t *cond )
170 return pthread_cond_broadcast( cond );
174 ldap_pvt_thread_cond_wait( ldap_pvt_thread_cond_t *cond,
175 ldap_pvt_thread_mutex_t *mutex )
177 return pthread_cond_wait( cond, mutex );
181 ldap_pvt_thread_mutex_init( ldap_pvt_thread_mutex_t *mutex )
183 return pthread_mutex_init( mutex, LDAP_PVT_THREAD_MUTEXATTR_DEFAULT );
187 ldap_pvt_thread_mutex_destroy( ldap_pvt_thread_mutex_t *mutex )
189 return pthread_mutex_destroy( mutex );
193 ldap_pvt_thread_mutex_lock( ldap_pvt_thread_mutex_t *mutex )
195 return pthread_mutex_lock( mutex );
199 ldap_pvt_thread_mutex_unlock( ldap_pvt_thread_mutex_t *mutex )
201 return pthread_mutex_unlock( mutex );
204 #endif /* HAVE_PTHREADS */