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.
11 /* thr_posix.c - wrapper around posix and posixish thread implementations.
16 #if defined( HAVE_PTHREADS )
20 #include "ldap_pvt_thread.h"
24 # define LDAP_PVT_THREAD_ATTR_DEFAULT pthread_attr_default
25 # define LDAP_PVT_THREAD_CONDATTR_DEFAULT pthread_condattr_default
26 # define LDAP_PVT_THREAD_MUTEXATTR_DEFAULT pthread_mutexattr_default
28 # define LDAP_PVT_THREAD_ATTR_DEFAULT NULL
29 # define LDAP_PVT_THREAD_CONDATTR_DEFAULT NULL
30 # define LDAP_PVT_THREAD_MUTEXATTR_DEFAULT NULL
35 ldap_pvt_thread_initialize( void )
37 #if defined( LDAP_THREAD_CONCURRENCY ) && HAVE_PTHREAD_SETCONCURRENCY
38 ldap_pvt_thread_set_concurrency( LDAP_THREAD_CONCURRENCY );
44 ldap_pvt_thread_destroy( void )
49 #ifdef HAVE_PTHREAD_SETCONCURRENCY
51 ldap_pvt_thread_set_concurrency(int n)
53 #ifdef HAVE_PTHREAD_SETCONCURRENCY
54 return pthread_setconcurrency( n );
55 #elif HAVE_THR_SETCONCURRENCY
56 return pthread_setconcurrency( n );
63 #ifdef HAVE_PTHREAD_GETCONCURRENCY
65 ldap_pvt_thread_get_concurrency(void)
67 #ifdef HAVE_PTHREAD_GETCONCURRENCY
68 return pthread_getconcurrency();
69 #elif HAVE_THR_GETCONCURRENCY
70 return pthread_getconcurrency();
78 ldap_pvt_thread_create( ldap_pvt_thread_t * thread,
80 void *(*start_routine)( void * ),
83 int rtn = pthread_create( thread, LDAP_PVT_THREAD_ATTR_DEFAULT,
87 #ifdef HAVE_PTHREADS_FINAL
88 pthread_detach( *thread );
90 pthread_detach( thread );
97 ldap_pvt_thread_exit( void *retval )
99 pthread_exit( retval );
103 ldap_pvt_thread_join( ldap_pvt_thread_t thread, void **thread_return )
105 #if !defined( HAVE_PTHREADS_FINAL )
107 if (thread_return==NULL)
108 thread_return=&dummy;
110 return pthread_join( thread, thread_return );
114 ldap_pvt_thread_kill( ldap_pvt_thread_t thread, int signo )
116 #ifdef HAVE_PTHREAD_KILL
117 return pthread_kill( thread, signo );
119 /* pthread package with DCE */
120 if (kill( getpid(), signo )<0)
127 ldap_pvt_thread_yield( void )
129 #ifdef _POSIX_THREAD_IS_GNU_PTH
133 #elif HAVE_SCHED_YIELD
134 return sched_yield();
136 #elif HAVE_PTHREAD_YIELD
149 ldap_pvt_thread_cond_init( ldap_pvt_thread_cond_t *cond )
151 return pthread_cond_init( cond, LDAP_PVT_THREAD_CONDATTR_DEFAULT );
155 ldap_pvt_thread_cond_destroy( ldap_pvt_thread_cond_t *cond )
157 return pthread_cond_destroy( cond );
161 ldap_pvt_thread_cond_signal( ldap_pvt_thread_cond_t *cond )
163 return pthread_cond_signal( cond );
167 ldap_pvt_thread_cond_broadcast( ldap_pvt_thread_cond_t *cond )
169 return pthread_cond_broadcast( cond );
173 ldap_pvt_thread_cond_wait( ldap_pvt_thread_cond_t *cond,
174 ldap_pvt_thread_mutex_t *mutex )
176 return pthread_cond_wait( cond, mutex );
180 ldap_pvt_thread_mutex_init( ldap_pvt_thread_mutex_t *mutex )
182 return pthread_mutex_init( mutex, LDAP_PVT_THREAD_MUTEXATTR_DEFAULT );
186 ldap_pvt_thread_mutex_destroy( ldap_pvt_thread_mutex_t *mutex )
188 return pthread_mutex_destroy( mutex );
192 ldap_pvt_thread_mutex_lock( ldap_pvt_thread_mutex_t *mutex )
194 return pthread_mutex_lock( mutex );
198 ldap_pvt_thread_mutex_unlock( ldap_pvt_thread_mutex_t *mutex )
200 return pthread_mutex_unlock( mutex );
203 #endif /* HAVE_PTHREADS */