-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bb62d45
commit ac5e737
Showing
3 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#ifndef ALLOCX_ASSERTIONS_H | ||
#define ALLOCX_ASSERTIONS_H | ||
|
||
#include <assert.h> | ||
#include <stdio.h> | ||
|
||
#define ALLOCX_ASSERT(condition, message) \ | ||
do { \ | ||
if (!(condition)) { \ | ||
fprintf(stderr, "Assertion failed: %s\n", message); \ | ||
assert(condition); \ | ||
} \ | ||
} while (0) | ||
|
||
#endif // ALLOCX_ASSERTIONS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#ifndef ALLOCX_ATOMIC_H | ||
#define ALLOCX_ATOMIC_H | ||
|
||
#include <stdatomic.h> | ||
|
||
// Memory order macros | ||
#define ALLOCX_MEMORY_ORDER_RELAXED memory_order_relaxed | ||
#define ALLOCX_MEMORY_ORDER_ACQUIRE memory_order_acquire | ||
#define ALLOCX_MEMORY_ORDER_RELEASE memory_order_release | ||
#define ALLOCX_MEMORY_ORDER_SEQ_CST memory_order_seq_cst | ||
|
||
// Memory Barrier Macro | ||
#define ALLOCX_MEMORY_BARRIER() __sync_synchronize() | ||
|
||
// Atomic Operations | ||
#define ALLOCX_ACQUIRE(ptr) __atomic_load_n(ptr, __ATOMIC_ACQUIRE) | ||
#define ALLOCX_RELEASE(ptr, value) __atomic_store_n(ptr, value, __ATOMIC_RELEASE) | ||
#define ALLOCX_RELAXED(ptr) __atomic_load_n(ptr, __ATOMIC_RELAXED) | ||
#define ALLOCX_SEQ_CST(ptr, value) __atomic_store_n(ptr, value, __ATOMIC_SEQ_CST) | ||
#define ALLOCX_ATOMIC_EXCHANGE(ptr, new_value) __atomic_exchange_n(ptr, new_value, __ATOMIC_SEQ_CST) | ||
#define ALLOCX_CAS(ptr, expected, desired) __atomic_compare_exchange_n( \ | ||
ptr, &expected, desired, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) | ||
|
||
// Atomic Operations for Lock-Free | ||
#define ALLOCX_FETCH_ADD(ptr, value) __atomic_fetch_add(ptr, value, __ATOMIC_SEQ_CST) | ||
#define ALLOCX_FETCH_SUB(ptr, value) __atomic_fetch_sub(ptr, value, __ATOMIC_SEQ_CST) | ||
#define ALLOCX_FETCH_AND(ptr, value) __atomic_fetch_and(ptr, value, __ATOMIC_SEQ_CST) | ||
#define ALLOCX_FETCH_OR(ptr, value) __atomic_fetch_or(ptr, value, __ATOMIC_SEQ_CST) | ||
|
||
#endif // ALLOCX_ATOMIC_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#ifndef ALLOCX_ERRORS_H | ||
#define ALLOCX_ERRORS_H | ||
|
||
typedef enum { | ||
ALLOCX_SUCCESS = 0, | ||
ALLOCX_ERROR_OUT_OF_MEMORY, | ||
ALLOCX_ERROR_INVALID_ARGUMENT, | ||
ALLOCX_ERROR_ALIGNMENT, | ||
ALLOCX_ERROR_OVERFLOW, | ||
ALLOCX_ERROR_UNKNOWN | ||
} allocx_error_t; | ||
|
||
#endif // ALLOCX_ERRORS_H |