Skip to content

Commit 0a636e9

Browse files
committed
clang-format phongo_atomic sources
1 parent 09d0e9a commit 0a636e9

File tree

2 files changed

+296
-308
lines changed

2 files changed

+296
-308
lines changed

src/phongo_atomic.c

Lines changed: 60 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@
2525
#include <sched.h>
2626
#endif
2727

28-
static void
29-
_thrd_yield (void)
28+
static void _thrd_yield(void)
3029
{
31-
BSON_IF_WINDOWS (SwitchToThread ();)
32-
BSON_IF_POSIX (sched_yield ();)
30+
BSON_IF_WINDOWS(SwitchToThread();)
31+
BSON_IF_POSIX(sched_yield();)
3332
}
3433

3534
/**
@@ -38,87 +37,83 @@ _thrd_yield (void)
3837
*/
3938
static int8_t gEmulAtomicLock = 0;
4039

41-
static void
42-
_lock_emul_atomic (void)
40+
static void _lock_emul_atomic(void)
4341
{
44-
int i;
45-
if (phongo_atomic_int8_compare_exchange_weak (&gEmulAtomicLock, 0, 1, phongo_memory_order_acquire) == 0) {
46-
/* Successfully took the spinlock */
47-
return;
48-
}
49-
/* Failed. Try taking ten more times, then begin sleeping. */
50-
for (i = 0; i < 10; ++i) {
51-
if (phongo_atomic_int8_compare_exchange_weak (&gEmulAtomicLock, 0, 1, phongo_memory_order_acquire) == 0) {
52-
/* Succeeded in taking the lock */
53-
return;
54-
}
55-
}
56-
/* Still don't have the lock. Spin and yield */
57-
while (phongo_atomic_int8_compare_exchange_weak (&gEmulAtomicLock, 0, 1, phongo_memory_order_acquire) != 0) {
58-
_thrd_yield ();
59-
}
42+
int i;
43+
if (phongo_atomic_int8_compare_exchange_weak(&gEmulAtomicLock, 0, 1, phongo_memory_order_acquire) == 0) {
44+
/* Successfully took the spinlock */
45+
return;
46+
}
47+
/* Failed. Try taking ten more times, then begin sleeping. */
48+
for (i = 0; i < 10; ++i) {
49+
if (phongo_atomic_int8_compare_exchange_weak(&gEmulAtomicLock, 0, 1, phongo_memory_order_acquire) == 0) {
50+
/* Succeeded in taking the lock */
51+
return;
52+
}
53+
}
54+
/* Still don't have the lock. Spin and yield */
55+
while (phongo_atomic_int8_compare_exchange_weak(&gEmulAtomicLock, 0, 1, phongo_memory_order_acquire) != 0) {
56+
_thrd_yield();
57+
}
6058
}
6159

62-
static void
63-
_unlock_emul_atomic (void)
60+
static void _unlock_emul_atomic(void)
6461
{
65-
int64_t rv = phongo_atomic_int8_exchange (&gEmulAtomicLock, 0, phongo_memory_order_release);
66-
BSON_ASSERT (rv == 1 && "Released atomic lock while not holding it");
62+
int64_t rv = phongo_atomic_int8_exchange(&gEmulAtomicLock, 0, phongo_memory_order_release);
63+
BSON_ASSERT(rv == 1 && "Released atomic lock while not holding it");
6764
}
6865

69-
int32_t
70-
_phongo_emul_atomic_int32_fetch_add (volatile int32_t *p, int32_t n, enum phongo_memory_order _unused)
66+
int32_t _phongo_emul_atomic_int32_fetch_add(volatile int32_t* p, int32_t n, enum phongo_memory_order _unused)
7167
{
72-
int32_t ret;
68+
int32_t ret;
7369

74-
BSON_UNUSED (_unused);
70+
BSON_UNUSED(_unused);
7571

76-
_lock_emul_atomic ();
77-
ret = *p;
78-
*p += n;
79-
_unlock_emul_atomic ();
80-
return ret;
72+
_lock_emul_atomic();
73+
ret = *p;
74+
*p += n;
75+
_unlock_emul_atomic();
76+
return ret;
8177
}
8278

83-
int32_t
84-
_phongo_emul_atomic_int32_exchange (volatile int32_t *p, int32_t n, enum phongo_memory_order _unused)
79+
int32_t _phongo_emul_atomic_int32_exchange(volatile int32_t* p, int32_t n, enum phongo_memory_order _unused)
8580
{
86-
int32_t ret;
81+
int32_t ret;
8782

88-
BSON_UNUSED (_unused);
83+
BSON_UNUSED(_unused);
8984

90-
_lock_emul_atomic ();
91-
ret = *p;
92-
*p = n;
93-
_unlock_emul_atomic ();
94-
return ret;
85+
_lock_emul_atomic();
86+
ret = *p;
87+
*p = n;
88+
_unlock_emul_atomic();
89+
return ret;
9590
}
9691

97-
int32_t
98-
_phongo_emul_atomic_int32_compare_exchange_strong (volatile int32_t *p,
99-
int32_t expect_value,
100-
int32_t new_value,
101-
enum phongo_memory_order _unused)
92+
int32_t _phongo_emul_atomic_int32_compare_exchange_strong(
93+
volatile int32_t* p,
94+
int32_t expect_value,
95+
int32_t new_value,
96+
enum phongo_memory_order _unused)
10297
{
103-
int32_t ret;
98+
int32_t ret;
10499

105-
BSON_UNUSED (_unused);
100+
BSON_UNUSED(_unused);
106101

107-
_lock_emul_atomic ();
108-
ret = *p;
109-
if (ret == expect_value) {
110-
*p = new_value;
111-
}
112-
_unlock_emul_atomic ();
113-
return ret;
102+
_lock_emul_atomic();
103+
ret = *p;
104+
if (ret == expect_value) {
105+
*p = new_value;
106+
}
107+
_unlock_emul_atomic();
108+
return ret;
114109
}
115110

116-
int32_t
117-
_phongo_emul_atomic_int32_compare_exchange_weak (volatile int32_t *p,
118-
int32_t expect_value,
119-
int32_t new_value,
120-
enum phongo_memory_order order)
111+
int32_t _phongo_emul_atomic_int32_compare_exchange_weak(
112+
volatile int32_t* p,
113+
int32_t expect_value,
114+
int32_t new_value,
115+
enum phongo_memory_order order)
121116
{
122-
/* We're emulating. We can't do a weak version. */
123-
return _phongo_emul_atomic_int32_compare_exchange_strong (p, expect_value, new_value, order);
117+
/* We're emulating. We can't do a weak version. */
118+
return _phongo_emul_atomic_int32_compare_exchange_strong(p, expect_value, new_value, order);
124119
}

0 commit comments

Comments
 (0)