]> git.sur5r.net Git - openldap/commitdiff
Support Sun DS 5.x thread abstraction layer
authorLuke Howard <lukeh@openldap.org>
Fri, 24 Jan 2003 05:19:57 +0000 (05:19 +0000)
committerLuke Howard <lukeh@openldap.org>
Fri, 24 Jan 2003 05:19:57 +0000 (05:19 +0000)
servers/slapd/slapi/slapi_utils.c
servers/slapd/slapi/slapi_utils.h

index 6f722ebfd3e5109be4f07c39136608e84e83b9d7..40f54a4799f64af2a05aa0b7280539cedba54ea5 100644 (file)
@@ -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
+}
+
index fe667e29a5428b6c48244eb64aa7e332a205bfac..2e31d542536665945c0ccf6568ebd00dc15b36d1 100644 (file)
@@ -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 );