Back to index

glibc  2.9
Functions
pthread_rwlock_tryrdlock.c File Reference
#include <errno.h>
#include "pthreadP.h"
#include <lowlevellock.h>

Go to the source code of this file.

Functions

int __pthread_rwlock_tryrdlock (pthread_rwlock_t *rwlock)

Function Documentation

int __pthread_rwlock_tryrdlock ( pthread_rwlock_t *  rwlock)

Definition at line 26 of file pthread_rwlock_tryrdlock.c.

{
  int result = EBUSY;

  lll_lock (rwlock->__data.__lock, rwlock->__data.__shared);

  if (rwlock->__data.__writer == 0
      && (rwlock->__data.__nr_writers_queued == 0
         || PTHREAD_RWLOCK_PREFER_READER_P (rwlock)))
    {
      if (__builtin_expect (++rwlock->__data.__nr_readers == 0, 0))
       {
         --rwlock->__data.__nr_readers;
         result = EAGAIN;
       }
      else
       result = 0;
    }

  lll_unlock (rwlock->__data.__lock, rwlock->__data.__shared);

  return result;
}