mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Added $$atomic_store and $$atomic_load.
This commit is contained in:
@@ -18,12 +18,42 @@ enum AtomicOrdering : int
|
||||
NOT_ATOMIC, // Not atomic
|
||||
UNORDERED, // No lock
|
||||
MONOTONIC, // Consistent ordering
|
||||
AQUIRE, // Barrier locking load/store
|
||||
ACQUIRE, // Barrier locking load/store
|
||||
RELEASE, // Barrier releasing load/store
|
||||
ACQUIRE_RELEASE, // Barrier fence to load/store
|
||||
SEQ_CONSISTENT, // Acquire semantics, ordered with other seq_consistent
|
||||
}
|
||||
|
||||
/**
|
||||
* @param [in] x "the variable or dereferenced pointer to load."
|
||||
* @param $ordering "atomic ordering of the load, defaults to SEQ_CONSISTENT"
|
||||
* @param $volatile "whether the load should be volatile, defaults to 'false'"
|
||||
* @return "returns the value of x"
|
||||
*
|
||||
* @require $ordering != AtomicOrdering.RELEASE "Release ordering is not valid for load."
|
||||
* @require $ordering != AtomicOrdering.ACQUIRE_RELEASE "Acquire release is not valid for load."
|
||||
* @require types::may_load_atomic($typeof(x)) "Only integer, float and pointers may be used."
|
||||
**/
|
||||
macro @atomic_load(&x, AtomicOrdering $ordering = SEQ_CONSISTENT, $volatile = false) @builtin
|
||||
{
|
||||
return $$atomic_load(&x, $volatile, (int)$ordering);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param [out] x "the variable or dereferenced pointer to store to."
|
||||
* @param value "the value to store."
|
||||
* @param $ordering "the atomic ordering of the store, defaults to SEQ_CONSISTENT"
|
||||
* @param $volatile "whether the store should be volatile, defaults to 'false'"
|
||||
*
|
||||
* @require $ordering != AtomicOrdering.ACQUIRE "Acquire ordering is not valid for store."
|
||||
* @require $ordering != AtomicOrdering.ACQUIRE_RELEASE "Acquire release is not valid for store."
|
||||
* @require types::may_load_atomic($typeof(x)) "Only integer, float and pointers may be used."
|
||||
**/
|
||||
macro void @atomic_store(&x, value, AtomicOrdering $ordering = SEQ_CONSISTENT, $volatile = false) @builtin
|
||||
{
|
||||
$$atomic_store(&x, value, $volatile, (int)$ordering);
|
||||
}
|
||||
|
||||
macro compare_exchange(ptr, compare, value, AtomicOrdering $success, AtomicOrdering $failure, bool $volatile = true, bool $weak = false, usz $alignment = 0)
|
||||
{
|
||||
return $$compare_exchange(ptr, compare, value, $volatile, $weak, $success.ordinal, $failure.ordinal, $alignment);
|
||||
|
||||
Reference in New Issue
Block a user