Back to index

glibc  2.9
Defines | Functions | Variables
lowlevellock.h File Reference
#include <time.h>
#include <sys/param.h>
#include <bits/pthreadtypes.h>
#include <atomic.h>
#include <sysdep.h>
#include <kernel-features.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define __NR_futex   394
#define FUTEX_WAIT   0
#define FUTEX_WAKE   1
#define FUTEX_REQUEUE   3
#define FUTEX_CMP_REQUEUE   4
#define FUTEX_WAKE_OP   5
#define FUTEX_OP_CLEAR_WAKE_IF_GT_ONE   ((4 << 24) | 1)
#define FUTEX_LOCK_PI   6
#define FUTEX_UNLOCK_PI   7
#define FUTEX_TRYLOCK_PI   8
#define FUTEX_PRIVATE_FLAG   128
#define LLL_PRIVATE   0
#define LLL_SHARED   FUTEX_PRIVATE_FLAG
#define __lll_private_flag(fl, private)   ((fl) | THREAD_GETMEM (THREAD_SELF, header.private_futex))
#define lll_futex_wait(futexp, val, private)   lll_futex_timed_wait (futexp, val, NULL, private)
#define lll_futex_timed_wait(futexp, val, timespec, private)
#define lll_futex_wake(futexp, nr, private)
#define lll_robust_dead(futexv, private)
#define lll_futex_requeue(futexp, nr_wake, nr_move, mutex, val, private)
#define lll_futex_wake_unlock(futexp, nr_wake, nr_wake2, futexp2, private)
#define lll_trylock(lock)   __lll_trylock (&(lock))
#define lll_cond_trylock(lock)   __lll_cond_trylock (&(lock))
#define lll_robust_trylock(lock, id)   __lll_robust_trylock (&(lock), id)
#define lll_lock(futex, private)   __lll_lock (&(futex), private)
#define lll_robust_lock(futex, id, private)   __lll_robust_lock (&(futex), id, private)
#define lll_cond_lock(futex, private)   __lll_cond_lock (&(futex), private)
#define lll_robust_cond_lock(futex, id, private)   __lll_robust_lock (&(futex), (id) | FUTEX_WAITERS, private)
#define lll_timedlock(futex, abstime, private)   __lll_timedlock (&(futex), abstime, private)
#define lll_robust_timedlock(futex, abstime, id, private)   __lll_robust_timedlock (&(futex), abstime, id, private)
#define __lll_unlock(futex, private)
#define lll_unlock(futex, private)   __lll_unlock(&(futex), private)
#define __lll_robust_unlock(futex, private)
#define lll_robust_unlock(futex, private)   __lll_robust_unlock(&(futex), private)
#define lll_islocked(futex)   (futex != 0)
#define LLL_LOCK_INITIALIZER   (0)
#define LLL_LOCK_INITIALIZER_LOCKED   (1)
#define lll_wait_tid(tid)
#define lll_timedwait_tid(tid, abstime)

Functions

static int __attribute__ ((always_inline)) __lll_trylock(int *futex)
void __lll_lock_wait (int *futex, int private) attribute_hidden
int __lll_robust_lock_wait (int *futex, int private) attribute_hidden
int __lll_robust_timedlock_wait (int *futex, const struct timespec *, int private) attribute_hidden

Variables

static int struct timespecabstime

Define Documentation

#define __lll_private_flag (   fl,
  private 
)    ((fl) | THREAD_GETMEM (THREAD_SELF, header.private_futex))

Definition at line 55 of file lowlevellock.h.

#define __lll_robust_unlock (   futex,
  private 
)
Value:
(void)                                           \
    ({ int *__futex = (futex);                                 \
       int __oldval = atomic_exchange_rel (__futex, 0);        \
       if (__builtin_expect (__oldval & FUTEX_WAITERS, 0))     \
        lll_futex_wake (__futex, 1, private);                  \
    })
#define __lll_unlock (   futex,
  private 
)
Value:
(void)                                           \
    ({ int *__futex = (futex);                                 \
       int __oldval = atomic_exchange_rel (__futex, 0);        \
       if (__builtin_expect (__oldval > 1, 0))                 \
        lll_futex_wake (__futex, 1, private);                  \
    })
#define __NR_futex   394

