Blame hurd/hurdlock.h

Packit 6c4009
/* Low-level lock implementation.  High-level Hurd helpers.
Packit 6c4009
   Copyright (C) 1999-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#ifndef _HURD_LOCK_H
Packit 6c4009
#define _HURD_LOCK_H   1
Packit 6c4009
Packit 6c4009
#include <mach/lowlevellock.h>
Packit 6c4009
Packit 6c4009
struct timespec;
Packit 6c4009
Packit 6c4009
/* Flags for robust locks.  */
Packit 6c4009
#define LLL_WAITERS      (1U << 31)
Packit 6c4009
#define LLL_DEAD_OWNER   (1U << 30)
Packit 6c4009
Packit 6c4009
#define LLL_OWNER_MASK   ~(LLL_WAITERS | LLL_DEAD_OWNER)
Packit 6c4009
Packit 6c4009
/* Wait on 64-bit address PTR, without blocking if its contents
Packit 6c4009
   are different from the pair <LO, HI>.  */
Packit 6c4009
#define lll_xwait(ptr, lo, hi, flags) \
Packit 6c4009
  __gsync_wait (__mach_task_self (), \
Packit 6c4009
    (vm_offset_t)ptr, lo, hi, 0, flags | GSYNC_QUAD)
Packit 6c4009
Packit 6c4009
/* Same as 'lll_wait', but only block for MLSEC milliseconds.  */
Packit 6c4009
#define lll_timed_wait(ptr, val, mlsec, flags) \
Packit 6c4009
  __gsync_wait (__mach_task_self (), \
Packit 6c4009
    (vm_offset_t)ptr, val, 0, mlsec, flags | GSYNC_TIMED)
Packit 6c4009
Packit 6c4009
/* Same as 'lll_xwait', but only block for MLSEC milliseconds.  */
Packit 6c4009
#define lll_timed_xwait(ptr, lo, hi, mlsec, flags) \
Packit 6c4009
  __gsync_wait (__mach_task_self (), (vm_offset_t)ptr, \
Packit 6c4009
    lo, hi, mlsec, flags | GSYNC_TIMED | GSYNC_QUAD)
Packit 6c4009
Packit 6c4009
/* Same as 'lll_wait', but only block until TSP elapses,
Packit 6c4009
   using clock CLK.  */
Packit 6c4009
extern int __lll_abstimed_wait (void *__ptr, int __val,
Packit 6c4009
  const struct timespec *__tsp, int __flags, int __clk);
Packit 6c4009
Packit 6c4009
/* Same as 'lll_xwait', but only block until TSP elapses,
Packit 6c4009
   using clock CLK.  */
Packit 6c4009
extern int __lll_abstimed_xwait (void *__ptr, int __lo, int __hi,
Packit 6c4009
  const struct timespec *__tsp, int __flags, int __clk);
Packit 6c4009
Packit 6c4009
/* Same as 'lll_lock', but return with an error if TSP elapses,
Packit 6c4009
   using clock CLK.  */
Packit 6c4009
extern int __lll_abstimed_lock (void *__ptr,
Packit 6c4009
  const struct timespec *__tsp, int __flags, int __clk);
Packit 6c4009
Packit 6c4009
/* Acquire the lock at PTR, but return with an error if
Packit 6c4009
   the process containing the owner thread dies.  */
Packit 6c4009
extern int __lll_robust_lock (void *__ptr, int __flags);
Packit 6c4009
Packit 6c4009
/* Same as '__lll_robust_lock', but only block until TSP
Packit 6c4009
   elapses, using clock CLK.  */
Packit 6c4009
extern int __lll_robust_abstimed_lock (void *__ptr,
Packit 6c4009
  const struct timespec *__tsp, int __flags, int __clk);
Packit 6c4009
Packit 6c4009
/* Same as '__lll_robust_lock', but return with an error
Packit 6c4009
   if the lock cannot be acquired without blocking.  */
Packit 6c4009
extern int __lll_robust_trylock (void *__ptr);
Packit 6c4009
Packit 6c4009
/* Wake one or more threads waiting on address PTR,
Packit 6c4009
   setting its value to VAL before doing so.  */
Packit 6c4009
#define lll_set_wake(ptr, val, flags) \
Packit 6c4009
  __gsync_wake (__mach_task_self (), \
Packit 6c4009
    (vm_offset_t)ptr, val, flags | GSYNC_MUTATE)
Packit 6c4009
Packit 6c4009
/* Release the robust lock at PTR.  */
Packit 6c4009
extern void __lll_robust_unlock (void *__ptr, int __flags);
Packit 6c4009
Packit 6c4009
/* Rearrange threads waiting on address SRC to instead wait on
Packit 6c4009
   DST, waking one of them if WAIT_ONE is non-zero.  */
Packit 6c4009
#define lll_requeue(src, dst, wake_one, flags) \
Packit 6c4009
  __gsync_requeue (__mach_task_self (), (vm_offset_t)src, \
Packit 6c4009
    (vm_offset_t)dst, (boolean_t)wake_one, flags)
Packit 6c4009
Packit 6c4009
/* The following are hacks that allow us to simulate optional
Packit 6c4009
   parameters in C, to avoid having to pass the clock id for
Packit 6c4009
   every one of these calls, defaulting to CLOCK_REALTIME if
Packit 6c4009
   no argument is passed.  */
Packit 6c4009
Packit 6c4009
#define lll_abstimed_wait(ptr, val, tsp, flags, ...)   \
Packit 6c4009
  ({   \
Packit 6c4009
     const clockid_t __clk[] = { CLOCK_REALTIME, ##__VA_ARGS__ };   \
Packit 6c4009
     __lll_abstimed_wait ((ptr), (val), (tsp), (flags),   \
Packit 6c4009
       __clk[sizeof (__clk) / sizeof (__clk[0]) - 1]);   \
Packit 6c4009
   })
Packit 6c4009
Packit 6c4009
#define lll_abstimed_xwait(ptr, lo, hi, tsp, flags, ...)   \
Packit 6c4009
  ({   \
Packit 6c4009
     const clockid_t __clk[] = { CLOCK_REALTIME, ##__VA_ARGS__ };   \
Packit 6c4009
     __lll_abstimed_xwait ((ptr), (lo), (hi), (tsp), (flags),   \
Packit 6c4009
       __clk[sizeof (__clk) / sizeof (__clk[0]) - 1]);   \
Packit 6c4009
   })
Packit 6c4009
Packit 6c4009
#define lll_abstimed_lock(ptr, tsp, flags, ...)   \
Packit 6c4009
  ({   \
Packit 6c4009
     const clockid_t __clk[] = { CLOCK_REALTIME, ##__VA_ARGS__ };   \
Packit 6c4009
     __lll_abstimed_lock ((ptr), (tsp), (flags),   \
Packit 6c4009
       __clk[sizeof (__clk) / sizeof (__clk[0]) - 1]);   \
Packit 6c4009
   })
Packit 6c4009
Packit 6c4009
#define lll_robust_abstimed_lock(ptr, tsp, flags, ...)   \
Packit 6c4009
  ({   \
Packit 6c4009
     const clockid_t __clk[] = { CLOCK_REALTIME, ##__VA_ARGS__ };   \
Packit 6c4009
     __lll_robust_abstimed_lock ((ptr), (tsp), (flags),   \
Packit 6c4009
       __clk[sizeof (__clk) / sizeof (__clk[0]) - 1]);   \
Packit 6c4009
   })
Packit 6c4009
Packit 6c4009
Packit 6c4009
#endif