Back to index

glibc  2.9
Functions
lowlevellock.c File Reference
#include <errno.h>
#include <sysdep.h>
#include <lowlevellock.h>
#include <sys/time.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void __lll_lock_wait (lll_lock_t *futex, int private)
void __lll_lock_wait_private (lll_lock_t *futex)
int __lll_timedlock_wait (lll_lock_t *futex, const struct timespec *abstime, int private)

Function Documentation

void __lll_lock_wait ( lll_lock_t futex,
int  private 
)

Definition at line 27 of file lowlevellock.c.

{
  do
    {
      int oldval = atomic_compare_and_exchange_val_acq (futex, 2, 1);
      if (oldval != 0)
       lll_futex_wait (futex, 2, private);
    }
  while (atomic_compare_and_exchange_val_acq (futex, 2, 0) != 0);
}

Definition at line 39 of file lowlevellock.c.

{
  do
    {
      int oldval = atomic_compare_and_exchange_val_acq (futex, 2, 1);
      if (oldval != 0)
       lll_futex_wait (futex, 2, LLL_PRIVATE);
    }
  while (atomic_compare_and_exchange_val_acq (futex, 2, 0) != 0);
}
int __lll_timedlock_wait ( lll_lock_t futex,
const struct timespec abstime,
int  private 
)

Definition at line 51 of file lowlevellock.c.

{
  /* Reject invalid timeouts.  */
  if (abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000)
    return EINVAL;

  do
    {
      struct timeval tv;
      struct timespec rt;

      /* Get the current time.  */
      (void) __gettimeofday (&tv, NULL);

      /* Compute relative timeout.  */
      rt.tv_sec = abstime->tv_sec - tv.tv_sec;
      rt.tv_nsec = abstime->tv_nsec - tv.tv_usec * 1000;
      if (rt.tv_nsec < 0)
       {
         rt.tv_nsec += 1000000000;
         --rt.tv_sec;
       }

      /* Already timed out?  */
      if (rt.tv_sec < 0)
       return ETIMEDOUT;

      /* Wait.  */
      int oldval = atomic_compare_and_exchange_val_acq (futex, 2, 1);
      if (oldval != 0)
       lll_futex_timed_wait (futex, 2, &rt, private);
    }
  while (atomic_compare_and_exchange_bool_acq (futex, 2, 0) != 0);
  return 0;
}