Skip to content

Commit 174cb7f

Browse files
cfriedtnashif
authored andcommitted
kernel: atomics: support for 64-bit atomic operations
With this change, `atomic_t` is 32-bit for 32-bit architectures and 64-bit for 64-bit architectures. More specifically, `sizeof(atomic_t) == sizeof(long)`. Fixes #39530 Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
1 parent 0b400d8 commit 174cb7f

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

include/sys/atomic.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313
#include <stddef.h>
1414

1515
#include <zephyr/types.h>
16+
#include <sys/util_macro.h>
1617

1718
#ifdef __cplusplus
1819
extern "C" {
1920
#endif
2021

21-
typedef int atomic_t;
22+
typedef long atomic_t;
2223
typedef atomic_t atomic_val_t;
2324
typedef void *atomic_ptr_t;
2425
typedef atomic_ptr_t atomic_ptr_val_t;
@@ -76,7 +77,7 @@ typedef atomic_ptr_t atomic_ptr_val_t;
7677
*/
7778

7879
#define ATOMIC_BITS (sizeof(atomic_val_t) * 8)
79-
#define ATOMIC_MASK(bit) (1U << ((uint32_t)(bit) & (ATOMIC_BITS - 1U)))
80+
#define ATOMIC_MASK(bit) BIT((unsigned long)(bit) & (ATOMIC_BITS - 1U))
8081
#define ATOMIC_ELEM(addr, bit) ((addr) + ((bit) / ATOMIC_BITS))
8182

8283
/**

0 commit comments

Comments
 (0)