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.
18 #include "ldap_pvt_thread.h"
20 #if defined( HAVE_PTHREADS )
23 # define LDAP_PVT_THREAD_ATTR_DEFAULT pthread_attr_default
24 # define LDAP_PVT_THREAD_CONDATTR_DEFAULT pthread_condattr_default
25 # define LDAP_PVT_THREAD_MUTEXATTR_DEFAULT pthread_mutexattr_default
27 # define LDAP_PVT_THREAD_ATTR_DEFAULT NULL
28 # define LDAP_PVT_THREAD_CONDATTR_DEFAULT NULL
29 # define LDAP_PVT_THREAD_MUTEXATTR_DEFAULT NULL
34 ldap_pvt_thread_initialize( void )
36 #if defined( LDAP_THREAD_CONCURRENCY ) && HAVE_PTHREAD_SETCONCURRENCY
37 ldap_pvt_thread_set_concurrency( LDAP_THREAD_CONCURRENCY );
42 #ifdef HAVE_PTHREAD_SETCONCURRENCY
44 ldap_pvt_thread_set_concurrency(int n)
46 #ifdef HAVE_PTHREAD_SETCONCURRENCY
47 return pthread_setconcurrency( n );
48 #elif HAVE_THR_SETCONCURRENCY
49 return pthread_setconcurrency( n );
56 #ifdef HAVE_PTHREAD_GETCONCURRENCY
58 ldap_pvt_thread_get_concurrency(void)
60 #ifdef HAVE_PTHREAD_GETCONCURRENCY
61 return pthread_getconcurrency();
62 #elif HAVE_THR_GETCONCURRENCY
63 return pthread_getconcurrency();
71 ldap_pvt_thread_create( ldap_pvt_thread_t * thread,
73 void *(*start_routine)( void * ),
76 int rtn = pthread_create( thread, LDAP_PVT_THREAD_ATTR_DEFAULT,
80 #ifdef HAVE_PTHREADS_FINAL
81 pthread_detach( *thread );
83 pthread_detach( thread );
90 ldap_pvt_thread_exit( void *retval )
92 pthread_exit( retval );
96 ldap_pvt_thread_join( ldap_pvt_thread_t thread, void **thread_return )
98 #if !defined( HAVE_PTHREADS_FINAL )
100 if (thread_return==NULL)
101 thread_return=&dummy;
103 return pthread_join( thread, thread_return );
107 ldap_pvt_thread_kill( ldap_pvt_thread_t thread, int signo )
109 #ifdef HAVE_PTHREAD_KILL
110 return pthread_kill( thread, signo );
112 /* pthread package with DCE */
113 if (kill( getpid(), signo )<0)
120 ldap_pvt_thread_yield( void )
122 #ifdef HAVE_SCHED_YIELD
123 return sched_yield();
124 #elif HAVE_PTHREAD_YIELD
135 ldap_pvt_thread_cond_init( ldap_pvt_thread_cond_t *cond )
137 return pthread_cond_init( cond, LDAP_PVT_THREAD_CONDATTR_DEFAULT );
141 ldap_pvt_thread_cond_destroy( ldap_pvt_thread_cond_t *cond )
143 return pthread_cond_destroy( cond );
147 ldap_pvt_thread_cond_signal( ldap_pvt_thread_cond_t *cond )
149 return pthread_cond_signal( cond );
153 ldap_pvt_thread_cond_broadcast( ldap_pvt_thread_cond_t *cond )
155 return pthread_cond_broadcast( cond );
159 ldap_pvt_thread_cond_wait( ldap_pvt_thread_cond_t *cond,
160 ldap_pvt_thread_mutex_t *mutex )
162 return pthread_cond_wait( cond, mutex );
166 ldap_pvt_thread_mutex_init( ldap_pvt_thread_mutex_t *mutex )
168 return pthread_mutex_init( mutex, LDAP_PVT_THREAD_MUTEXATTR_DEFAULT );
172 ldap_pvt_thread_mutex_destroy( ldap_pvt_thread_mutex_t *mutex )
174 return pthread_mutex_destroy( mutex );
178 ldap_pvt_thread_mutex_lock( ldap_pvt_thread_mutex_t *mutex )
180 return pthread_mutex_lock( mutex );
184 ldap_pvt_thread_mutex_unlock( ldap_pvt_thread_mutex_t *mutex )
186 return pthread_mutex_unlock( mutex );
189 #endif /* HAVE_PTHREADS */