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

   if (rwl->valid != RWLOCK_VALID) {
      return EINVAL;
   }
   if ((stat = pthread_mutex_lock(&rwl->mutex)) != 0) {
      return stat;
   }
   if (rwl->w_active && pthread_equal(rwl->writer_id, pthread_self())) {
      rwl->w_active++;
      pthread_mutex_unlock(&rwl->mutex);
      return 0;
   }
   if (rwl->w_active || rwl->r_active > 0) {
      stat = EBUSY;
   } else {
      rwl->w_active = 1;              /* we are running */
      rwl->writer_id = pthread_self(); /* save writer thread's id */
      lmgr_do_lock(rwl, rwl->priority, __FILE__, __LINE__);
   }
   stat2 = pthread_mutex_unlock(&rwl->mutex);
   return (stat == 0 ? stat2 : stat);
}
/*
 * Attempt to lock for write access, don't wait
 */
Attempt to lock for write access, don't wait
Attempt to lock for write access don ' t wait
int rwl_writetrylock(brwlock_t *rwl)
{
   int stat, stat2;
   if (rwl->valid != RWLOCK_VALID) {
      return EINVAL;
   }
   if ((stat = pthread_mutex_lock(&rwl->mutex)) != 0) {
      return stat;
   }
   if (rwl->w_active && pthread_equal(rwl->writer_id, pthread_self())) {
      rwl->w_active++;
      pthread_mutex_unlock(&rwl->mutex);
      return 0;
   }
   if (rwl->w_active || rwl->r_active > 0) {
      stat = EBUSY;
   } else {
      rwl->w_active = 1;              
      rwl->writer_id = pthread_self(); 
      lmgr_do_lock(rwl, rwl->priority, __FILE__, __LINE__);
   }
   stat2 = pthread_mutex_unlock(&rwl->mutex);
   return (stat == 0 ? stat2 : stat);
}
int rwl_writetrylock ( brwlock_t * rwl ) { int stat , stat2 ; if ( rwl -> valid != RWLOCK_VALID ) { return EINVAL ; } if ( ( stat = pthread_mutex_lock ( & rwl -> mutex ) ) != 0 ) { return stat ; } if ( rwl -> w_active && pthread_equal ( rwl -> writer_id , pthread_self ( ) ) ) { rwl -> w_active ++ ; pthread_mutex_unlock ( & rwl -> mutex ) ; return 0 ; } if ( rwl -> w_active || rwl -> r_active > 0 ) { stat = EBUSY ; } else { rwl -> w_active = 1 ; rwl -> writer_id = pthread_self ( ) ; lmgr_do_lock ( rwl , rwl -> priority , __FILE__ , __LINE__ ) ; } stat2 = pthread_mutex_unlock ( & rwl -> mutex ) ; return ( stat == 0 ? stat2 : stat ) ; }
Attempt to lock for write access, don't wait
Attempt to lock for write access don ' t wait
/* we are running */ /* save writer thread's id */