Commit Graph

13 Commits

Author SHA1 Message Date
Robert Manner
6dc36f99c0 heimbase-atomics.h: replace heim_base_atomic_barrier with syntax valid noop
in case there is no implementation available.
2023-02-06 18:17:48 -06:00
Nicolas Williams
efdd6c589d base: Fix fallback atomics 2023-01-11 12:59:12 -06:00
Nicolas Williams
08c48c10c8 base: Add atomic CAS macros/functions 2023-01-10 23:28:33 -06:00
Luke Howard
8c25c0d46a base: support for 64-bit atomic increment/decrement 2023-01-07 21:45:01 +11:00
Luke Howard
8fcf05ac2e base: wrap __machine_rw_barrier() in function for Solaris
__machine_rw_barrier() assembly expansion cannot be treated as a function call
(as it is later in the heim_base_atomic_store() macro definition)
2023-01-07 21:33:43 +11:00
Stefan Metzmacher
dc3ac8592b heimbase-atomics: let heim_base_atomic_* use 'long' instead of 'int' on AIX
As the atomics are signed on AIX, we better try to use the largest
possible max value.

The 'int' API uses 32-bit values for both 32-bit and 64-bit binaries:

  typedef int *atomic_p;

  int fetch_and_add(atomic_p addr, int value);

The 'long' API uses 32-bit values for 32-bit binaries and 64-bit values
for 64-bit binaries:

  typedef long *atomic_l;

  long fetch_and_addlp(atomic_l addr, long value);

So we better use the 'long' API in order to avoid any potential
problems with the heim_base_atomic_integer_max magic value, where
INT[32]_MAX would be a little bit low compared to 64-bit pointer space.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
2022-12-22 22:12:52 +11:00
Stefan Metzmacher
1e5cb64569 heimbase-atomics: fix heim_base_atomic_* on AIX
The API looks like this on AIX:

  typedef int *atomic_p;

  int fetch_and_add(atomic_p addr, int value);

The strange thing is that the xlc compiler ignores missing arguments by
default. (It warns but doesn't fail to compile)
As a result the value argument was just uninitialized memory,
which means that the ref_cnt variable of struct heim_base,
gets unpredictable values during heim_retain() and heim_release(),
resulting in memory leaks.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
2022-12-22 22:12:52 +11:00
Nicolas Williams
e2e7eacb6f base: Do not include config.h twice 2022-12-15 17:44:41 -06:00
Luke Howard
4986ebcb67 base: rename heim_base_atomic_{max,type} to ...integer_{max,type}
Rename heim_base_atomic_max to heim_base_atomic_integer_max (ditto with _type)
in order to better reflect their usage, now we have a separate
heim_base_atomic() macro for making an atomic version of any type.
2020-07-14 09:35:14 +10:00
Luke Howard
9ba00949dd base: add atomic init, load and store macros
Add new macros for atomic initialization, load and store, with ordering
semantics equivalent to <stdatomic.h>
2020-07-14 09:35:14 +10:00
Luke Howard
cbb2ceb018 base: use <stdatomic.h> for atomics, where present
C11 introduces a new set of atomic APIs in <stdatomic.h>. If available, use
those in preference to compiler- or platform-specific intrinsics.
2020-07-14 09:35:14 +10:00
Luke Howard
932605c01e base: heim_base_exchange_{32,64} for platforms without atomics
heim_base_exchange_32() and heim_base_exchange_64() inline functions for
platforms without atomics were missing (these are very inefficient but,
clearly rarely used given the lack of build error reports)
2020-07-14 09:35:14 +10:00
Luke Howard
fcfca367cf base: move atomic macros into separate header
Move the atomic macros into a distinct header, heimbase-atomics.h, in
preparation for the introduction of additional macros
2020-07-14 09:35:14 +10:00