Warning: That file was not part of the compilation database. It may have many parsing errors.

1/* Copyright (C) 2003-2019 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Jakub Jelinek <jakub@redhat.com>, 2003.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19#ifndef _LOWLEVELLOCK_H
20#define _LOWLEVELLOCK_H 1
21
22#include <time.h>
23#include <sys/param.h>
24#include <bits/pthreadtypes.h>
25#include <atomic.h>
26#include <kernel-features.h>
27
28#include <lowlevellock-futex.h>
29
30static inline int
31__attribute__ ((always_inline))
32__lll_trylock (int *futex)
33{
34 return atomic_compare_and_exchange_val_24_acq (futex, 1, 0) != 0;
35}
36#define lll_trylock(futex) __lll_trylock (&(futex))
37
38static inline int
39__attribute__ ((always_inline))
40__lll_cond_trylock (int *futex)
41{
42 return atomic_compare_and_exchange_val_24_acq (futex, 2, 0) != 0;
43}
44#define lll_cond_trylock(futex) __lll_cond_trylock (&(futex))
45
46
47extern void __lll_lock_wait_private (int *futex) attribute_hidden;
48extern void __lll_lock_wait (int *futex, int private) attribute_hidden;
49
50static inline void
51__attribute__ ((always_inline))
52__lll_lock (int *futex, int private)
53{
54 int val = atomic_compare_and_exchange_val_24_acq (futex, 1, 0);
55
56 if (__glibc_unlikely (val != 0))
57 {
58 if (__builtin_constant_p (private) && private == LLL_PRIVATE)
59 __lll_lock_wait_private (futex);
60 else
61 __lll_lock_wait (futex, private);
62 }
63}
64#define lll_lock(futex, private) __lll_lock (&(futex), private)
65
66static inline void
67__attribute__ ((always_inline))
68__lll_cond_lock (int *futex, int private)
69{
70 int val = atomic_compare_and_exchange_val_24_acq (futex, 2, 0);
71
72 if (__glibc_unlikely (val != 0))
73 __lll_lock_wait (futex, private);
74}
75#define lll_cond_lock(futex, private) __lll_cond_lock (&(futex), private)
76
77
78extern int __lll_timedlock_wait (int *futex, const struct timespec *,
79 int private) attribute_hidden;
80
81static inline int
82__attribute__ ((always_inline))
83__lll_timedlock (int *futex, const struct timespec *abstime, int private)
84{
85 int val = atomic_compare_and_exchange_val_24_acq (futex, 1, 0);
86 int result = 0;
87
88 if (__glibc_unlikely (val != 0))
89 result = __lll_timedlock_wait (futex, abstime, private);
90 return result;
91}
92#define lll_timedlock(futex, abstime, private) \
93 __lll_timedlock (&(futex), abstime, private)
94
95#define lll_unlock(lock, private) \
96 ((void) ({ \
97 int *__futex = &(lock); \
98 int __private = (private); \
99 int __val = atomic_exchange_24_rel (__futex, 0); \
100 if (__glibc_unlikely (__val > 1)) \
101 lll_futex_wake (__futex, 1, __private); \
102 }))
103
104#define lll_islocked(futex) \
105 (futex != 0)
106
107/* Initializers for lock. */
108#define LLL_LOCK_INITIALIZER (0)
109#define LLL_LOCK_INITIALIZER_LOCKED (1)
110
111#endif /* lowlevellock.h */
112

Warning: That file was not part of the compilation database. It may have many parsing errors.