src/lib/rwlock.c
int rwl_destroy(brwlock_t *rwl)
{
   int stat, stat1, stat2;

  if (rwl->valid != RWLOCK_VALID) {
     return EINVAL;
  }
  if ((stat = pthread_mutex_lock(&rwl->mutex)) != 0) {
     return stat;
  }

  /*
   * If any threads are active, report EBUSY
   */
  if (rwl->r_active > 0 || rwl->w_active) {
     pthread_mutex_unlock(&rwl->mutex);
     return EBUSY;
  }

  /*
   * If any threads are waiting, report EBUSY
   */
  if (rwl->r_wait > 0 || rwl->w_wait > 0) {
     pthread_mutex_unlock(&rwl->mutex);
     return EBUSY;
  }

  rwl->valid = 0;
  if ((stat = pthread_mutex_unlock(&rwl->mutex)) != 0) {
     return stat;
  }
  stat  = pthread_mutex_destroy(&rwl->mutex);
  stat1 = pthread_cond_destroy(&rwl->read);
  stat2 = pthread_cond_destroy(&rwl->write);
  return (stat != 0 ? stat : (stat1 != 0 ? stat1 : stat2));
}
/*
 * Destroy a read/write lock
 *
 * Returns: 0 on success
 *          errno on failure
 */
Destroy a read/write lock
Returns: 0 on success
errno on failure
Destroy a read / write lock Returns : 0 on success errno on failure
int rwl_destroy(brwlock_t *rwl)
{
   int stat, stat1, stat2;
  if (rwl->valid != RWLOCK_VALID) {
     return EINVAL;
  }
  if ((stat = pthread_mutex_lock(&rwl->mutex)) != 0) {
     return stat;
  }
  if (rwl->r_active > 0 || rwl->w_active) {
     pthread_mutex_unlock(&rwl->mutex);
     return EBUSY;
  }
  if (rwl->r_wait > 0 || rwl->w_wait > 0) {
     pthread_mutex_unlock(&rwl->mutex);
     return EBUSY;
  }
  rwl->valid = 0;
  if ((stat = pthread_mutex_unlock(&rwl->mutex)) != 0) {
     return stat;
  }
  stat  = pthread_mutex_destroy(&rwl->mutex);
  stat1 = pthread_cond_destroy(&rwl->read);
  stat2 = pthread_cond_destroy(&rwl->write);
  return (stat != 0 ? stat : (stat1 != 0 ? stat1 : stat2));
}
int rwl_destroy ( brwlock_t * rwl ) { int stat , stat1 , stat2 ; if ( rwl -> valid != RWLOCK_VALID ) { return EINVAL ; } if ( ( stat = pthread_mutex_lock ( & rwl -> mutex ) ) != 0 ) { return stat ; } if ( rwl -> r_active > 0 || rwl -> w_active ) { pthread_mutex_unlock ( & rwl -> mutex ) ; return EBUSY ; } if ( rwl -> r_wait > 0 || rwl -> w_wait > 0 ) { pthread_mutex_unlock ( & rwl -> mutex ) ; return EBUSY ; } rwl -> valid = 0 ; if ( ( stat = pthread_mutex_unlock ( & rwl -> mutex ) ) != 0 ) { return stat ; } stat = pthread_mutex_destroy ( & rwl -> mutex ) ; stat1 = pthread_cond_destroy ( & rwl -> read ) ; stat2 = pthread_cond_destroy ( & rwl -> write ) ; return ( stat != 0 ? stat : ( stat1 != 0 ? stat1 : stat2 ) ) ; }
Destroy a read/write lock
 Returns: 0 on success
          errno on failure
Destroy a read / write lock Returns : 0 on success errno on failure
/*
   * If any threads are active, report EBUSY
   */ /*
   * If any threads are waiting, report EBUSY
   */