1999-09-09 03:06:24 +08:00
|
|
|
/* $OpenLDAP$ */
|
2003-05-25 11:31:21 +08:00
|
|
|
/*
|
|
|
|
* Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
|
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
*/
|
1999-01-15 22:54:25 +08:00
|
|
|
/*
|
1999-02-05 02:00:50 +08:00
|
|
|
** This is an improved implementation of Reader/Writer locks does
|
|
|
|
** not protect writers from starvation. That is, if a writer is
|
1999-01-15 22:54:25 +08:00
|
|
|
** currently waiting on a reader, any new reader will get
|
|
|
|
** the lock before the writer.
|
1999-02-05 02:00:50 +08:00
|
|
|
**
|
|
|
|
** Does not support cancellation nor does any status checking.
|
1999-01-15 22:54:25 +08:00
|
|
|
*/
|
2000-06-07 05:20:38 +08:00
|
|
|
/* Adapted from publically available examples for:
|
1999-02-05 02:00:50 +08:00
|
|
|
* "Programming with Posix Threads"
|
2000-06-07 05:20:38 +08:00
|
|
|
* by David R Butenhof, Addison-Wesley
|
|
|
|
* http://cseng.aw.com/bookpage.taf?ISBN=0-201-63392-2
|
1999-01-15 22:54:25 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
1999-06-03 08:37:44 +08:00
|
|
|
#include <ac/stdlib.h>
|
1999-01-15 22:54:25 +08:00
|
|
|
|
1999-02-05 02:00:50 +08:00
|
|
|
#include <ac/errno.h>
|
1999-03-02 06:37:05 +08:00
|
|
|
#include <ac/string.h>
|
2000-06-13 10:42:13 +08:00
|
|
|
#include <ac/time.h>
|
1999-03-02 06:37:05 +08:00
|
|
|
|
2000-06-13 10:42:13 +08:00
|
|
|
#include "ldap-int.h"
|
1999-01-15 22:54:25 +08:00
|
|
|
#include "ldap_pvt_thread.h"
|
|
|
|
|
2000-06-07 05:20:38 +08:00
|
|
|
/*
|
2000-06-07 07:46:45 +08:00
|
|
|
* implementations that provide their own compatible
|
|
|
|
* reader/writer locks define LDAP_THREAD_HAVE_RDWR
|
|
|
|
* in ldap_pvt_thread.h
|
2000-06-07 05:20:38 +08:00
|
|
|
*/
|
|
|
|
#ifndef LDAP_THREAD_HAVE_RDWR
|
|
|
|
|
2000-06-13 10:42:13 +08:00
|
|
|
struct ldap_int_thread_rdwr_s {
|
|
|
|
ldap_pvt_thread_mutex_t ltrw_mutex;
|
|
|
|
ldap_pvt_thread_cond_t ltrw_read; /* wait for read */
|
|
|
|
ldap_pvt_thread_cond_t ltrw_write; /* wait for write */
|
|
|
|
int ltrw_valid;
|
|
|
|
#define LDAP_PVT_THREAD_RDWR_VALID 0x0bad
|
|
|
|
int ltrw_r_active;
|
|
|
|
int ltrw_w_active;
|
|
|
|
int ltrw_r_wait;
|
|
|
|
int ltrw_w_wait;
|
|
|
|
};
|
|
|
|
|
1999-01-15 22:54:25 +08:00
|
|
|
int
|
2000-06-13 10:42:13 +08:00
|
|
|
ldap_pvt_thread_rdwr_init( ldap_pvt_thread_rdwr_t *rwlock )
|
1999-01-15 22:54:25 +08:00
|
|
|
{
|
2000-06-13 10:42:13 +08:00
|
|
|
struct ldap_int_thread_rdwr_s *rw;
|
|
|
|
|
|
|
|
assert( rwlock != NULL );
|
1999-05-19 09:12:33 +08:00
|
|
|
|
2000-06-13 10:42:13 +08:00
|
|
|
rw = (struct ldap_int_thread_rdwr_s *) LDAP_CALLOC( 1,
|
|
|
|
sizeof( struct ldap_int_thread_rdwr_s ) );
|
1999-02-05 02:00:50 +08:00
|
|
|
|
|
|
|
/* we should check return results */
|
|
|
|
ldap_pvt_thread_mutex_init( &rw->ltrw_mutex );
|
|
|
|
ldap_pvt_thread_cond_init( &rw->ltrw_read );
|
|
|
|
ldap_pvt_thread_cond_init( &rw->ltrw_write );
|
|
|
|
|
1999-04-27 13:18:21 +08:00
|
|
|
rw->ltrw_valid = LDAP_PVT_THREAD_RDWR_VALID;
|
2000-06-13 10:42:13 +08:00
|
|
|
|
|
|
|
*rwlock = rw;
|
1999-01-15 22:54:25 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-01-29 14:05:18 +08:00
|
|
|
int
|
2000-06-13 10:42:13 +08:00
|
|
|
ldap_pvt_thread_rdwr_destroy( ldap_pvt_thread_rdwr_t *rwlock )
|
1999-01-29 14:05:18 +08:00
|
|
|
{
|
2000-06-13 10:42:13 +08:00
|
|
|
struct ldap_int_thread_rdwr_s *rw;
|
|
|
|
|
|
|
|
assert( rwlock != NULL );
|
|
|
|
rw = *rwlock;
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
assert( rw != NULL );
|
|
|
|
assert( rw->ltrw_valid == LDAP_PVT_THREAD_RDWR_VALID );
|
|
|
|
|
1999-04-27 13:18:21 +08:00
|
|
|
if( rw->ltrw_valid != LDAP_PVT_THREAD_RDWR_VALID )
|
1999-02-05 02:00:50 +08:00
|
|
|
return LDAP_PVT_THREAD_EINVAL;
|
|
|
|
|
|
|
|
ldap_pvt_thread_mutex_lock( &rw->ltrw_mutex );
|
|
|
|
|
2000-06-17 05:25:03 +08:00
|
|
|
assert( rw->ltrw_w_active >= 0 );
|
|
|
|
assert( rw->ltrw_w_wait >= 0 );
|
|
|
|
assert( rw->ltrw_r_active >= 0 );
|
|
|
|
assert( rw->ltrw_r_wait >= 0 );
|
|
|
|
|
1999-02-05 02:00:50 +08:00
|
|
|
/* active threads? */
|
1999-12-09 07:54:33 +08:00
|
|
|
if( rw->ltrw_r_active > 0 || rw->ltrw_w_active > 0) {
|
1999-02-05 02:00:50 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( &rw->ltrw_mutex );
|
|
|
|
return LDAP_PVT_THREAD_EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* waiting threads? */
|
|
|
|
if( rw->ltrw_r_wait > 0 || rw->ltrw_w_wait > 0) {
|
|
|
|
ldap_pvt_thread_mutex_unlock( &rw->ltrw_mutex );
|
|
|
|
return LDAP_PVT_THREAD_EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
rw->ltrw_valid = 0;
|
|
|
|
|
1999-04-06 09:55:11 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( &rw->ltrw_mutex );
|
1999-04-06 11:23:40 +08:00
|
|
|
|
1999-02-05 02:00:50 +08:00
|
|
|
ldap_pvt_thread_mutex_destroy( &rw->ltrw_mutex );
|
|
|
|
ldap_pvt_thread_cond_destroy( &rw->ltrw_read );
|
|
|
|
ldap_pvt_thread_cond_destroy( &rw->ltrw_write );
|
|
|
|
|
2000-06-13 10:42:13 +08:00
|
|
|
LDAP_FREE(rw);
|
|
|
|
*rwlock = NULL;
|
1999-01-29 14:05:18 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-06-13 10:42:13 +08:00
|
|
|
int ldap_pvt_thread_rdwr_rlock( ldap_pvt_thread_rdwr_t *rwlock )
|
1999-02-05 02:00:50 +08:00
|
|
|
{
|
2000-06-13 10:42:13 +08:00
|
|
|
struct ldap_int_thread_rdwr_s *rw;
|
|
|
|
|
|
|
|
assert( rwlock != NULL );
|
|
|
|
rw = *rwlock;
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
assert( rw != NULL );
|
|
|
|
assert( rw->ltrw_valid == LDAP_PVT_THREAD_RDWR_VALID );
|
|
|
|
|
1999-04-27 13:18:21 +08:00
|
|
|
if( rw->ltrw_valid != LDAP_PVT_THREAD_RDWR_VALID )
|
1999-02-05 02:00:50 +08:00
|
|
|
return LDAP_PVT_THREAD_EINVAL;
|
|
|
|
|
|
|
|
ldap_pvt_thread_mutex_lock( &rw->ltrw_mutex );
|
|
|
|
|
2000-06-17 05:25:03 +08:00
|
|
|
assert( rw->ltrw_w_active >= 0 );
|
|
|
|
assert( rw->ltrw_w_wait >= 0 );
|
|
|
|
assert( rw->ltrw_r_active >= 0 );
|
|
|
|
assert( rw->ltrw_r_wait >= 0 );
|
|
|
|
|
1999-12-09 07:54:33 +08:00
|
|
|
if( rw->ltrw_w_active > 0 ) {
|
1999-02-05 02:00:50 +08:00
|
|
|
/* writer is active */
|
|
|
|
|
|
|
|
rw->ltrw_r_wait++;
|
|
|
|
|
|
|
|
do {
|
|
|
|
ldap_pvt_thread_cond_wait(
|
|
|
|
&rw->ltrw_read, &rw->ltrw_mutex );
|
1999-12-09 07:54:33 +08:00
|
|
|
} while( rw->ltrw_w_active > 0 );
|
1999-02-05 02:00:50 +08:00
|
|
|
|
|
|
|
rw->ltrw_r_wait--;
|
2000-06-17 05:25:03 +08:00
|
|
|
assert( rw->ltrw_r_wait >= 0 );
|
1999-01-15 22:54:25 +08:00
|
|
|
}
|
1999-02-05 02:00:50 +08:00
|
|
|
|
|
|
|
rw->ltrw_r_active++;
|
|
|
|
|
|
|
|
ldap_pvt_thread_mutex_unlock( &rw->ltrw_mutex );
|
|
|
|
|
1999-01-15 22:54:25 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-06-13 10:42:13 +08:00
|
|
|
int ldap_pvt_thread_rdwr_rtrylock( ldap_pvt_thread_rdwr_t *rwlock )
|
1999-01-15 22:54:25 +08:00
|
|
|
{
|
2000-06-13 10:42:13 +08:00
|
|
|
struct ldap_int_thread_rdwr_s *rw;
|
|
|
|
|
|
|
|
assert( rwlock != NULL );
|
|
|
|
rw = *rwlock;
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
assert( rw != NULL );
|
|
|
|
assert( rw->ltrw_valid == LDAP_PVT_THREAD_RDWR_VALID );
|
|
|
|
|
1999-04-27 13:18:21 +08:00
|
|
|
if( rw->ltrw_valid != LDAP_PVT_THREAD_RDWR_VALID )
|
1999-02-05 02:00:50 +08:00
|
|
|
return LDAP_PVT_THREAD_EINVAL;
|
|
|
|
|
|
|
|
ldap_pvt_thread_mutex_lock( &rw->ltrw_mutex );
|
|
|
|
|
2000-06-17 05:25:03 +08:00
|
|
|
assert( rw->ltrw_w_active >= 0 );
|
|
|
|
assert( rw->ltrw_w_wait >= 0 );
|
|
|
|
assert( rw->ltrw_r_active >= 0 );
|
|
|
|
assert( rw->ltrw_r_wait >= 0 );
|
|
|
|
|
1999-12-09 07:54:33 +08:00
|
|
|
if( rw->ltrw_w_active > 0) {
|
1999-02-05 02:00:50 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( &rw->ltrw_mutex );
|
|
|
|
return LDAP_PVT_THREAD_EBUSY;
|
1999-01-15 22:54:25 +08:00
|
|
|
}
|
1999-02-05 02:00:50 +08:00
|
|
|
|
|
|
|
rw->ltrw_r_active++;
|
|
|
|
|
|
|
|
ldap_pvt_thread_mutex_unlock( &rw->ltrw_mutex );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-06-13 10:42:13 +08:00
|
|
|
int ldap_pvt_thread_rdwr_runlock( ldap_pvt_thread_rdwr_t *rwlock )
|
1999-02-05 02:00:50 +08:00
|
|
|
{
|
2000-06-13 10:42:13 +08:00
|
|
|
struct ldap_int_thread_rdwr_s *rw;
|
|
|
|
|
|
|
|
assert( rwlock != NULL );
|
|
|
|
rw = *rwlock;
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
assert( rw != NULL );
|
|
|
|
assert( rw->ltrw_valid == LDAP_PVT_THREAD_RDWR_VALID );
|
|
|
|
|
1999-04-27 13:18:21 +08:00
|
|
|
if( rw->ltrw_valid != LDAP_PVT_THREAD_RDWR_VALID )
|
1999-02-05 02:00:50 +08:00
|
|
|
return LDAP_PVT_THREAD_EINVAL;
|
|
|
|
|
|
|
|
ldap_pvt_thread_mutex_lock( &rw->ltrw_mutex );
|
|
|
|
|
|
|
|
rw->ltrw_r_active--;
|
|
|
|
|
2000-06-17 05:25:03 +08:00
|
|
|
assert( rw->ltrw_w_active >= 0 );
|
|
|
|
assert( rw->ltrw_w_wait >= 0 );
|
|
|
|
assert( rw->ltrw_r_active >= 0 );
|
|
|
|
assert( rw->ltrw_r_wait >= 0 );
|
|
|
|
|
1999-02-05 02:00:50 +08:00
|
|
|
if (rw->ltrw_r_active == 0 && rw->ltrw_w_wait > 0 ) {
|
|
|
|
ldap_pvt_thread_cond_signal( &rw->ltrw_write );
|
1999-01-15 22:54:25 +08:00
|
|
|
}
|
1999-02-05 02:00:50 +08:00
|
|
|
|
|
|
|
ldap_pvt_thread_mutex_unlock( &rw->ltrw_mutex );
|
|
|
|
|
|
|
|
return 0;
|
1999-01-15 22:54:25 +08:00
|
|
|
}
|
|
|
|
|
2000-06-13 10:42:13 +08:00
|
|
|
int ldap_pvt_thread_rdwr_wlock( ldap_pvt_thread_rdwr_t *rwlock )
|
1999-01-15 22:54:25 +08:00
|
|
|
{
|
2000-06-13 10:42:13 +08:00
|
|
|
struct ldap_int_thread_rdwr_s *rw;
|
|
|
|
|
|
|
|
assert( rwlock != NULL );
|
|
|
|
rw = *rwlock;
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
assert( rw != NULL );
|
|
|
|
assert( rw->ltrw_valid == LDAP_PVT_THREAD_RDWR_VALID );
|
|
|
|
|
1999-04-27 13:18:21 +08:00
|
|
|
if( rw->ltrw_valid != LDAP_PVT_THREAD_RDWR_VALID )
|
1999-02-05 02:00:50 +08:00
|
|
|
return LDAP_PVT_THREAD_EINVAL;
|
|
|
|
|
|
|
|
ldap_pvt_thread_mutex_lock( &rw->ltrw_mutex );
|
|
|
|
|
2000-06-17 05:25:03 +08:00
|
|
|
assert( rw->ltrw_w_active >= 0 );
|
|
|
|
assert( rw->ltrw_w_wait >= 0 );
|
|
|
|
assert( rw->ltrw_r_active >= 0 );
|
|
|
|
assert( rw->ltrw_r_wait >= 0 );
|
|
|
|
|
1999-02-05 02:00:50 +08:00
|
|
|
if ( rw->ltrw_w_active > 0 || rw->ltrw_r_active > 0 ) {
|
|
|
|
rw->ltrw_w_wait++;
|
|
|
|
|
|
|
|
do {
|
|
|
|
ldap_pvt_thread_cond_wait(
|
|
|
|
&rw->ltrw_write, &rw->ltrw_mutex );
|
|
|
|
} while ( rw->ltrw_w_active > 0 || rw->ltrw_r_active > 0 );
|
|
|
|
|
|
|
|
rw->ltrw_w_wait--;
|
2000-06-17 05:25:03 +08:00
|
|
|
assert( rw->ltrw_w_wait >= 0 );
|
1999-01-15 22:54:25 +08:00
|
|
|
}
|
1999-02-05 02:00:50 +08:00
|
|
|
|
|
|
|
rw->ltrw_w_active++;
|
|
|
|
|
|
|
|
ldap_pvt_thread_mutex_unlock( &rw->ltrw_mutex );
|
|
|
|
|
1999-01-15 22:54:25 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-06-13 10:42:13 +08:00
|
|
|
int ldap_pvt_thread_rdwr_wtrylock( ldap_pvt_thread_rdwr_t *rwlock )
|
1999-01-15 22:54:25 +08:00
|
|
|
{
|
2000-06-13 10:42:13 +08:00
|
|
|
struct ldap_int_thread_rdwr_s *rw;
|
|
|
|
|
|
|
|
assert( rwlock != NULL );
|
|
|
|
rw = *rwlock;
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
assert( rw != NULL );
|
|
|
|
assert( rw->ltrw_valid == LDAP_PVT_THREAD_RDWR_VALID );
|
|
|
|
|
1999-04-27 13:18:21 +08:00
|
|
|
if( rw->ltrw_valid != LDAP_PVT_THREAD_RDWR_VALID )
|
1999-02-05 02:00:50 +08:00
|
|
|
return LDAP_PVT_THREAD_EINVAL;
|
|
|
|
|
|
|
|
ldap_pvt_thread_mutex_lock( &rw->ltrw_mutex );
|
|
|
|
|
2000-06-17 05:25:03 +08:00
|
|
|
assert( rw->ltrw_w_active >= 0 );
|
|
|
|
assert( rw->ltrw_w_wait >= 0 );
|
|
|
|
assert( rw->ltrw_r_active >= 0 );
|
|
|
|
assert( rw->ltrw_r_wait >= 0 );
|
|
|
|
|
1999-02-05 02:00:50 +08:00
|
|
|
if ( rw->ltrw_w_active > 0 || rw->ltrw_r_active > 0 ) {
|
|
|
|
ldap_pvt_thread_mutex_unlock( &rw->ltrw_mutex );
|
|
|
|
return LDAP_PVT_THREAD_EBUSY;
|
1999-01-15 22:54:25 +08:00
|
|
|
}
|
1999-02-05 02:00:50 +08:00
|
|
|
|
|
|
|
rw->ltrw_w_active++;
|
|
|
|
|
|
|
|
ldap_pvt_thread_mutex_unlock( &rw->ltrw_mutex );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-06-13 10:42:13 +08:00
|
|
|
int ldap_pvt_thread_rdwr_wunlock( ldap_pvt_thread_rdwr_t *rwlock )
|
1999-02-05 02:00:50 +08:00
|
|
|
{
|
2000-06-13 10:42:13 +08:00
|
|
|
struct ldap_int_thread_rdwr_s *rw;
|
|
|
|
|
|
|
|
assert( rwlock != NULL );
|
|
|
|
rw = *rwlock;
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
assert( rw != NULL );
|
|
|
|
assert( rw->ltrw_valid == LDAP_PVT_THREAD_RDWR_VALID );
|
|
|
|
|
1999-04-27 13:18:21 +08:00
|
|
|
if( rw->ltrw_valid != LDAP_PVT_THREAD_RDWR_VALID )
|
1999-02-05 02:00:50 +08:00
|
|
|
return LDAP_PVT_THREAD_EINVAL;
|
|
|
|
|
|
|
|
ldap_pvt_thread_mutex_lock( &rw->ltrw_mutex );
|
|
|
|
|
|
|
|
rw->ltrw_w_active--;
|
|
|
|
|
2000-06-17 05:25:03 +08:00
|
|
|
assert( rw->ltrw_w_active >= 0 );
|
|
|
|
assert( rw->ltrw_w_wait >= 0 );
|
|
|
|
assert( rw->ltrw_r_active >= 0 );
|
|
|
|
assert( rw->ltrw_r_wait >= 0 );
|
|
|
|
|
1999-02-05 02:00:50 +08:00
|
|
|
if (rw->ltrw_r_wait > 0) {
|
|
|
|
ldap_pvt_thread_cond_broadcast( &rw->ltrw_read );
|
|
|
|
|
|
|
|
} else if (rw->ltrw_w_wait > 0) {
|
|
|
|
ldap_pvt_thread_cond_signal( &rw->ltrw_write );
|
1999-01-15 22:54:25 +08:00
|
|
|
}
|
1999-02-05 02:00:50 +08:00
|
|
|
|
|
|
|
ldap_pvt_thread_mutex_unlock( &rw->ltrw_mutex );
|
|
|
|
|
|
|
|
return 0;
|
1999-01-15 22:54:25 +08:00
|
|
|
}
|
|
|
|
|
2000-06-07 08:28:35 +08:00
|
|
|
#ifdef LDAP_RDWR_DEBUG
|
1999-01-15 22:54:25 +08:00
|
|
|
|
|
|
|
/* just for testing,
|
|
|
|
* return 0 if false, suitable for assert(ldap_pvt_thread_rdwr_Xchk(rdwr))
|
|
|
|
*
|
|
|
|
* Currently they don't check if the calling thread is the one
|
|
|
|
* that has the lock, just that there is a reader or writer.
|
|
|
|
*
|
|
|
|
* Basically sufficent for testing that places that should have
|
|
|
|
* a lock are caught.
|
|
|
|
*/
|
|
|
|
|
2000-06-13 10:42:13 +08:00
|
|
|
int ldap_pvt_thread_rdwr_readers(ldap_pvt_thread_rdwr_t *rwlock)
|
1999-01-15 22:54:25 +08:00
|
|
|
{
|
2000-06-13 10:42:13 +08:00
|
|
|
struct ldap_int_thread_rdwr_s *rw;
|
|
|
|
|
|
|
|
assert( rwlock != NULL );
|
|
|
|
rw = *rwlock;
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
assert( rw != NULL );
|
|
|
|
assert( rw->ltrw_valid == LDAP_PVT_THREAD_RDWR_VALID );
|
2000-06-17 05:25:03 +08:00
|
|
|
assert( rw->ltrw_w_active >= 0 );
|
|
|
|
assert( rw->ltrw_w_wait >= 0 );
|
|
|
|
assert( rw->ltrw_r_active >= 0 );
|
|
|
|
assert( rw->ltrw_r_wait >= 0 );
|
1999-05-19 09:12:33 +08:00
|
|
|
|
1999-02-05 02:00:50 +08:00
|
|
|
return( rw->ltrw_r_active );
|
1999-01-15 22:54:25 +08:00
|
|
|
}
|
|
|
|
|
2000-06-13 10:42:13 +08:00
|
|
|
int ldap_pvt_thread_rdwr_writers(ldap_pvt_thread_rdwr_t *rwlock)
|
1999-01-15 22:54:25 +08:00
|
|
|
{
|
2000-06-13 10:42:13 +08:00
|
|
|
struct ldap_int_thread_rdwr_s *rw;
|
|
|
|
|
|
|
|
assert( rwlock != NULL );
|
|
|
|
rw = *rwlock;
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
assert( rw != NULL );
|
|
|
|
assert( rw->ltrw_valid == LDAP_PVT_THREAD_RDWR_VALID );
|
2000-06-17 05:25:03 +08:00
|
|
|
assert( rw->ltrw_w_active >= 0 );
|
|
|
|
assert( rw->ltrw_w_wait >= 0 );
|
|
|
|
assert( rw->ltrw_r_active >= 0 );
|
|
|
|
assert( rw->ltrw_r_wait >= 0 );
|
1999-05-19 09:12:33 +08:00
|
|
|
|
1999-02-05 02:00:50 +08:00
|
|
|
return( rw->ltrw_w_active );
|
1999-01-15 22:54:25 +08:00
|
|
|
}
|
1999-02-05 02:00:50 +08:00
|
|
|
|
2000-06-13 10:42:13 +08:00
|
|
|
int ldap_pvt_thread_rdwr_active(ldap_pvt_thread_rdwr_t *rwlock)
|
1999-01-15 22:54:25 +08:00
|
|
|
{
|
2000-06-13 10:42:13 +08:00
|
|
|
struct ldap_int_thread_rdwr_s *rw;
|
|
|
|
|
|
|
|
assert( rwlock != NULL );
|
|
|
|
rw = *rwlock;
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
assert( rw != NULL );
|
|
|
|
assert( rw->ltrw_valid == LDAP_PVT_THREAD_RDWR_VALID );
|
2000-06-17 05:25:03 +08:00
|
|
|
assert( rw->ltrw_w_active >= 0 );
|
|
|
|
assert( rw->ltrw_w_wait >= 0 );
|
|
|
|
assert( rw->ltrw_r_active >= 0 );
|
|
|
|
assert( rw->ltrw_r_wait >= 0 );
|
1999-05-19 09:12:33 +08:00
|
|
|
|
1999-02-05 02:00:50 +08:00
|
|
|
return(ldap_pvt_thread_rdwr_readers(rw) +
|
|
|
|
ldap_pvt_thread_rdwr_writers(rw));
|
1999-01-15 22:54:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* LDAP_DEBUG */
|
2000-06-07 05:20:38 +08:00
|
|
|
|
|
|
|
#endif /* LDAP_THREAD_HAVE_RDWR */
|