]> git.sur5r.net Git - openldap/commitdiff
Additional debug tracking...
authorHoward Chu <hyc@openldap.org>
Sat, 3 Jul 2004 16:25:30 +0000 (16:25 +0000)
committerHoward Chu <hyc@openldap.org>
Sat, 3 Jul 2004 16:25:30 +0000 (16:25 +0000)
libraries/libldap_r/rdwr.c

index dc9dcedc4b4be7c53bbd3ffcb2cb4be6c6585cba..b0613c07514a0f1bca8442007bdd3fe9d40790e8 100644 (file)
@@ -59,6 +59,12 @@ struct ldap_int_thread_rdwr_s {
        int ltrw_w_active;
        int ltrw_r_wait;
        int ltrw_w_wait;
+#ifdef LDAP_RDWR_DEBUG
+       /* keep track of who has these locks */
+#define        MAX_READERS     32
+       ldap_pvt_thread_t ltrw_readers[MAX_READERS];
+       ldap_pvt_thread_t ltrw_writer;
+#endif
 };
 
 int 
@@ -162,8 +168,12 @@ int ldap_pvt_thread_rdwr_rlock( ldap_pvt_thread_rdwr_t *rwlock )
                assert( rw->ltrw_r_wait >= 0 ); 
        }
 
+#ifdef LDAP_RDWR_DEBUG
+       rw->ltrw_readers[rw->ltrw_r_active] = ldap_pvt_thread_self();
+#endif
        rw->ltrw_r_active++;
 
+
        ldap_pvt_thread_mutex_unlock( &rw->ltrw_mutex );
 
        return 0;
@@ -194,6 +204,9 @@ int ldap_pvt_thread_rdwr_rtrylock( ldap_pvt_thread_rdwr_t *rwlock )
                return LDAP_PVT_THREAD_EBUSY;
        }
 
+#ifdef LDAP_RDWR_DEBUG
+       rw->ltrw_readers[rw->ltrw_r_active] = ldap_pvt_thread_self();
+#endif
        rw->ltrw_r_active++;
 
        ldap_pvt_thread_mutex_unlock( &rw->ltrw_mutex );
@@ -216,6 +229,22 @@ int ldap_pvt_thread_rdwr_runlock( ldap_pvt_thread_rdwr_t *rwlock )
 
        ldap_pvt_thread_mutex_lock( &rw->ltrw_mutex );
 
+#ifdef LDAP_RDWR_DEBUG
+       /* Remove us from the list of readers */
+       { int i, j;
+       ldap_pvt_thread_t self = ldap_pvt_thread_self();
+
+       for (i=0; i<rw->ltrw_r_active;i++)
+       {
+               if (rw->ltrw_readers[i] == self) {
+                       for (j=i; j<rw->ltrw_r_active-1; j++)
+                               rw->ltrw_readers[j] = rw->ltrw_readers[j+1];
+                       rw->ltrw_readers[j] = 0;
+                       break;
+               }
+       }
+       }
+#endif
        rw->ltrw_r_active--;
 
        assert( rw->ltrw_w_active >= 0 ); 
@@ -264,6 +293,9 @@ int ldap_pvt_thread_rdwr_wlock( ldap_pvt_thread_rdwr_t *rwlock )
                assert( rw->ltrw_w_wait >= 0 ); 
        }
 
+#ifdef LDAP_RDWR_DEBUG
+       rw->ltrw_writer = ldap_pvt_thread_self();
+#endif
        rw->ltrw_w_active++;
 
        ldap_pvt_thread_mutex_unlock( &rw->ltrw_mutex );
@@ -296,6 +328,9 @@ int ldap_pvt_thread_rdwr_wtrylock( ldap_pvt_thread_rdwr_t *rwlock )
                return LDAP_PVT_THREAD_EBUSY;
        }
 
+#ifdef LDAP_RDWR_DEBUG
+       rw->ltrw_writer = ldap_pvt_thread_self();
+#endif
        rw->ltrw_w_active++;
 
        ldap_pvt_thread_mutex_unlock( &rw->ltrw_mutex );
@@ -332,6 +367,9 @@ int ldap_pvt_thread_rdwr_wunlock( ldap_pvt_thread_rdwr_t *rwlock )
                ldap_pvt_thread_cond_signal( &rw->ltrw_write );
        }
 
+#ifdef LDAP_RDWR_DEBUG
+       rw->ltrw_writer = 0;
+#endif
        ldap_pvt_thread_mutex_unlock( &rw->ltrw_mutex );
 
        return 0;
@@ -397,8 +435,8 @@ int ldap_pvt_thread_rdwr_active(ldap_pvt_thread_rdwr_t *rwlock)
        assert( rw->ltrw_r_active >= 0 ); 
        assert( rw->ltrw_r_wait >= 0 ); 
 
-       return(ldap_pvt_thread_rdwr_readers(rw) +
-              ldap_pvt_thread_rdwr_writers(rw));
+       return(ldap_pvt_thread_rdwr_readers(rwlock) +
+              ldap_pvt_thread_rdwr_writers(rwlock));
 }
 
 #endif /* LDAP_DEBUG */