L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
lock.h
Go to the documentation of this file.
1/*****************************************************************************/
9/*
10 * (c) 2000-2009 Author(s)
11 * economic rights: Technische Universität Dresden (Germany)
12 * This file is part of TUD:OS and distributed under the terms of the
13 * GNU Lesser General Public License 2.1.
14 * Please see the COPYING-LGPL-2.1 file for details.
15 */
16
17/*****************************************************************************/
18#ifndef __L4UTIL_LOCK_H__
19#define __L4UTIL_LOCK_H__
20
21#include <l4/sys/thread.h>
22#include <l4/sys/compiler.h>
23#include <l4/util/atomic.h>
24
26
27typedef l4_uint32_t l4util_simple_lock_t;
28
29L4_INLINE int l4_simple_try_lock(l4util_simple_lock_t *lock);
30L4_INLINE void l4_simple_unlock(l4util_simple_lock_t *lock);
31L4_INLINE int l4_simple_lock_locked(l4util_simple_lock_t *lock);
32L4_INLINE void l4_simple_lock_solid(register l4util_simple_lock_t *p);
33L4_INLINE void l4_simple_lock(l4util_simple_lock_t * lock);
34
35L4_INLINE int
36l4_simple_try_lock(l4util_simple_lock_t *lock)
37{
38 return l4util_xchg32(lock, 1) == 0;
39}
40
41L4_INLINE void
42l4_simple_unlock(l4util_simple_lock_t *lock)
43{
44 *lock = 0;
45}
46
47L4_INLINE int
48l4_simple_lock_locked(l4util_simple_lock_t *lock)
49{
50 return (*lock == 0) ? 0 : 1;
51}
52
53L4_INLINE void
54l4_simple_lock_solid(register l4util_simple_lock_t *p)
55{
56 while (l4_simple_lock_locked(p) || !l4_simple_try_lock(p))
58}
59
60L4_INLINE void
61l4_simple_lock(l4util_simple_lock_t * lock)
62{
63 if (!l4_simple_try_lock(lock))
64 l4_simple_lock_solid(lock);
65}
66
68
69#endif
L4 compiler related defines.
unsigned int l4_uint32_t
Unsigned 32bit value.
Definition l4int.h:40
@ L4_INVALID_CAP
Invalid capability selector.
Definition consts.h:168
l4_msgtag_t l4_thread_switch(l4_cap_idx_t to_thread) L4_NOTHROW
Switch to another thread (and donate the remaining time slice).
Definition thread.h:972
#define L4_INLINE
L4 Inline function attribute.
Definition compiler.h:62
#define EXTERN_C_BEGIN
Start section with C types and functions.
Definition compiler.h:192
#define EXTERN_C_END
End section with C types and functions.
Definition compiler.h:193
l4_uint32_t l4util_xchg32(volatile l4_uint32_t *dest, l4_uint32_t val)
Atomic exchange (32 bit version)
Definition atomic.h:389
atomic operations header and generic implementations