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 ldap_pvt_thread_initialize( void )
25 #if defined( LDAP_THREAD_CONCURRENCY ) && HAVE_PTHREAD_SETCONCURRENCY
26 ldap_pvt_thread_set_concurrency( LDAP_THREAD_CONCURRENCY );
31 #ifdef HAVE_PTHREAD_SETCONCURRENCY
33 ldap_pvt_thread_set_concurrency(int n)
35 #ifdef HAVE_PTHREAD_SETCONCURRENCY
36 return pthread_setconcurrency( n );
37 #elif HAVE_THR_SETCONCURRENCY
38 return pthread_setconcurrency( n );
45 #ifdef HAVE_PTHREAD_GETCONCURRENCY
47 ldap_pvt_thread_get_concurrency(void)
49 #ifdef HAVE_PTHREAD_GETCONCURRENCY
50 return pthread_getconcurrency();
51 #elif HAVE_THR_GETCONCURRENCY
52 return pthread_getconcurrency();
60 ldap_pvt_thread_create( ldap_pvt_thread_t * thread,
62 void *(*start_routine)( void * ),
65 int rtn = pthread_create( thread, NULL, start_routine, arg );
68 #ifdef HAVE_PTHREADS_FINAL
69 pthread_detach( *thread );
71 pthread_detach( thread );
78 ldap_pvt_thread_exit( void *retval )
80 pthread_exit( retval );
84 ldap_pvt_thread_join( ldap_pvt_thread_t thread, void **thread_return )
86 #if !defined( HAVE_PTHREADS_FINAL )
88 if (thread_return==NULL)
91 return pthread_join( thread, thread_return );
95 ldap_pvt_thread_kill( ldap_pvt_thread_t thread, int signo )
97 #ifdef HAVE_PTHREAD_KILL
98 return pthread_kill( thread, signo );
100 /* pthread package with DCE */
101 if (kill( getpid(), signo )<0)
108 ldap_pvt_thread_yield( void )
110 #ifdef HAVE_SCHED_YIELD
111 return sched_yield();
112 #elif HAVE_PTHREAD_YIELD
113 return pthread_yield();
122 ldap_pvt_thread_cond_init( ldap_pvt_thread_cond_t *cond )
124 return pthread_cond_init( cond, NULL );
128 ldap_pvt_thread_cond_destroy( ldap_pvt_thread_cond_t *cond )
130 return pthread_cond_destroy( cond );
134 ldap_pvt_thread_cond_signal( ldap_pvt_thread_cond_t *cond )
136 return pthread_cond_signal( cond );
140 ldap_pvt_thread_cond_broadcast( ldap_pvt_thread_cond_t *cond )
142 return pthread_cond_broadcast( cond );
146 ldap_pvt_thread_cond_wait( ldap_pvt_thread_cond_t *cond,
147 ldap_pvt_thread_mutex_t *mutex )
149 return pthread_cond_wait( cond, mutex );
153 ldap_pvt_thread_mutex_init( ldap_pvt_thread_mutex_t *mutex )
155 return pthread_mutex_init( mutex, NULL );
159 ldap_pvt_thread_mutex_destroy( ldap_pvt_thread_mutex_t *mutex )
161 return pthread_mutex_destroy( mutex );
165 ldap_pvt_thread_mutex_lock( ldap_pvt_thread_mutex_t *mutex )
167 return pthread_mutex_lock( mutex );
171 ldap_pvt_thread_mutex_unlock( ldap_pvt_thread_mutex_t *mutex )
173 return pthread_mutex_unlock( mutex );
176 #endif /* HAVE_PTHREADS */