Back to index

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

Go to the source code of this file.

Defines

#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 FUTEX_WAITERS   0x80000000
#define FUTEX_OWNER_DIED   0x40000000
#define FUTEX_TID_MASK   0x3fffffff
#define LLL_PRIVATE   0
#define LLL_SHARED   FUTEX_PRIVATE_FLAG
#define LLL_MUTEX_LOCK_INITIALIZER   (0)
#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, 0, private)
#define lll_futex_timed_wait(futexp, val, timespec, private)
#define lll_futex_wake(futexp, nr, private)
#define lll_private_futex_wait(futex, val)   lll_private_futex_timed_wait (futex, val, NULL)
#define lll_private_futex_timed_wait(futexp, val, timespec)
#define lll_private_futex_wake(futexp, nr)
#define lll_futex_requeue(futexp, nr_wake, nr_move, mutex, val, private)
#define lll_robust_dead(futexv, private)
#define lll_futex_wake_unlock(futexp, nr_wake, nr_wake2, futexp2, private)
#define lll_robust_trylock(futex, id)   __lll_robust_trylock (&(futex), id)
#define lll_cond_trylock(futex)   __lll_cond_trylock (&(futex))
#define lll_trylock(futex)   __lll_trylock (&(futex))
#define lll_mutex_lock(futex, private)   __lll_mutex_lock (&(futex), private)
#define lll_lock(lock, private)   lll_mutex_lock (lock, private)
#define lll_robust_lock(futex, id, private)   __lll_robust_lock (&(futex), id, private)
#define lll_robust_cond_lock(futex, id, private)   __lll_robust_lock (&(futex), (id) | FUTEX_WAITERS, private)
#define lll_cond_lock(futex, private)   __lll_cond_lock (&(futex), 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_CONST   (0)
#define LLL_LOCK_INITIALIZER_LOCKED   (1)
#define THREAD_INIT_LOCK(PD, LOCK)   (PD)->LOCK = LLL_LOCK_INITIALIZER
#define lll_wait_tid(tid)
#define lll_timedwait_tid(tid, abstime)

Typedefs

typedef int lll_lock_t

Functions

static int __attribute__ ((always_inline)) __lll_robust_trylock(int *futex
void __lll_lock_wait_private (lll_lock_t *futex) attribute_hidden
int __lll_robust_timedlock_wait (int *futex, const struct timespec *, int private) attribute_hidden
int __lll_timedwait_tid (int *, const struct timespec *) attribute_hidden

Variables

static int int id
static int struct timespecabstime

Define Documentation

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

Definition at line 66 of file lowlevellock.h.

#define __lll_robust_unlock (   futex,
  private 
)
Value:
(void)                                               \
    ({ int val = atomic_exchange_rel (futex, 0);       \
       if (__builtin_expect (val & FUTEX_WAITERS, 0))  \
         lll_futex_wake (futex, 1, private);           \
    })
#define __lll_unlock (   futex,
  private 
)
Value:
(void)                             \
  ({ int val = atomic_exchange_rel (futex, 0);  \
     if (__builtin_expect (val > 1, 0))         \
       lll_futex_wake (futex, 1, private);      \
  })
#define FUTEX_CMP_REQUEUE   4

Definition at line 38 of file lowlevellock.h.

#define FUTEX_LOCK_PI   6

Definition at line 41 of file lowlevellock.h.

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

Definition at line 40 of file lowlevellock.h.

#define FUTEX_OWNER_DIED   0x40000000

Definition at line 48 of file lowlevellock.h.

#define FUTEX_PRIVATE_FLAG   128

Definition at line 44 of file lowlevellock.h.

#define FUTEX_REQUEUE   3

Definition at line 37 of file lowlevellock.h.

#define FUTEX_TID_MASK   0x3fffffff

Definition at line 49 of file lowlevellock.h.

#define FUTEX_TRYLOCK_PI   8

Definition at line 43 of file lowlevellock.h.

#define FUTEX_UNLOCK_PI   7

Definition at line 42 of file lowlevellock.h.

