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 );
43 ldap_pvt_thread_destroy( void )
48 #ifdef HAVE_PTHREAD_SETCONCURRENCY
50 ldap_pvt_thread_set_concurrency(int n)
52 #ifdef HAVE_PTHREAD_SETCONCURRENCY
53 return pthread_setconcurrency( n );
54 #elif HAVE_THR_SETCONCURRENCY
55 return pthread_setconcurrency( n );
62 #ifdef HAVE_PTHREAD_GETCONCURRENCY
64 ldap_pvt_thread_get_concurrency(void)
66 #ifdef HAVE_PTHREAD_GETCONCURRENCY
67 return pthread_getconcurrency();
68 #elif HAVE_THR_GETCONCURRENCY
69 return pthread_getconcurrency();
77 ldap_pvt_thread_create( ldap_pvt_thread_t * thread,
79 void *(*start_routine)( void * ),
82 int rtn = pthread_create( thread, LDAP_PVT_THREAD_ATTR_DEFAULT,
86 #ifdef HAVE_PTHREADS_FINAL
87 pthread_detach( *thread );
89 pthread_detach( thread );
96 ldap_pvt_thread_exit( void *retval )
98 pthread_exit( retval );
102 ldap_pvt_thread_join( ldap_pvt_thread_t thread, void **thread_return )
104 #if !defined( HAVE_PTHREADS_FINAL )
106 if (thread_return==NULL)
107 thread_return=&dummy;
109 return pthread_join( thread, thread_return );
113 ldap_pvt_thread_kill( ldap_pvt_thread_t thread, int signo )
115 #ifdef HAVE_PTHREAD_KILL
116 return pthread_kill( thread, signo );
118 /* pthread package with DCE */
119 if (kill( getpid(), signo )<0)
126 ldap_pvt_thread_yield( void )
128 #ifdef HAVE_SCHED_YIELD
129 return sched_yield();
130 #elif HAVE_PTHREAD_YIELD
141 ldap_pvt_thread_cond_init( ldap_pvt_thread_cond_t *cond )
143 return pthread_cond_init( cond, LDAP_PVT_THREAD_CONDATTR_DEFAULT );
147 ldap_pvt_thread_cond_destroy( ldap_pvt_thread_cond_t *cond )
149 return pthread_cond_destroy( cond );
153 ldap_pvt_thread_cond_signal( ldap_pvt_thread_cond_t *cond )
155 return pthread_cond_signal( cond );
159 ldap_pvt_thread_cond_broadcast( ldap_pvt_thread_cond_t *cond )
161 return pthread_cond_broadcast( cond );
165 ldap_pvt_thread_cond_wait( ldap_pvt_thread_cond_t *cond,
166 ldap_pvt_thread_mutex_t *mutex )
168 return pthread_cond_wait( cond, mutex );
172 ldap_pvt_thread_mutex_init( ldap_pvt_thread_mutex_t *mutex )
174 return pthread_mutex_init( mutex, LDAP_PVT_THREAD_MUTEXATTR_DEFAULT );
178 ldap_pvt_thread_mutex_destroy( ldap_pvt_thread_mutex_t *mutex )
180 return pthread_mutex_destroy( mutex );
184 ldap_pvt_thread_mutex_lock( ldap_pvt_thread_mutex_t *mutex )
186 return pthread_mutex_lock( mutex );
190 ldap_pvt_thread_mutex_unlock( ldap_pvt_thread_mutex_t *mutex )
192 return pthread_mutex_unlock( mutex );
195 #endif /* HAVE_PTHREADS */