3 * Copyright 1998-2000 The OpenLDAP Foundation, Redwood City, California, USA
6 * Redistribution and use in source and binary forms are permitted only
7 * as authorized by the OpenLDAP Public License. A copy of this
8 * license is available at http://www.OpenLDAP.org/license.html or
9 * in file LICENSE in the top-level directory of the distribution.
12 /* thr_thr.c - wrappers around solaris threads */
16 #if defined( HAVE_GNU_PTH )
18 #include "ldap_pvt_thread.h"
26 static pth_attr_t detach_attr;
29 ldap_int_thread_initialize( void )
34 detach_attr = pth_attr_new();
35 return pth_attr_set( detach_attr, PTH_ATTR_JOINABLE, FALSE );
39 ldap_int_thread_destroy( void )
41 pth_attr_destroy(detach_attr);
47 ldap_pvt_thread_create( ldap_pvt_thread_t * thread,
49 void *(*start_routine)( void *),
52 *thread = pth_spawn( detach ? detach_attr : PTH_ATTR_DEFAULT,
55 return *thread == NULL;
59 ldap_pvt_thread_exit( void *retval )
64 int ldap_pvt_thread_join( ldap_pvt_thread_t thread, void **thread_return )
66 pth_join( thread, thread_return );
71 ldap_pvt_thread_kill( ldap_pvt_thread_t thread, int signo )
73 pth_raise( thread, signo );
78 ldap_pvt_thread_yield( void )
85 ldap_pvt_thread_cond_init( ldap_pvt_thread_cond_t *cond )
87 return( pth_cond_init( cond ) );
91 ldap_pvt_thread_cond_signal( ldap_pvt_thread_cond_t *cond )
93 return( pth_cond_notify( cond, 0 ) );
97 ldap_pvt_thread_cond_broadcast( ldap_pvt_thread_cond_t *cond )
99 return( pth_cond_notify( cond, 1 ) );
103 ldap_pvt_thread_cond_wait( ldap_pvt_thread_cond_t *cond,
104 ldap_pvt_thread_mutex_t *mutex )
106 return( pth_cond_await( cond, mutex, NULL ) );
110 ldap_pvt_thread_cond_destroy( ldap_pvt_thread_cond_t *cv )
116 ldap_pvt_thread_mutex_init( ldap_pvt_thread_mutex_t *mutex )
118 return( pth_mutex_init( mutex ) );
122 ldap_pvt_thread_mutex_destroy( ldap_pvt_thread_mutex_t *mutex )
128 ldap_pvt_thread_mutex_lock( ldap_pvt_thread_mutex_t *mutex )
130 return( pth_mutex_acquire( mutex, 0, NULL ) );
134 ldap_pvt_thread_mutex_unlock( ldap_pvt_thread_mutex_t *mutex )
136 return( pth_mutex_release( mutex ) );
140 ldap_pvt_thread_mutex_trylock( ldap_pvt_thread_mutex_t *mutex )
142 return( pth_mutex_acquire( mutex, 1, NULL ) );
145 #ifdef LDAP_THREAD_HAVE_RDWR
147 ldap_pvt_thread_rdwr_init( ldap_pvt_thread_rdwr_t *rw )
149 return pth_rwlock_init( rw );
153 ldap_pvt_thread_rdwr_destroy( ldap_pvt_thread_rdwr_t *rw )
158 int ldap_pvt_thread_rdwr_rlock( ldap_pvt_thread_rdwr_t *rw )
160 return pth_rwlock_acquire( rw, PTH_RWLOCK_RD, 0, NULL );
163 int ldap_pvt_thread_rdwr_rtrylock( ldap_pvt_thread_rdwr_t *rw )
165 return pth_rwlock_acquire( rw, PTH_RWLOCK_RD, 1, NULL );
168 int ldap_pvt_thread_rdwr_runlock( ldap_pvt_thread_rdwr_t *rw )
170 return pth_rwlock_release( rw );
173 int ldap_pvt_thread_rdwr_wlock( ldap_pvt_thread_rdwr_t *rw )
175 return pth_rwlock_acquire( rw, PTH_RWLOCK_RW, 0, NULL );
178 int ldap_pvt_thread_rdwr_wtrylock( ldap_pvt_thread_rdwr_t *rw )
180 return pth_rwlock_acquire( rw, PTH_RWLOCK_RW, 1, NULL );
183 int ldap_pvt_thread_rdwr_wunlock( ldap_pvt_thread_rdwr_t *rw )
185 return pth_rwlock_release( rw );
188 #endif /* LDAP_THREAD_HAVE_RDWR */
189 #endif /* HAVE_GNU_PTH */