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.
15 #include "ldap_pvt_thread.h"
17 #if defined( HAVE_PTHREADS )
20 ldap_pvt_thread_initialize( void )
22 #if defined( LDAP_THREAD_CONCURRENCY ) && HAVE_PTHREAD_SETCONCURRENCY
23 ldap_pvt_thread_setconcurrency( LDAP_THREAD_CONCURRENCY );
28 #ifdef HAVE_PTHREAD_SETCONCURRENCY
30 ldap_pvt_thread_set_concurrency(int n)
32 #ifdef HAVE_PTHREAD_SETCONCURRENCY
33 return pthread_setconcurrency( n );
34 #elif HAVE_THR_SETCONCURRENCY
35 return pthread_setconcurrency( n );
42 #ifdef HAVE_PTHREAD_GETCONCURRENCY
44 ldap_pvt_thread_get_concurrency(void)
46 #ifdef HAVE_PTHREAD_GETCONCURRENCY
47 return pthread_getconcurrency();
48 #elif HAVE_THR_GETCONCURRENCY
49 return pthread_getconcurrency();
57 ldap_pvt_thread_create( ldap_pvt_thread_t * thread,
59 void *(*start_routine)( void * ),
62 int rtn = pthread_create( thread, NULL, start_routine, arg );
65 #ifdef HAVE_PTHREADS_FINAL
66 pthread_detach( *thread );
68 pthread_detach( thread );
75 ldap_pvt_thread_exit( void *retval )
77 pthread_exit( retval );
81 ldap_pvt_thread_join( ldap_pvt_thread_t thread, void **thread_return )
83 #if !defined( HAVE_PTHREADS_FINAL )
85 if (thread_return==NULL)
88 return pthread_join( thread, thread_return );
92 ldap_pvt_thread_kill( ldap_pvt_thread_t thread, int signo )
94 #ifdef HAVE_PTHREAD_KILL
95 return pthread_kill( thread, signo );
97 /* pthread package with DCE */
98 if (kill( getpid(), sig )<0)
105 ldap_pvt_thread_yield( void )
107 #ifdef HAVE_SCHED_YIELD
108 return sched_yield();
109 #elif HAVE_PTHREAD_YIELD
110 return pthread_yield();
119 ldap_pvt_thread_cond_init( ldap_pvt_thread_cond_t *cond )
121 return pthread_cond_init( cond, NULL );
125 ldap_pvt_thread_cond_destroy( ldap_pvt_thread_cond_t *cond )
127 return pthread_cond_destroy( cond );
131 ldap_pvt_thread_cond_signal( ldap_pvt_thread_cond_t *cond )
133 return pthread_cond_signal( cond );
137 ldap_pvt_thread_cond_broadcast( ldap_pvt_thread_cond_t *cond )
139 return pthread_cond_broadcast( cond );
143 ldap_pvt_thread_cond_wait( ldap_pvt_thread_cond_t *cond,
144 ldap_pvt_thread_mutex_t *mutex )
146 return pthread_cond_wait( cond, mutex );
150 ldap_pvt_thread_mutex_init( ldap_pvt_thread_mutex_t *mutex )
152 return pthread_mutex_init( mutex, NULL );
156 ldap_pvt_thread_mutex_destroy( ldap_pvt_thread_mutex_t *mutex )
158 return pthread_mutex_destroy( mutex );
162 ldap_pvt_thread_mutex_lock( ldap_pvt_thread_mutex_t *mutex )
164 return pthread_mutex_lock( mutex );
168 ldap_pvt_thread_mutex_unlock( ldap_pvt_thread_mutex_t *mutex )
170 return pthread_mutex_unlock( mutex );
173 #endif /* HAVE_PTHREADS */