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 <kernel-features.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define SYS_futex   238
#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(futex, val, private)   lll_futex_timed_wait (futex, val, NULL, private)
#define lll_futex_timed_wait(futex, val, timespec, private)
#define lll_futex_wake(futex, nr, private)
#define lll_robust_dead(futexv, private)
#define lll_futex_requeue(futex, nr_wake, nr_move, mutex, val, private)
#define lll_futex_wake_unlock(futex, nr_wake, nr_wake2, futex2, private)
#define lll_compare_and_swap(futex, oldval, newval, operation)
#define lll_trylock(futex)   __lll_trylock (&(futex))
#define lll_cond_trylock(futex)   __lll_cond_trylock (&(futex))
#define lll_robust_trylock(futex, id)   __lll_robust_trylock (&(futex), 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(ptid)
#define lll_wait_tid(tid)   __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 54 of file lowlevellock.h.

#define __lll_robust_unlock (   futex,
  private 
)
Value:
(void)                                                        \
    ({ int __oldval;                                                 \
       int __newval = 0;                                             \
       int *__futexp = (futex);                                             \
									      \
       lll_compare_and_swap (__futexp, __oldval, __newval, "slr %2,%2");      \
       if (__builtin_expect (__oldval & FUTEX_WAITERS, 0))                  \
        lll_futex_wake (__futexp, 1, private);                              \
    })
#define __lll_unlock (   futex,
  private 
)
Value:
(void)                                                        \
    ({ int __oldval;                                                 \
       int __newval = 0;                                             \
       int *__futexp = (futex);                                             \
									      \
       lll_compare_and_swap (__futexp, __oldval, __newval, "slr %2,%2");      \
       if (__builtin_expect (__oldval > 1, 0))                              \
        lll_futex_wake (__futexp, 1, private);                              \
    })
#define __lll_wait_tid (   ptid)
Value:
do                                                                   \
    {                                                                \
      int __tid;                                                     \
                                                                     \
      while ((__tid = *ptid) != 0)                                   \
       lll_futex_wait (ptid, __tid, LLL_SHARED);                     \
    }                                                                \
  while (0)
#define FUTEX_CMP_REQUEUE   4

Definition at line 33 of file lowlevellock.h.

#define FUTEX_LOCK_PI   6

Definition at line 36 of file lowlevellock.h.

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

Definition at line 35 of file lowlevellock.h.

#define FUTEX_PRIVATE_FLAG   128

Definition at line 39 of file lowlevellock.h.

#define FUTEX_REQUEUE   3

Definition at line 32 of file lowlevellock.h.

#define FUTEX_TRYLOCK_PI   8

Definition at line 38 of file lowlevellock.h.

#define FUTEX_UNLOCK_PI   7

Definition at line 37 of file lowlevellock.h.

#define FUTEX_WAIT   0

Definition at line 30 of file lowlevellock.h.

#define FUTEX_WAKE   1

Definition at line 31 of file lowlevellock.h.

#define FUTEX_WAKE_OP   5

Definition at line 34 of file lowlevellock.h.

#define lll_compare_and_swap (   futex,
  oldval,
  newval,
  operation 
)
Value:
do {                                                                 \
    __typeof (futex) __futex = (futex);                                     \
    __asm __volatile ("       l   %1,%0\n"                                         \
                    "0: " operation "\n"                             \
                    "         cs  %1,%2,%0\n"                               \
                    "         jl  0b\n"                                     \
                    "1:"                                             \
                    : "=Q" (*__futex), "=&d" (oldval), "=&d" (newval)       \
                    : "m" (*__futex) : "cc", "memory" );                    \
  } while (0)

Definition at line 163 of file lowlevellock.h.

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

Definition at line 201 of file lowlevellock.h.

#define lll_futex_requeue (   futex,
  nr_wake,
  nr_move,
  mutex,
  val,
  private 
)
Value:
({                                                                   \
    register unsigned long int __r2 asm ("2") = (unsigned long int) (futex);  \
    register unsigned long int __r3 asm ("3")                               \
      = __lll_private_flag (FUTEX_CMP_REQUEUE, private);                    \
    register unsigned long int __r4 asm ("4") = (long int) (nr_wake);       \
    register unsigned long int __r5 asm ("5") = (long int) (nr_move);       \
    register unsigned long int __r6 asm ("6") = (unsigned long int) (mutex);  \
    register unsigned long int __r7 asm ("7") = (int) (val);                \
    register unsigned long __result asm ("2");                              \
                                                                     \
    __asm __volatile ("svc %b1"                                             \
                    : "=d" (__result)                                       \
                    : "i" (SYS_futex), "0" (__r2), "d" (__r3),       \
                     "d" (__r4), "d" (__r5), "d" (__r6), "d" (__r7)         \
                    : "cc", "memory" );                              \
    __result > -4096UL;                                                     \
  })

