From: Luke Howard Date: Fri, 24 Jan 2003 05:19:57 +0000 (+0000) Subject: Support Sun DS 5.x thread abstraction layer X-Git-Tag: NO_SLAP_OP_BLOCKS~518 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=6a54a9db0fe6e82f82afde71a35cdb54c7c84f9b;p=openldap Support Sun DS 5.x thread abstraction layer --- diff --git a/servers/slapd/slapi/slapi_utils.c b/servers/slapd/slapi/slapi_utils.c index 6f722ebfd3..40f54a4799 100644 --- a/servers/slapd/slapi/slapi_utils.c +++ b/servers/slapd/slapi/slapi_utils.c @@ -44,6 +44,15 @@ static struct timeval base_time; ldap_pvt_thread_mutex_t slapi_hn_mutex; ldap_pvt_thread_mutex_t slapi_time_mutex; +struct slapi_mutex { + ldap_pvt_thread_mutex_t mutex; +}; + +struct slapi_condvar { + ldap_pvt_thread_cond_t cond; + ldap_pvt_thread_mutex_t mutex; +}; + /* * This function converts an array of pointers to berval objects to * an array of berval objects. @@ -2868,3 +2877,110 @@ int slapi_x_compute_get_pblock(computed_attr_context *c, Slapi_PBlock **pb) #endif /* LDAP_SLAPI */ } +Slapi_Mutex *slapi_new_mutex( void ) +{ +#ifdef LDAP_SLAPI + Slapi_Mutex *m; + + m = (Slapi_Mutex *)slapi_ch_malloc( sizeof(*m) ); + if ( ldap_pvt_thread_mutex_init( &m->mutex ) != 0 ) { + slapi_ch_free( (void **)&m ); + return NULL; + } + + return m; +#else + return NULL; +#endif +} + +void slapi_destroy_mutex( Slapi_Mutex *mutex ) +{ +#ifdef LDAP_SLAPI + if ( mutex != NULL ) { + ldap_pvt_thread_mutex_destroy( &mutex->mutex ); + slapi_ch_free( (void **)&mutex); + } +#endif +} + +void slapi_lock_mutex( Slapi_Mutex *mutex ) +{ +#ifdef LDAP_SLAPI + ldap_pvt_thread_mutex_lock( &mutex->mutex ); +#endif +} + +int slapi_unlock_mutex( Slapi_Mutex *mutex ) +{ +#ifdef LDAP_SLAPI + return ldap_pvt_thread_mutex_unlock( &mutex->mutex ); +#else + return -1; +#endif +} + +Slapi_CondVar *slapi_new_condvar( Slapi_Mutex *mutex ) +{ +#ifdef LDAP_SLAPI + Slapi_CondVar *cv; + + if ( mutex == NULL ) { + return NULL; + } + + cv = (Slapi_CondVar *)slapi_ch_malloc( sizeof(*cv) ); + if ( ldap_pvt_thread_cond_init( &cv->cond ) != 0 ) { + slapi_ch_free( (void **)&cv ); + return NULL; + } + + /* XXX struct copy */ + cv->mutex = mutex->mutex; + + return cv; +#else + return NULL; +#endif +} + +void slapi_destroy_condvar( Slapi_CondVar *cvar ) +{ +#ifdef LDAP_SLAPI + if ( cvar != NULL ) { + ldap_pvt_thread_cond_destroy( &cvar->cond ); + slapi_ch_free( (void **)&cvar ); + } +#endif +} + +int slapi_wait_condvar( Slapi_CondVar *cvar, struct timeval *timeout ) +{ +#ifdef LDAP_SLAPI + if ( cvar == NULL ) { + return -1; + } + + return ldap_pvt_thread_cond_wait( &cvar->cond, &cvar->mutex ); +#else + return -1; +#endif +} + +int slapi_notify_condvar( Slapi_CondVar *cvar, int notify_all ) +{ +#ifdef LDAP_SLAPI + if ( cvar == NULL ) { + return -1; + } + + if ( notify_all ) { + return ldap_pvt_thread_cond_braodcast( &cvar->cond ); + } + + return ldap_pvt_thread_cond_signal( &cvar->cond ); +#else + return -1; +#endif +} + diff --git a/servers/slapd/slapi/slapi_utils.h b/servers/slapd/slapi/slapi_utils.h index fe667e29a5..2e31d54253 100644 --- a/servers/slapd/slapi/slapi_utils.h +++ b/servers/slapd/slapi/slapi_utils.h @@ -123,6 +123,17 @@ int slapi_valueset_next_value( Slapi_ValueSet *vs, int index, Slapi_Value **v); int slapi_valueset_count( const Slapi_ValueSet *vs); void slapi_valueset_set_valueset(Slapi_ValueSet *vs1, const Slapi_ValueSet *vs2); +typedef struct slapi_mutex Slapi_Mutex; +typedef struct slapi_condvar Slapi_CondVar; +Slapi_Mutex *slapi_new_mutex( void ); +void slapi_destroy_mutex( Slapi_Mutex *mutex ); +void slapi_lock_mutex( Slapi_Mutex *mutex ); +int slapi_unlock_mutex( Slapi_Mutex *mutex ); +Slapi_CondVar *slapi_new_condvar( Slapi_Mutex *mutex ); +void slapi_destroy_condvar( Slapi_CondVar *cvar ); +int slapi_wait_condvar( Slapi_CondVar *cvar, struct timeval *timeout ); +int slapi_notify_condvar( Slapi_CondVar *cvar, int notify_all ); + char *slapi_ch_malloc( unsigned long size ); void slapi_ch_free( void **ptr ); void slapi_ch_free_string( char **s );