Skip to content

Commit

Permalink
GHI #32 Add memory_order.h header
Browse files Browse the repository at this point in the history
  • Loading branch information
doodspav committed Mar 6, 2024

Verified

This commit was signed with the committer’s verified signature. The key has expired.
doodspav doodspav
1 parent 46610a0 commit a1e5685
Showing 4 changed files with 119 additions and 2 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -41,6 +41,7 @@ target_sources(
# include/types
include/patomic/types/align.h
include/patomic/types/ids.h
include/patomic/types/memory_order.h
)

# add /src files to target
2 changes: 1 addition & 1 deletion include/patomic/types/align.h
Original file line number Diff line number Diff line change
@@ -161,7 +161,7 @@ patomic_align_meets_minimum(


#ifdef __cplusplus
};
} /* extern "C" */
#endif

#endif /* PATOMIC_ALIGN_H */
4 changes: 3 additions & 1 deletion include/patomic/types/ids.h
Original file line number Diff line number Diff line change
@@ -70,6 +70,7 @@ typedef unsigned long patomic_id_t;
*/

typedef enum {

/** @brief The implementation kind is unknown. */
patomic_kind_UNKN = 0x0

@@ -94,6 +95,7 @@ typedef enum {
patomic_kind_LIB |
patomic_kind_BLTN |
patomic_kind_ASM

} patomic_kind_t;


@@ -137,7 +139,7 @@ patomic_get_kind(


#ifdef __cplusplus
};
} /* extern "C" */
#endif

#endif /* PATOMIC_IDS_H */
114 changes: 114 additions & 0 deletions include/patomic/types/memory_order.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#ifndef PATOMIC_MEMORY_ORDER_H
#define PATOMIC_MEMORY_ORDER_H

#include <patomic/patomic_export.h>

#ifdef __cplusplus
extern "C" {
#endif


/**
* @addtogroup mem_order
*
* @brief
* Enum constants specifying how memory accesses are to be ordered around an
* atomic operation.
*
* @details
* Each enum label's value and semantics are identical to C++11's
* std::memory_order's values and semantics.
*
* @note
* Consume is only present for compatibility. It is not and will not be
* implemented, and will always be treated as patomic_ACQUIRE.
*/

typedef enum {
patomic_RELAXED,
patomic_CONSUME,
patomic_ACQUIRE,
patomic_RELEASE,
patomic_ACQ_REL,
patomic_SEQ_CST
} patomic_memory_order_t;


/**
* @addtogroup mem_order
*
* @brief
* Checks that order has a value corresponding to a label in
* patomic_memory_order_t.
*
* @returns If the check succeeds returns 1, else 0.
*/

PATOMIC_EXPORT int
patomic_is_valid_order(int order);


/**
* @addtogroup mem_order
*
* @brief
* Checks that order has a value corresponding to a label in
* patomic_memory_order_t, and is valid to use for an atomic store operation.
*
* @returns If the check succeeds returns 1, else 0.
*/

PATOMIC_EXPORT int
patomic_is_valid_store_order(int order);


/**
* @addtogroup mem_order
*
* @brief
* Checks that order has a value corresponding to a label in
* patomic_memory_order_t, and is valid to use for an atomic load operation.
*
* @returns If the check succeeds returns 1, else 0.
*/

PATOMIC_EXPORT int
patomic_is_valid_load_order(int order);


/**
* @addtogroup mem_order
*
* @brief
* Checks that both succ and fail have a value corresponding to a label in
* patomic_memory_order_t, and fail is not stronger than succ or equal to
* patomic_RELEASE or patomic_ACQ_REL.
*
* @returns If the check succeeds returns 1, else 0.
*/

PATOMIC_EXPORT int
patomic_is_valid_fail_order(int succ, int fail);


/**
* @addtogroup mem_order
*
* @brief
* Returns the strictest memory order that would satisfy the checks done by
* patomic_is_valid_fail_order(succ, <return>).
*
* @warning
* If an invalid memory order is passed to this function, it will be returned
* unmodified.
*/

PATOMIC_EXPORT int
patomic_cmpxchg_fail_order(int succ);


#ifdef __cplusplus
} /* extern "C" */
#endif

#endif /* PATOMIC_MEMORY_ORDER_H */

0 comments on commit a1e5685

Please sign in to comment.