Definition at line 121 of file lowlevellock.h.

#define lll_futex_timed_wait (   futex,
  val,
  timespec,
  private 
)
Value:
({                                                                   \
    register unsigned long int __r2 asm ("2") = (unsigned long int) (futex);  \
    register unsigned long int __r3 asm ("3")                               \
      = __lll_private_flag (FUTEX_WAIT, private);                           \
    register unsigned long int __r4 asm ("4") = (unsigned long int) (val);    \
    register unsigned long int __r5 asm ("5") = (unsigned long int)(timespec);\
    register unsigned long int __result asm ("2");                          \
                                                                     \
    __asm __volatile ("svc %b1"                                             \
                    : "=d" (__result)                                       \
                    : "i" (SYS_futex), "0" (__r2), "d" (__r3),       \
                     "d" (__r4), "d" (__r5)                                 \
                    : "cc", "memory" );                              \
    __result;                                                        \
  })

Definition at line 75 of file lowlevellock.h.

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

Definition at line 72 of file lowlevellock.h.

#define lll_futex_wake (   futex,
  nr,
  private 
)
Value:
({                                                                   \
    register unsigned long int __r2 asm ("2") = (unsigned long int) (futex);  \
    register unsigned long int __r3 asm ("3")                               \
      = __lll_private_flag (FUTEX_WAKE, private);                           \
    register unsigned long int __r4 asm ("4") = (unsigned long int) (nr);     \
    register unsigned long int __result asm ("2");                          \
                                                                     \
    __asm __volatile ("svc %b1"                                             \
                    : "=d" (__result)                                       \
                    : "i" (SYS_futex), "0" (__r2), "d" (__r3), "d" (__r4)   \
                    : "cc", "memory" );                              \
    __result;                                                        \
  })

Definition at line 93 of file lowlevellock.h.

#define lll_futex_wake_unlock (   futex,
  nr_wake,
  nr_wake2,
  futex2,
  private 
)
Value:
({                                                                   \
    register unsigned long int __r2 asm ("2") = (unsigned long int) (futex);  \
    register unsigned long int __r3 asm ("3")                               \
      = __lll_private_flag (FUTEX_WAKE_OP, private);                        \
    register unsigned long int __r4 asm ("4") = (long int) (nr_wake);       \
    register unsigned long int __r5 asm ("5") = (long int) (nr_wake2);             \
    register unsigned long int __r6 asm ("6") = (unsigned long int) (futex2); \
    register unsigned long int __r7 asm ("7")                               \
      = (int) FUTEX_OP_CLEAR_WAKE_IF_GT_ONE;                                \
    register unsigned long __result asm ("2");                              \
                                                                     \
    __asm __volatile ("svc %b1"                                             \
                    : "=d" (__result)                                       \
                    : "i" (SYS_futex), "0" (__r2), "d" (__r3),       \
                     "d" (__r4), "d" (__r5), "d" (__r6), "d" (__r7)         \
                    : "cc", "memory" );                              \
    __result > -4096UL;                                                     \
  })

Definition at line 142 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 44 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 109 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 45 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 346 of file lowlevellock.h.

#define lll_trylock (   futex)    __lll_trylock (&(futex))

Definition at line 187 of file lowlevellock.h.

#define lll_unlock (   futex,
  private 
)    __lll_unlock(&(futex), private)
#define lll_wait_tid (   tid)    __lll_wait_tid(&(tid))
#define SYS_futex   238

Definition at line 29 of file lowlevellock.h.


Function Documentation

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

Definition at line 177 of file lowlevellock.h.

{
    unsigned int old;

    __asm __volatile ("cs %0,%3,%1"
                     : "=d" (old), "=Q" (*futex)
                     : "0" (0), "d" (1), "m" (*futex) : "cc", "memory" );
    return old != 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 269 of file lowlevellock.h.