L4Re - L4 Runtime Environment
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 
27 typedef l4_uint32_t l4util_simple_lock_t;
28 
29 L4_INLINE int l4_simple_try_lock(l4util_simple_lock_t *lock);
30 L4_INLINE void l4_simple_unlock(l4util_simple_lock_t *lock);
31 L4_INLINE int l4_simple_lock_locked(l4util_simple_lock_t *lock);
32 L4_INLINE void l4_simple_lock_solid(register l4util_simple_lock_t *p);
33 L4_INLINE void l4_simple_lock(l4util_simple_lock_t * lock);
34 
35 L4_INLINE int
36 l4_simple_try_lock(l4util_simple_lock_t *lock)
37 {
38  return l4util_xchg32(lock, 1) == 0;
39 }
40 
41 L4_INLINE void
42 l4_simple_unlock(l4util_simple_lock_t *lock)
43 {
44  *lock = 0;
45 }
46 
47 L4_INLINE int
48 l4_simple_lock_locked(l4util_simple_lock_t *lock)
49 {
50  return (*lock == 0) ? 0 : 1;
51 }
52 
53 L4_INLINE void
54 l4_simple_lock_solid(register l4util_simple_lock_t *p)
55 {
56  while (l4_simple_lock_locked(p) || !l4_simple_try_lock(p))
58 }
59 
60 L4_INLINE void
61 l4_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_uint32_t l4util_xchg32(volatile l4_uint32_t *dest, l4_uint32_t val)
Atomic exchange (32 bit version)
Definition: atomic.h:343
Invalid capability selector.
Definition: consts.h:141
#define EXTERN_C_END
End section with C types and functions.
Definition: compiler.h:187
L4 compiler related defines.
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:889
atomic operations header and generic implementations
#define EXTERN_C_BEGIN
Start section with C types and functions.
Definition: compiler.h:186
unsigned int l4_uint32_t
Unsigned 32bit value.
Definition: l4int.h:40