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
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;
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 );
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 );
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 );
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 );
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;
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 */