]> git.sur5r.net Git - openldap/commitdiff
rmutex_lock etc.: caller supplies thread id
authorHoward Chu <hyc@openldap.org>
Fri, 28 Apr 2006 21:39:38 +0000 (21:39 +0000)
committerHoward Chu <hyc@openldap.org>
Fri, 28 Apr 2006 21:39:38 +0000 (21:39 +0000)
include/ldap_pvt_thread.h
libraries/libldap_r/rmutex.c
libraries/libldap_r/threads.c
servers/slapd/overlays/accesslog.c

index 76a371ebf52f8b21f304013c9954bbb044287b26..c5db79d2cf192ad4805163ee4b695e707209f3b4 100644 (file)
@@ -130,13 +130,16 @@ LDAP_F( int )
 ldap_pvt_thread_rmutex_destroy LDAP_P(( ldap_pvt_thread_rmutex_t *rmutex ));
 
 LDAP_F( int )
-ldap_pvt_thread_rmutex_lock LDAP_P(( ldap_pvt_thread_rmutex_t *rmutex ));
+ldap_pvt_thread_rmutex_lock LDAP_P(( ldap_pvt_thread_rmutex_t *rmutex,
+       ldap_pvt_thread_t owner));
 
 LDAP_F( int )
-ldap_pvt_thread_rmutex_trylock LDAP_P(( ldap_pvt_thread_rmutex_t *rmutex ));
+ldap_pvt_thread_rmutex_trylock LDAP_P(( ldap_pvt_thread_rmutex_t *rmutex,
+       ldap_pvt_thread_t owner));
 
 LDAP_F( int )
-ldap_pvt_thread_rmutex_unlock LDAP_P(( ldap_pvt_thread_rmutex_t *rmutex ));
+ldap_pvt_thread_rmutex_unlock LDAP_P(( ldap_pvt_thread_rmutex_t *rmutex,
+       ldap_pvt_thread_t owner));
 
 LDAP_F( ldap_pvt_thread_t )
 ldap_pvt_thread_self LDAP_P(( void ));
index eb04f5674dfe82f69c6369c59a715a44979c0044..98529e42e0d5694fadea7348c2a0f129f9d3185b 100644 (file)
@@ -102,10 +102,10 @@ ldap_pvt_thread_rmutex_destroy( ldap_pvt_thread_rmutex_t *rmutex )
        return 0;
 }
 