Definition at line 30 of file lowlevellock.h.

#define FUTEX_CMP_REQUEUE   4

Definition at line 34 of file lowlevellock.h.

#define FUTEX_LOCK_PI   6

Definition at line 37 of file lowlevellock.h.

#define FUTEX_OP_CLEAR_WAKE_IF_GT_ONE   ((4 << 24) | 1)

Definition at line 36 of file lowlevellock.h.

#define FUTEX_PRIVATE_FLAG   128

Definition at line 40 of file lowlevellock.h.

#define FUTEX_REQUEUE   3

Definition at line 33 of file lowlevellock.h.

#define FUTEX_TRYLOCK_PI   8

Definition at line 39 of file lowlevellock.h.

#define FUTEX_UNLOCK_PI   7

Definition at line 38 of file lowlevellock.h.

#define FUTEX_WAIT   0

Definition at line 31 of file lowlevellock.h.

#define FUTEX_WAKE   1

Definition at line 32 of file lowlevellock.h.

#define FUTEX_WAKE_OP   5

Definition at line 35 of file lowlevellock.h.

#define lll_cond_lock (   futex,
  private 
)    __lll_cond_lock (&(futex), private)
#define lll_cond_trylock (   lock)    __lll_cond_trylock (&(lock))

Definition at line 145 of file lowlevellock.h.

#define lll_futex_requeue (   futexp,
  nr_wake,
  nr_move,
  mutex,
  val,
  private 
)
Value:
({                                                                   \
    INTERNAL_SYSCALL_DECL (__err);                                   \
    long int __ret;                                                  \
    __ret = INTERNAL_SYSCALL (futex, __err, 6, (futexp),                    \
                           __lll_private_flag (FUTEX_CMP_REQUEUE, private),\
                           (nr_wake), (nr_move), (mutex), (val));           \
    INTERNAL_SYSCALL_ERROR_P (__ret, __err);                                \
  })

Definition at line 107 of file lowlevellock.h.

#define lll_futex_timed_wait (   futexp,
  val,
  timespec,
  private 
)
Value:
({                                                                   \
    INTERNAL_SYSCALL_DECL (__err);                                   \
    long int __ret;                                                  \
    __ret = INTERNAL_SYSCALL (futex, __err, 4, (futexp),                    \
                           __lll_private_flag (FUTEX_WAIT, private),        \
                           (val), (timespec));                       \
    INTERNAL_SYSCALL_ERROR_P (__ret, __err)? -__ret : __ret;                \
  })

Definition at line 77 of file lowlevellock.h.

#define lll_futex_wait (   futexp,
  val,
  private 
)    lll_futex_timed_wait (futexp, val, NULL, private)

Definition at line 74 of file lowlevellock.h.

#define lll_futex_wake (   futexp,
  nr,
  private 
)
Value:
({                                                                   \
    INTERNAL_SYSCALL_DECL (__err);                                   \
    long int __ret;                                                  \
    __ret = INTERNAL_SYSCALL (futex, __err, 4, (futexp),                    \
                           __lll_private_flag (FUTEX_WAKE, private),        \
                           (nr), 0);                                        \
    INTERNAL_SYSCALL_ERROR_P (__ret, __err)? -__ret : __ret;                \
  })

Definition at line 87 of file lowlevellock.h.

#define lll_futex_wake_unlock (   futexp,
  nr_wake,
  nr_wake2,
  futexp2,
  private 
)
Value:
({                                                                   \
    INTERNAL_SYSCALL_DECL (__err);                                   \
    long int __ret;                                                  \
    __ret = INTERNAL_SYSCALL (futex, __err, 6, (futexp),                    \
                           __lll_private_flag (FUTEX_WAKE_OP, private),    \
                           (nr_wake), (nr_wake2), (futexp2),                \
                           FUTEX_OP_CLEAR_WAKE_IF_GT_ONE);                  \
    INTERNAL_SYSCALL_ERROR_P (__ret, __err);                                \
  })

Definition at line 118 of file lowlevellock.h.

#define lll_islocked (   futex)    (futex != 0)
#define lll_lock (   futex,
  private 
)    __lll_lock (&(futex), private)
#define LLL_LOCK_INITIALIZER   (0)
#define LLL_LOCK_INITIALIZER_LOCKED   (1)
#define LLL_PRIVATE   0

