Back to index

glibc  2.9
Functions
pthread_rwlock_unlock.c File Reference
#include <errno.h>
#include <sysdep.h>
#include <lowlevellock.h>
#include <pthread.h>
#include <pthreadP.h>

Go to the source code of this file.

Functions

int __pthread_rwlock_unlock (pthread_rwlock_t *rwlock)

Function Documentation

int __pthread_rwlock_unlock ( pthread_rwlock_t *  rwlock)

Definition at line 28 of file pthread_rwlock_unlock.c.

{
  lll_lock (rwlock->__data.__lock, rwlock->__data.__shared);
  if (rwlock->__data.__writer)
    rwlock->__data.__writer = 0;
  else
    --rwlock->__data.__nr_readers;
  if (rwlock->__data.__nr_readers == 0)
    {
      if (rwlock->__data.__nr_writers_queued)
       {
         ++rwlock->__data.__writer_wakeup;
         lll_unlock (rwlock->__data.__lock, rwlock->__data.__shared);
         lll_futex_wake (&rwlock->__data.__writer_wakeup, 1,
                       rwlock->__data.__shared);
         return 0;
       }
      else if (rwlock->__data.__nr_readers_queued)
       {
         ++rwlock->__data.__readers_wakeup;
         lll_unlock (rwlock->__data.__lock, rwlock->__data.__shared);
         lll_futex_wake (&rwlock->__data.__readers_wakeup, INT_MAX,
                       rwlock->__data.__shared);
         return 0;
       }
    }
  lll_unlock (rwlock->__data.__lock, rwlock->__data.__shared);
  return 0;
}