L4Re Operating System Framework
Interface and Usage Documentation
•All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
atomic.h
Go to the documentation of this file.
1
5/*
6 * (c) 2004-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
7 * Alexander Warg <warg@os.inf.tu-dresden.de>
8 * economic rights: Technische Universität Dresden (Germany)
9 *
10 * License: see LICENSE.spdx (in this directory or the directories above)
11 */
12#pragma once
13
14#include <l4/util/atomic.h>
15
16extern "C" void ____error_compare_and_swap_does_not_support_3_bytes____();
17extern "C" void ____error_compare_and_swap_does_not_support_more_than_4_bytes____();
18
19namespace L4
20{
21 template< typename X >
22 inline int compare_and_swap(X volatile *dst, X old_val, X new_val)
23 {
24 switch (sizeof(X))
25 {
26 case 1:
27 return l4util_cmpxchg8((l4_uint8_t volatile*)dst, old_val, new_val);
28 case 2:
29 return l4util_cmpxchg16((l4_uint16_t volatile *)dst, old_val, new_val);
30 case 3: ____error_compare_and_swap_does_not_support_3_bytes____();
31 case 4:
32 return l4util_cmpxchg32((l4_uint32_t volatile*)dst, old_val, new_val);
33 default:
34 ____error_compare_and_swap_does_not_support_more_than_4_bytes____();
35 }
36 return 0;
37 }
38}
unsigned char l4_uint8_t
Unsigned 8bit value.
Definition l4int.h:25
unsigned int l4_uint32_t
Unsigned 32bit value.
Definition l4int.h:29
unsigned short int l4_uint16_t
Unsigned 16bit value.
Definition l4int.h:27
int l4util_cmpxchg8(volatile l4_uint8_t *dest, l4_uint8_t cmp_val, l4_uint8_t new_val)
Atomic compare and exchange (8 bit version)
Definition atomic.h:371
int l4util_cmpxchg16(volatile l4_uint16_t *dest, l4_uint16_t cmp_val, l4_uint16_t new_val)
Atomic compare and exchange (16 bit version)
Definition atomic.h:363
int l4util_cmpxchg32(volatile l4_uint32_t *dest, l4_uint32_t cmp_val, l4_uint32_t new_val)
Atomic compare and exchange (32 bit version)
Definition atomic.h:355
atomic operations header and generic implementations
L4 low-level kernel interface.