Definition at line 45 of file lowlevellock.h.

#define lll_robust_cond_lock (   futex,
  id,
  private 
)    __lll_robust_lock (&(futex), (id) | FUTEX_WAITERS, private)
#define lll_robust_dead (   futexv,
  private 
)
Value:
do                                                                   \
    {                                                                \
      int *__futexp = &(futexv);                                     \
      atomic_or (__futexp, FUTEX_OWNER_DIED);                               \
      lll_futex_wake (__futexp, 1, private);                                \
    }                                                                \
  while (0)

Definition at line 97 of file lowlevellock.h.

#define lll_robust_lock (   futex,
  id,
  private 
)    __lll_robust_lock (&(futex), id, private)
#define lll_robust_timedlock (   futex,
  abstime,
  id,
  private 
)    __lll_robust_timedlock (&(futex), abstime, id, private)
#define lll_robust_trylock (   lock,
  id 
)    __lll_robust_trylock (&(lock), id)
#define lll_robust_unlock (   futex,
  private 
)    __lll_robust_unlock(&(futex), private)

Definition at line 46 of file lowlevellock.h.

#define lll_timedlock (   futex,
  abstime,
  private 
)    __lll_timedlock (&(futex), abstime, private)
#define lll_timedwait_tid (   tid,
  abstime 
)
Value:
({                                               \
    int __res = 0;                               \
    if ((tid) != 0)                              \
      __res = __lll_timedwait_tid (&(tid), (abstime));  \
    __res;                                       \
  })

Definition at line 272 of file lowlevellock.h.

#define lll_trylock (   lock)    __lll_trylock (&(lock))

Definition at line 137 of file lowlevellock.h.

#define lll_unlock (   futex,
  private 
)    __lll_unlock(&(futex), private)
#define lll_wait_tid (   tid)
Value:
do {                                             \
    __typeof (tid) __tid;                        \
    while ((__tid = (tid)) != 0)                 \
      lll_futex_wait (&(tid), __tid, LLL_SHARED);       \
  } while (0)

Function Documentation

static int __attribute__ ( (always_inline)  ) [inline, static]

Definition at line 132 of file lowlevellock.h.

{
  return atomic_compare_and_exchange_val_acq (futex, 1, 0) != 0;
}
void __lll_lock_wait ( int 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);
}
int __lll_robust_lock_wait ( int futex,
int  private 
)

Definition at line 28 of file lowlevelrobustlock.c.

{
  int oldval = *futex;
  int tid = THREAD_GETMEM (THREAD_SELF, tid);

  /* If the futex changed meanwhile try locking again.  */
  if (oldval == 0)
    goto try;

  do
    {
      if (__builtin_expect (oldval & FUTEX_OWNER_DIED, 0))
       return oldval;

      int newval = oldval | FUTEX_WAITERS;
      if (oldval != newval
         && atomic_compare_and_exchange_bool_acq (futex, newval, oldval))
       continue;

      lll_futex_wait (futex, newval, private);

    try:
      ;
    }
  while ((oldval = atomic_compare_and_exchange_val_acq (futex,
                                                 tid | FUTEX_WAITERS,
                                                 0)) != 0);
  return 0;
}
int __lll_robust_timedlock_wait ( int futex,
const struct timespec ,
int  private 
)

Definition at line 60 of file lowlevelrobustlock.c.

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

  int tid = THREAD_GETMEM (THREAD_SELF, tid);
  int oldval = *futex;

  /* If the futex changed meanwhile try locking again.  */
  if (oldval == 0)
    goto try;

  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.  */
      if (__builtin_expect (oldval & FUTEX_OWNER_DIED, 0))
       return oldval;

      int newval = oldval | FUTEX_WAITERS;
      if (oldval != newval
         && atomic_compare_and_exchange_bool_acq (futex, newval, oldval))
       continue;

      lll_futex_timed_wait (futex, newval, &rt, private);

    try:
      ;
    }
  while ((oldval = atomic_compare_and_exchange_val_acq (futex,
                                                 tid | FUTEX_WAITERS,
                                                 0)) != 0);

  return 0;
}

Variable Documentation

int struct timespec* abstime

Definition at line 205 of file lowlevellock.h.