Skip to content

Commit 0d32d2e

Browse files
committed
Finish generic-xlc.h draft atomics implementation.
Back-patch to 9.5, where commit b64d92f introduced this file.
1 parent be8b06c commit 0d32d2e

File tree

1 file changed

+6
-20
lines changed

1 file changed

+6
-20
lines changed

src/include/port/atomics/generic-xlc.h

+6-20
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818

1919
#if defined(HAVE_ATOMICS)
2020

21-
#include <atomic.h>
22-
2321
#define PG_HAVE_ATOMIC_U32_SUPPORT
2422
typedef struct pg_atomic_uint32
2523
{
@@ -48,9 +46,6 @@ static inline bool
4846
pg_atomic_compare_exchange_u32_impl(volatile pg_atomic_uint32 *ptr,
4947
uint32 *expected, uint32 newval)
5048
{
51-
bool ret;
52-
uint64 current;
53-
5449
/*
5550
* xlc's documentation tells us:
5651
* "If __compare_and_swap is used as a locking primitive, insert a call to
@@ -62,18 +57,15 @@ pg_atomic_compare_exchange_u32_impl(volatile pg_atomic_uint32 *ptr,
6257
* XXX: __compare_and_swap is defined to take signed parameters, but that
6358
* shouldn't matter since we don't perform any arithmetic operations.
6459
*/
65-
current = (uint32)__compare_and_swap((volatile int*)ptr->value,
66-
(int)*expected, (int)newval);
67-
ret = current == *expected;
68-
*expected = current;
69-
return ret;
60+
return __compare_and_swap((volatile int*)&ptr->value,
61+
(int *)expected, (int)newval);
7062
}
7163

7264
#define PG_HAVE_ATOMIC_FETCH_ADD_U32
7365
static inline uint32
7466
pg_atomic_fetch_add_u32_impl(volatile pg_atomic_uint32 *ptr, int32 add_)
7567
{
76-
return __fetch_and_add(&ptr->value, add_);
68+
return __fetch_and_add((volatile int *)&ptr->value, add_);
7769
}
7870

7971
#ifdef PG_HAVE_ATOMIC_U64_SUPPORT
@@ -83,23 +75,17 @@ static inline bool
8375
pg_atomic_compare_exchange_u64_impl(volatile pg_atomic_uint64 *ptr,
8476
uint64 *expected, uint64 newval)
8577
{
86-
bool ret;
87-
uint64 current;
88-
8978
__isync();
9079

91-
current = (uint64)__compare_and_swaplp((volatile long*)ptr->value,
92-
(long)*expected, (long)newval);
93-
ret = current == *expected;
94-
*expected = current;
95-
return ret;
80+
return __compare_and_swaplp((volatile long*)&ptr->value,
81+
(long *)expected, (long)newval);;
9682
}
9783

9884
#define PG_HAVE_ATOMIC_FETCH_ADD_U64
9985
static inline uint64
10086
pg_atomic_fetch_add_u64_impl(volatile pg_atomic_uint64 *ptr, int64 add_)
10187
{
102-
return __fetch_and_addlp(&ptr->value, add_);
88+
return __fetch_and_addlp((volatile long *)&ptr->value, add_);
10389
}
10490

10591
#endif /* PG_HAVE_ATOMIC_U64_SUPPORT */

0 commit comments

Comments
 (0)