Back to index

glibc  2.9
Defines | Functions
lowlevellock.h File Reference
#include <time.h>
#include <sys/param.h>
#include <bits/pthreadtypes.h>
#include <ia64intrin.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 __NR_futex   1230
#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 BUSY_WAIT_NOP   asm ("hint @pause")
#define lll_futex_wait(futex, val, private)   lll_futex_timed_wait (futex, val, NULL, private)
#define lll_futex_timed_wait(ftx, val, timespec, private)
#define lll_futex_wake(ftx, nr, private)
#define lll_robust_dead(futexv, private)
#define lll_futex_requeue(ftx, nr_wake, nr_move, mutex, val, private)
#define lll_futex_wake_unlock(ftx, nr_wake, nr_wake2, ftx2, private)
#define __lll_trylock(futex)   (atomic_compare_and_exchange_val_acq (futex, 1, 0) != 0)
#define lll_trylock(futex)   __lll_trylock (&(futex))
#define __lll_robust_trylock(futex, id)   (atomic_compare_and_exchange_val_acq (futex, id, 0) != 0)
#define lll_robust_trylock(futex, id)   __lll_robust_trylock (&(futex), id)
#define __lll_cond_trylock(futex)   (atomic_compare_and_exchange_val_acq (futex, 2, 0) != 0)
#define lll_cond_trylock(futex)   __lll_cond_trylock (&(futex))
#define __lll_lock(futex, private)
#define lll_lock(futex, private)   __lll_lock (&(futex), private)
#define __lll_robust_lock(futex, id, private)
#define lll_robust_lock(futex, id, private)   __lll_robust_lock (&(futex), id, private)
#define __lll_cond_lock(futex, private)
#define lll_cond_lock(futex, private)   __lll_cond_lock (&(futex), private)
#define __lll_robust_cond_lock(futex, id, private)
#define lll_robust_cond_lock(futex, id, private)   __lll_robust_cond_lock (&(futex), id, private)
#define __lll_timedlock(futex, abstime, private)
#define lll_timedlock(futex, abstime, private)   __lll_timedlock (&(futex), abstime, private)
#define __lll_robust_timedlock(futex, abstime, id, 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

void __lll_lock_wait_private (int *futex) attribute_hidden
void __lll_lock_wait (int *futex, int private) attribute_hidden
int __lll_robust_lock_wait (int *futex, int private) attribute_hidden
int __lll_timedlock_wait (int *futex, const struct timespec *, int private) 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

Define Documentation

#define __lll_cond_lock (   futex,
  private 
)
Value:
((void) ({                                                           \
    int *__futex = (futex);                                          \
    if (__builtin_expect (atomic_compare_and_exchange_bool_acq (__futex, 2,   \
                                                        0), 0))             \
      __lll_lock_wait (__futex, private);                            \
  }))

Definition at line 177 of file lowlevellock.h.

#define __lll_cond_trylock (   futex)    (atomic_compare_and_exchange_val_acq (futex, 2, 0) != 0)

Definition at line 138 of file lowlevellock.h.

#define __lll_lock (   futex,
  private 
)
Value:
((void) ({                                                           \
    int *__futex = (futex);                                          \
    if (__builtin_expect (atomic_compare_and_exchange_bool_acq (__futex,      \
                                                        1, 0), 0))    \
      {                                                                     \
       if (__builtin_constant_p (private) && (private) == LLL_PRIVATE)             \
         __lll_lock_wait_private (__futex);                                 \
	else								      \
	  __lll_lock_wait (__futex, private);                               \
      }                                                                     \
  }))

Definition at line 148 of file lowlevellock.h.

#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_cond_lock (   futex,
  id,
  private 
)
Value:
({                                                                   \
    int *__futex = (futex);                                          \
    int __val = 0;                                                   \
    int __id = (id) | FUTEX_WAITERS;                                        \
                                                                     \
    if (__builtin_expect (atomic_compare_and_exchange_bool_acq (__futex,      \
                                                        __id, 0), 0)) \
      __val = __lll_robust_lock_wait (__futex, private);                    \
    __val;                                                           \
  })

Definition at line 187 of file lowlevellock.h.

#define __lll_robust_lock (   futex,
  id,
  private 
)
Value:
({                                                                   \
    int *__futex = (futex);                                          \
    int __val = 0;                                                   \
                                                                     \
    if (__builtin_expect (atomic_compare_and_exchange_bool_acq (__futex, id,  \
                                                        0), 0))             \
      __val = __lll_robust_lock_wait (__futex, private);                    \
    __val;                                                           \
  })

Definition at line 163 of file lowlevellock.h.

#define __lll_robust_timedlock (   futex,
  abstime,
  id,
  private 
)
Value:
({                                                                   \
    int *__futex = (futex);                                          \
    int __val = 0;                                                   \
                                                                     \
    if (__builtin_expect (atomic_compare_and_exchange_bool_acq (__futex, id,  \
                                                        0), 0))             \
      __val = __lll_robust_timedlock_wait (__futex, abstime, private);             \
    __val;                                                           \
  })

Definition at line 222 of file lowlevellock.h.

#define __lll_robust_trylock (   futex,
  id 
)    (atomic_compare_and_exchange_val_acq (futex, id, 0) != 0)

Definition at line 132 of file lowlevellock.h.

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

Definition at line 247 of file lowlevellock.h.

#define __lll_timedlock (   futex,
  abstime,
  private 
)
Value:
({                                                                   \
     int *__futex = (futex);                                                \
     int __val = 0;                                                  \
                                                                     \
     if (__builtin_expect (atomic_compare_and_exchange_bool_acq (__futex, 1,  \
                                                         0), 0))      \
       __val = __lll_timedlock_wait (__futex, abstime, private);            \
     __val;                                                          \
  })

