From eaa470676a69c06fdf55aa6c13b715dbd2c1b929 Mon Sep 17 00:00:00 2001
From: Arvind S Raj <sraj.arvind@gmail.com>
Date: Fri, 15 Aug 2014 23:41:49 +0530
Subject: [PATCH] Reimplemented atomic_get_and_set in C++.
---
build/jam/board/beagle/BoardSetup | 2 +-
src/system/kernel/lib/arch/arm/Jamfile | 1 +
src/system/libroot/os/arch/arm/Jamfile | 1 +
src/system/libroot/os/arch/arm/atomic.S | 10 ----------
src/system/libroot/os/arch/generic/generic_atomic.cpp | 19 +++++++++++++++++++
5 files changed, 22 insertions(+), 11 deletions(-)
create mode 100644 src/system/libroot/os/arch/generic/generic_atomic.cpp
diff --git a/build/jam/board/beagle/BoardSetup b/build/jam/board/beagle/BoardSetup
index 5ee0a11..ddf5442 100644
a
|
b
|
HAIKU_CCFLAGS_$(HAIKU_PACKAGING_ARCH)
|
73 | 73 | -DHAIKU_BOARD_LOADER_STACK_BASE=$(HAIKU_BOARD_LOADER_STACK_BASE) |
74 | 74 | -DHAIKU_BOARD_LOADER_UIBASE=$(HAIKU_BOARD_LOADER_UIBASE) ; |
75 | 75 | HAIKU_C++FLAGS_$(HAIKU_PACKAGING_ARCH) |
76 | | += -mcpu=cortex-a8 -mfpu=vfpv3 -mfloat-abi=hard |
| 76 | += -mcpu=cortex-a8 -mfpu=vfpv3 -mfloat-abi=hard -std=c++11 |
77 | 77 | -DHAIKU_BOARD_LOADER_STACK_BASE=$(HAIKU_BOARD_LOADER_STACK_BASE) |
78 | 78 | -DHAIKU_BOARD_LOADER_UIBASE=$(HAIKU_BOARD_LOADER_UIBASE) ; |
diff --git a/src/system/kernel/lib/arch/arm/Jamfile b/src/system/kernel/lib/arch/arm/Jamfile
index 1bdf0f1..12b8c50 100644
a
|
b
|
KernelMergeObject kernel_os_arch_$(TARGET_ARCH).o :
|
12 | 12 | atomic.S |
13 | 13 | byteorder.S |
14 | 14 | |
| 15 | generic_atomic.cpp |
15 | 16 | generic_system_time_nsecs.cpp |
16 | 17 | |
17 | 18 | : $(TARGET_KERNEL_PIC_CCFLAGS) |
diff --git a/src/system/libroot/os/arch/arm/Jamfile b/src/system/libroot/os/arch/arm/Jamfile
index bdfa8c6..87acdea 100644
a
|
b
|
for architectureObject in [ MultiArchSubDirSetup arm ] {
|
20 | 20 | time.c |
21 | 21 | tls.c |
22 | 22 | |
| 23 | generic_atomic.cpp |
23 | 24 | generic_system_time_nsecs.cpp |
24 | 25 | ; |
25 | 26 | } |
diff --git a/src/system/libroot/os/arch/arm/atomic.S b/src/system/libroot/os/arch/arm/atomic.S
index 5728e5c..56f1c2c 100644
a
|
b
|
FUNCTION(atomic_set):
|
54 | 54 | bx lr |
55 | 55 | FUNCTION_END(atomic_set) |
56 | 56 | |
57 | | /* int atomic_get_and_set(int *value, int setTo) |
58 | | */ |
59 | | FUNCTION(atomic_get_and_set): |
60 | | miss4: ldrex r12, [r0] |
61 | | strex r3, r1, [r0] |
62 | | teq r3, #0 |
63 | | bne miss4 |
64 | | bx lr |
65 | | FUNCTION_END(atomic_get_and_set) |
66 | | |
67 | 57 | /* int atomic_test_and_set(int *value, int setTo, int testValue) |
68 | 58 | */ |
69 | 59 | FUNCTION(atomic_test_and_set): |
diff --git a/src/system/libroot/os/arch/generic/generic_atomic.cpp b/src/system/libroot/os/arch/generic/generic_atomic.cpp
new file mode 100644
index 0000000..73b5c56
-
|
+
|
|
| 1 | /* |
| 2 | * Copyright 2014, Haiku, Inc. |
| 3 | * Distributed under the terms of the MIT License. |
| 4 | * |
| 5 | */ |
| 6 | |
| 7 | #include <atomic> |
| 8 | #include <sys/types.h> |
| 9 | |
| 10 | #ifndef ATOMIC_FUNCS_ARE_SYSCALLS |
| 11 | |
| 12 | extern "C" int32_t |
| 13 | atomic_get_and_set(int32_t* ptr, int32_t value) |
| 14 | { |
| 15 | auto& obj = *reinterpret_cast<std::atomic<int32_t>*>(ptr); |
| 16 | return obj.exchange(value); |
| 17 | } |
| 18 | |
| 19 | #endif /* ATOMIC64_FUNCS_ARE_SYSCALLS */ |