#define FUTEX_WAIT   0

Definition at line 35 of file lowlevellock.h.

#define FUTEX_WAITERS   0x80000000

Definition at line 47 of file lowlevellock.h.

#define FUTEX_WAKE   1

Definition at line 36 of file lowlevellock.h.

#define FUTEX_WAKE_OP   5

Definition at line 39 of file lowlevellock.h.

#define lll_cond_lock (   futex,
  private 
)    __lll_cond_lock (&(futex), private)
#define lll_cond_trylock (   futex)    __lll_cond_trylock (&(futex))
#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));           \
    __ret;                                                           \
  })

Definition at line 158 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));                 \
    __ret;                                                     \
  })

Definition at line 90 of file lowlevellock.h.

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

Definition at line 87 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);                                  \
    __ret;                                                     \
  })

Definition at line 100 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);               \
    __ret;                                                        \
  })

Definition at line 178 of file lowlevellock.h.

#define lll_islocked (   futex)    (futex != 0)
#define lll_lock (   lock,
  private 
)    lll_mutex_lock (lock, private)
#define LLL_LOCK_INITIALIZER   (0)
#define LLL_LOCK_INITIALIZER_CONST   (0)
#define LLL_LOCK_INITIALIZER_LOCKED   (1)
#define lll_mutex_lock (   futex,
  private 
)    __lll_mutex_lock (&(futex), private)
#define LLL_MUTEX_LOCK_INITIALIZER   (0)

Definition at line 58 of file lowlevellock.h.

#define LLL_PRIVATE   0

Definition at line 54 of file lowlevellock.h.

#define lll_private_futex_timed_wait (   futexp,
  val,
  timespec 
)
Value:
({                                                                   \
    INTERNAL_SYSCALL_DECL (__err);                                   \
    long int __ret, __op;                                            \
    __op = FUTEX_WAIT | THREAD_GETMEM (THREAD_SELF, header.private_futex);    \
    __ret = INTERNAL_SYSCALL (futex, __err, 4,                              \
                           (futexp), __op, (val), (timespec));       \
    __ret;                                                           \
  })

Definition at line 136 of file lowlevellock.h.

#define lll_private_futex_wait (   futex,
  val 
)    lll_private_futex_timed_wait (futex, val, NULL)

Definition at line 110 of file lowlevellock.h.

#define lll_private_futex_wake (   futexp,
  nr 
)
Value:
({                                                                   \
    INTERNAL_SYSCALL_DECL (__err);                                   \
    long int __ret, __op;                                            \
    __op = FUTEX_WAKE | THREAD_GETMEM (THREAD_SELF, header.private_futex);    \
    __ret = INTERNAL_SYSCALL (futex, __err, 4,                              \
                           (futexp), __op, (nr), 0);                        \
    __ret;                                                           \
  })

Definition at line 146 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 168 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 (   futex,
  id 
)    __lll_robust_trylock (&(futex), id)
#define lll_robust_unlock (   futex,
  private 
)    __lll_robust_unlock(&(futex), private)

Definition at line 55 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 339 of file lowlevellock.h.

#define lll_trylock (   futex)    __lll_trylock (&(futex))
#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)

Definition at line 327 of file lowlevellock.h.

#define THREAD_INIT_LOCK (   PD,
  LOCK 
)    (PD)->LOCK = LLL_LOCK_INITIALIZER

Typedef Documentation

typedef int lll_lock_t

Definition at line 85 of file lowlevellock.h.


Function Documentation

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

Definition at line 28 of file lowlevellock.c.

{
  if (*futex == 2)
    lll_futex_wait (futex, 2, LLL_PRIVATE);

  while (atomic_exchange_acq (futex, 2) != 0)
    lll_futex_wait (futex, 2, LLL_PRIVATE);
}
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;
}
int __lll_timedwait_tid ( int ,
const struct timespec  
)

Variable Documentation

int struct timespec* abstime

Definition at line 268 of file lowlevellock.h.

Definition at line 237 of file lowlevellock.h.