1 /* thrposix.c - wrapper around posix and posixish thread implementations.
5 #include "ldap_pvt_thread.h"
7 #if defined( HAVE_PTHREADS )
10 ldap_pvt_thread_create( ldap_pvt_thread_t * thread,
11 ldap_pvt_thread_attr_t *attr,
12 void *(*start_routine)( void *), void *arg)
14 #if !defined( HAVE_PTHREADS_D4 )
15 /* This is a standard pthreads implementation. */
16 return pthread_create( thread, attr, start_routine, arg );
18 /* This is a draft 4 or earlier implementation. */
19 return pthread_create( thread, *attr, start_routine, arg );
24 ldap_pvt_thread_exit( void *retval )
26 pthread_exit( retval );
30 ldap_pvt_thread_join( ldap_pvt_thread_t thread, void **thread_return )
32 #if !defined( HAVE_PTHREADS_FINAL )
34 if (thread_return==NULL)
37 return pthread_join( thread, thread_return );
41 ldap_pvt_thread_kill( ldap_pvt_thread_t thread, int signo )
43 #ifdef HAVE_PTHREAD_KILL
44 return pthread_kill( thread, signo );
46 /* pthread package with DCE */
47 if (kill( getpid(), sig )<0)
54 ldap_pvt_thread_yield( void )
56 #ifdef HAVE_SCHED_YIELD
59 return pthread_yield();
64 ldap_pvt_thread_attr_init( ldap_pvt_thread_attr_t *attr )
66 #if defined( HAVE_PTHREAD_ATTR_INIT )
67 return pthread_attr_init( attr );
68 #elif defined( HAVE_PTHREAD_ATTR_CREATE )
69 return pthread_attr_create( attr );
71 No way to init attr, so cause an error.
76 ldap_pvt_thread_attr_destroy( ldap_pvt_thread_attr_t *attr )
78 #if defined( HAVE_PTHREAD_ATTR_DESTROY )
79 return pthread_attr_destroy( attr );
80 #elif defined( HAVE_PTHREAD_ATTR_DELETE )
81 return pthread_attr_delete( attr );
83 No way to destroy attr, so cause an error.
88 ldap_pvt_thread_attr_setdetachstate( ldap_pvt_thread_attr_t *attr, int dstate )
90 #if defined( HAVE_PTHREAD_ATTR_SETDETACHSTATE )
91 return pthread_attr_setdetachstate( attr, dstate );
92 #elif defined( HAVE_PTHREAD_ATTR_SETDETACH_NP )
93 return pthread_attr_setdetach_np( attr, dstate );
95 No way to set state, so cause an error.
100 ldap_pvt_thread_cond_init( ldap_pvt_thread_cond_t *cond,
101 ldap_pvt_thread_condattr_t *attr )
103 #if defined( HAVE_PTHREADS_D4 )
104 return pthread_cond_init( cond,
105 attr ? attr : pthread_condattr_default );
107 return pthread_cond_init( cond, attr );
112 ldap_pvt_thread_cond_signal( ldap_pvt_thread_cond_t *cond )
114 return pthread_cond_signal( cond );
118 ldap_pvt_thread_cond_broadcast( ldap_pvt_thread_cond_t *cond )
120 return pthread_cond_broadcast( cond );
124 ldap_pvt_thread_cond_wait( ldap_pvt_thread_cond_t *cond,
125 ldap_pvt_thread_mutex_t *mutex )
127 return pthread_cond_wait( cond, mutex );
131 ldap_pvt_thread_mutex_init( ldap_pvt_thread_mutex_t *mutex,
132 ldap_pvt_thread_mutexattr_t *attr )
134 #if defined( HAVE_PTHREADS_D4 )
135 return pthread_mutex_init( mutex,
136 attr ? attr : pthread_mutexattr_default );
138 return pthread_mutex_init( mutex, attr );
143 ldap_pvt_thread_mutex_destroy( ldap_pvt_thread_mutex_t *mutex )
145 return pthread_mutex_destroy( mutex );
149 ldap_pvt_thread_mutex_lock( ldap_pvt_thread_mutex_t *mutex )
151 return pthread_mutex_lock( mutex );
155 ldap_pvt_thread_mutex_unlock( ldap_pvt_thread_mutex_t *mutex )
157 return pthread_mutex_unlock( mutex );
160 #endif /* HAVE_PTHREADS */