-int ldap_pvt_thread_rmutex_lock( ldap_pvt_thread_rmutex_t *rmutex )
+int ldap_pvt_thread_rmutex_lock( ldap_pvt_thread_rmutex_t *rmutex,
+       ldap_pvt_thread_t owner )
 {
        struct ldap_int_thread_rmutex_s *rm;
-       ldap_pvt_thread_t tid;
 
        assert( rmutex != NULL );
        rm = *rmutex;
@@ -121,11 +121,9 @@ int ldap_pvt_thread_rmutex_lock( ldap_pvt_thread_rmutex_t *rmutex )
        assert( rm->ltrm_depth >= 0 );
        assert( rm->ltrm_waits >= 0 );
 
-       tid = ldap_pvt_thread_self();
-
        if( rm->ltrm_depth > 0 ) {
                /* already locked */
-               if ( !ldap_pvt_thread_equal( rm->ltrm_owner, tid )) {
+               if ( !ldap_pvt_thread_equal( rm->ltrm_owner, owner )) {
                        rm->ltrm_waits++;
                        do {
                                ldap_pvt_thread_cond_wait( &rm->ltrm_cond,
@@ -134,10 +132,10 @@ int ldap_pvt_thread_rmutex_lock( ldap_pvt_thread_rmutex_t *rmutex )
 
                        rm->ltrm_waits--;
                        assert( rm->ltrm_waits >= 0 );
-                       rm->ltrm_owner = tid;
+                       rm->ltrm_owner = owner;
                }
        } else {
-               rm->ltrm_owner = tid;
+               rm->ltrm_owner = owner;
        }
 
        rm->ltrm_depth++;
@@ -147,10 +145,10 @@ int ldap_pvt_thread_rmutex_lock( ldap_pvt_thread_rmutex_t *rmutex )
        return 0;
 }
 
-int ldap_pvt_thread_rmutex_trylock( ldap_pvt_thread_rmutex_t *rmutex )
+int ldap_pvt_thread_rmutex_trylock( ldap_pvt_thread_rmutex_t *rmutex,
+       ldap_pvt_thread_t owner )
 {
        struct ldap_int_thread_rmutex_s *rm;
-       ldap_pvt_thread_t tid;
 
        assert( rmutex != NULL );
        rm = *rmutex;
@@ -166,15 +164,13 @@ int ldap_pvt_thread_rmutex_trylock( ldap_pvt_thread_rmutex_t *rmutex )
        assert( rm->ltrm_depth >= 0 );
        assert( rm->ltrm_waits >= 0 );
 
-       tid = ldap_pvt_thread_self();
-
        if( rm->ltrm_depth > 0 ) {
-               if ( !ldap_pvt_thread_equal( tid, rm->ltrm_owner )) {
+               if ( !ldap_pvt_thread_equal( owner, rm->ltrm_owner )) {
                        ldap_pvt_thread_mutex_unlock( &rm->ltrm_mutex );
                        return LDAP_PVT_THREAD_EBUSY;
                }
        } else {
-               rm->ltrm_owner = tid;
+               rm->ltrm_owner = owner;
        }
 
        rm->ltrm_depth++;
@@ -184,10 +180,10 @@ int ldap_pvt_thread_rmutex_trylock( ldap_pvt_thread_rmutex_t *rmutex )
        return 0;
 }
 
-int ldap_pvt_thread_rmutex_unlock( ldap_pvt_thread_rmutex_t *rmutex )
+int ldap_pvt_thread_rmutex_unlock( ldap_pvt_thread_rmutex_t *rmutex,
+       ldap_pvt_thread_t owner )
 {
        struct ldap_int_thread_rmutex_s *rm;
-       ldap_pvt_thread_t tid;
 
        assert( rmutex != NULL );
        rm = *rmutex;
@@ -200,9 +196,7 @@ int ldap_pvt_thread_rmutex_unlock( ldap_pvt_thread_rmutex_t *rmutex )
 
        ldap_pvt_thread_mutex_lock( &rm->ltrm_mutex );
 
-       tid = ldap_pvt_thread_self();
-
-       if( !ldap_pvt_thread_equal( tid, rm->ltrm_owner )) {
+       if( !ldap_pvt_thread_equal( owner, rm->ltrm_owner )) {
                ldap_pvt_thread_mutex_unlock( &rm->ltrm_mutex );
                return LDAP_PVT_THREAD_EINVAL;
        }
index c810ad56be709f17ef1260080f1384ad47fd8138..b562a87d571e5f21695c8b13e08e2c96289eed0f 100644 (file)
@@ -39,6 +39,7 @@ int ldap_pvt_thread_initialize( void )
        int rc;
        static int init = 0;
        ldap_pvt_thread_rmutex_t rm;
+       ldap_pvt_thread_t tid;
 
        /* we only get one shot at this */
        if( init++ ) return -1;
@@ -53,10 +54,11 @@ int ldap_pvt_thread_initialize( void )
 
        /* kludge to pull symbol definitions in */
        ldap_pvt_thread_rmutex_init( &rm );
-       ldap_pvt_thread_rmutex_lock( &rm );
-       ldap_pvt_thread_rmutex_trylock( &rm );
-       ldap_pvt_thread_rmutex_unlock( &rm );
-       ldap_pvt_thread_rmutex_unlock( &rm );
+       tid = ldap_pvt_thread_self();
+       ldap_pvt_thread_rmutex_lock( &rm, tid );
+       ldap_pvt_thread_rmutex_trylock( &rm, tid );
+       ldap_pvt_thread_rmutex_unlock( &rm, tid );
+       ldap_pvt_thread_rmutex_unlock( &rm, tid );
        ldap_pvt_thread_rmutex_destroy( &rm );
 
        return 0;
index eccecd3a476305c6ac2b6219784fb568c339f67a..1630dcc5184b3884717edb27dcd9fd687595c4cc 100644 (file)
@@ -934,7 +934,7 @@ static int accesslog_response(Operation *op, SlapReply *rs) {
                ldap_pvt_thread_mutex_lock( &li->li_log_mutex );
                old = li->li_old;
                li->li_old = NULL;
-               ldap_pvt_thread_rmutex_unlock( &li->li_op_rmutex );
+               ldap_pvt_thread_rmutex_unlock( &li->li_op_rmutex, op->o_tid );
        }
 
        if ( li->li_success && rs->sr_err != LDAP_SUCCESS )
@@ -1253,7 +1253,7 @@ accesslog_op_mod( Operation *op, SlapReply *rs )
        log_info *li = on->on_bi.bi_private;
 
        if ( li->li_ops & LOG_OP_WRITES ) {
-               ldap_pvt_thread_rmutex_lock( &li->li_op_rmutex );
+               ldap_pvt_thread_rmutex_lock( &li->li_op_rmutex, op->o_tid );
                if ( li->li_oldf && ( op->o_tag == LDAP_REQ_DELETE ||
                        op->o_tag == LDAP_REQ_MODIFY )) {
                        int rc;