Loading...
Searching...
No Matches
lock.h
Go to the documentation of this file.
/*****************************************************************************/
/*
* (c) 2000-2009 Author(s)
* economic rights: Technische Universität Dresden (Germany)
* License: see LICENSE.spdx (in this directory or the directories above)
*/
/*****************************************************************************/
#ifndef __L4UTIL_LOCK_H__
#define __L4UTIL_LOCK_H__
#include <l4/sys/thread.h>
#include <l4/sys/compiler.h>
#include <l4/util/atomic.h>
L4_BEGIN_DECLS
typedef l4_uint32_t l4util_simple_lock_t;
L4_INLINE int l4_simple_try_lock(l4util_simple_lock_t *lock);
L4_INLINE void l4_simple_unlock(l4util_simple_lock_t *lock);
L4_INLINE int l4_simple_lock_locked(l4util_simple_lock_t *lock);
L4_INLINE void l4_simple_lock_solid(register l4util_simple_lock_t *p);
L4_INLINE void l4_simple_lock(l4util_simple_lock_t * lock);
L4_INLINE int
l4_simple_try_lock(l4util_simple_lock_t *lock)
{
return l4util_xchg32(lock, 1) == 0;
}
L4_INLINE void
l4_simple_unlock(l4util_simple_lock_t *lock)
{
*lock = 0;
}
L4_INLINE int
l4_simple_lock_locked(l4util_simple_lock_t *lock)
{
return (*lock == 0) ? 0 : 1;
}
L4_INLINE void
l4_simple_lock_solid(register l4util_simple_lock_t *p)
{
while (l4_simple_lock_locked(p) || !l4_simple_try_lock(p))
l4_thread_switch(L4_INVALID_CAP);
}
L4_INLINE void
l4_simple_lock(l4util_simple_lock_t * lock)
{
if (!l4_simple_try_lock(lock))
l4_simple_lock_solid(lock);
}
L4_END_DECLS
#endif
compiler.h
L4 compiler related defines.
l4_uint32_t
unsigned int l4_uint32_t
Unsigned 32bit value.
Definition l4int.h:29
L4_INVALID_CAP
@ L4_INVALID_CAP
Invalid capability selector.
Definition consts.h:153
l4_thread_switch
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:996
L4_INLINE
#define L4_INLINE
L4 Inline function attribute.
Definition compiler.h:51
L4_BEGIN_DECLS
#define L4_BEGIN_DECLS
Start section with C types and functions.
Definition compiler.h:165
L4_END_DECLS
#define L4_END_DECLS
End section with C types and functions.
Definition compiler.h:166
l4util_xchg32
l4_uint32_t l4util_xchg32(volatile l4_uint32_t *dest, l4_uint32_t val)
Atomic exchange (32 bit version).
Definition atomic.h:387
thread.h
Common thread related definitions.
atomic.h
atomic operations header and generic implementations