Definition at line 208 of file lowlevellock.h.

#define __lll_trylock (   futex)    (atomic_compare_and_exchange_val_acq (futex, 1, 0) != 0)

Definition at line 127 of file lowlevellock.h.

#define __lll_unlock (   futex,
  private 
)
Value:
((void) ({                                                           \
    int *__futex = (futex);                                          \
    int __val = atomic_exchange_rel (__futex, 0);                           \
                                                                     \
    if (__builtin_expect (__val > 1, 0))                             \
      lll_futex_wake (__futex, 1, private);                                 \
  }))

Definition at line 236 of file lowlevellock.h.

#define __NR_futex   1230

Definition at line 30 of file lowlevellock.h.

#define BUSY_WAIT_NOP   asm ("hint @pause")

Definition at line 75 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)

Definition at line 184 of file lowlevellock.h.

#define lll_cond_trylock (   futex)    __lll_cond_trylock (&(futex))

Definition at line 140 of file lowlevellock.h.

#define lll_futex_requeue (   ftx,
  nr_wake,
  nr_move,
  mutex,
  val,
  private 
)
Value:
({                                                                  \
   DO_INLINE_SYSCALL(futex, 6, (long) (ftx),                               \
                   __lll_private_flag (FUTEX_CMP_REQUEUE, private),        \
                   (int) (nr_wake), (int) (nr_move), (long) (mutex),       \
                   (int) val);                                      \
   _r10 == -1;                                                             \
})

Definition at line 107 of file lowlevellock.h.

#define lll_futex_timed_wait (   ftx,
  val,
  timespec,
  private 
)
Value:
({                                                             \
   DO_INLINE_SYSCALL(futex, 4, (long) (ftx),                          \
                   __lll_private_flag (FUTEX_WAIT, private),          \
                   (int) (val), (long) (timespec));                   \
   _r10 == -1 ? -_retval : _retval;                                   \
})

Definition at line 80 of file lowlevellock.h.

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

Definition at line 77 of file lowlevellock.h.

#define lll_futex_wake (   ftx,
  nr,
  private 
)
Value:
({                                                             \
   DO_INLINE_SYSCALL(futex, 3, (long) (ftx),                          \
                   __lll_private_flag (FUTEX_WAKE, private),          \
                   (int) (nr));                                \
   _r10 == -1 ? -_retval : _retval;                                   \
})

Definition at line 88 of file lowlevellock.h.

#define lll_futex_wake_unlock (   ftx,
  nr_wake,
  nr_wake2,
  ftx2,
  private 
)
Value:
({                                                                  \
   DO_INLINE_SYSCALL(futex, 6, (long) (ftx),                               \
                   __lll_private_flag (FUTEX_WAKE_OP, private),            \
                   (int) (nr_wake), (int) (nr_wake2), (long) (ftx2),       \
                   FUTEX_OP_CLEAR_WAKE_IF_GT_ONE);                         \
   _r10 == -1;                                                             \
})

Definition at line 117 of file lowlevellock.h.

#define lll_islocked (   futex)    (futex != 0)

Definition at line 259 of file lowlevellock.h.

#define lll_lock (   futex,
  private 
)    __lll_lock (&(futex), private)

Definition at line 160 of file lowlevellock.h.

#define LLL_LOCK_INITIALIZER   (0)

Definition at line 263 of file lowlevellock.h.

#define LLL_LOCK_INITIALIZER_LOCKED   (1)

Definition at line 264 of file lowlevellock.h.

#define LLL_PRIVATE   0

Definition at line 45 of file lowlevellock.h.

#define lll_robust_cond_lock (   futex,
  id,
  private 
)    __lll_robust_cond_lock (&(futex), id, private)

Definition at line 198 of file lowlevellock.h.

#define lll_robust_dead (   futexv,
  private 
)
Value:
do                                                             \
  {                                                            \
    int *__futexp = &(futexv);                                        \
    atomic_or (__futexp, FUTEX_OWNER_DIED);                           \
    DO_INLINE_SYSCALL(futex, 3, (long) __futexp,               \
                    __lll_private_flag (FUTEX_WAKE, private), 1);     \
  }                                                            \
while (0)

Definition at line 96 of file lowlevellock.h.

#define lll_robust_lock (   futex,
  id,
  private 
)    __lll_robust_lock (&(futex), id, private)

Definition at line 173 of file lowlevellock.h.

#define lll_robust_timedlock (   futex,
  abstime,
  id,
  private 
)    __lll_robust_timedlock (&(futex), abstime, id, private)

Definition at line 232 of file lowlevellock.h.

#define lll_robust_trylock (   futex,
  id 
)    __lll_robust_trylock (&(futex), id)

Definition at line 134 of file lowlevellock.h.

#define lll_robust_unlock (   futex,
  private 
)    __lll_robust_unlock(&(futex), private)

Definition at line 255 of file lowlevellock.h.

Definition at line 46 of file lowlevellock.h.

#define lll_timedlock (   futex,
  abstime,
  private 
)    __lll_timedlock (&(futex), abstime, private)

Definition at line 218 of file lowlevellock.h.

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

Definition at line 282 of file lowlevellock.h.

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

Definition at line 129 of file lowlevellock.h.

#define lll_unlock (   futex,
  private 
)    __lll_unlock(&(futex), private)

Definition at line 244 of file lowlevellock.h.

#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 270 of file lowlevellock.h.


Function Documentation

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);
}
void __lll_lock_wait_private ( int futex)

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_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;
}
int __lll_timedlock_wait ( int futex,
const struct timespec ,
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;
}
int __lll_timedwait_tid ( int ,
const struct timespec  
)