Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GHI #35 Add std implementation #36

Merged
merged 54 commits into from
Nov 13, 2024
Merged
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
b669bf9
GHI #35 Add config check for alignof function
doodspav Oct 29, 2024
ba7901d
GHI #35 Implement stdalign.h/c
doodspav Oct 29, 2024
e09f478
GHI #35 Add config checks for restrict keyword
doodspav Oct 29, 2024
30592ab
GHI #35 Add restrict.h macro
doodspav Oct 29, 2024
86b17da
GHI #35 Add string.h/c in stdlib (just memcpy for now)
doodspav Oct 29, 2024
473947c
GHI #35 Minor qualifier/comment fixes
doodspav Oct 29, 2024
397d113
GHI #35 Set up the base for wrapped
doodspav Oct 29, 2024
b69b308
GHI #35 Minor comment fix
doodspav Oct 29, 2024
76fe688
GHI #35 Check to make sure commit signing works
doodspav Oct 29, 2024
8edabbf
GHI #35 It works. Undo last change
doodspav Oct 29, 2024
7cefb21
GHI #35 Add empty std impl
doodspav Oct 29, 2024
7c9ec6b
GHI #35 Rename opts to options
doodspav Oct 29, 2024
d8d85ae
GHI #35 Implement fallback for std
doodspav Oct 29, 2024
3d6970b
GHI #35 Add static_assert
doodspav Oct 29, 2024
ab7035f
GHI #35 Add wrapped macros for direct load and store
doodspav Oct 30, 2024
485ead4
GHI #35 Add wrapped macro for direct explicit
doodspav Oct 30, 2024
a9ffbfc
GHI #35 Add wrapped macro for direct cmpxchg
doodspav Oct 30, 2024
8246dce
GHI #35 Add wrapped macro for direct bit test/modify
doodspav Oct 30, 2024
9d7e447
GHI #35 Add wrapped macro for direct fetch
doodspav Oct 30, 2024
206386a
GHI #35 Add wrapped macro for direct fetch noarg
doodspav Oct 30, 2024
6adbcb0
GHI #35 Add wrapped macro for direct void
doodspav Oct 30, 2024
7dbc939
GHI #35 Add wrapped macro for direct void noarg
doodspav Oct 30, 2024
7190620
GHI #35 Add config check for <stdatomic.h>
doodspav Oct 30, 2024
feffb5e
GHI #35 Add config check for _Atomic
doodspav Oct 30, 2024
d1276bb
GHI #35 Fix direct macro names
doodspav Oct 30, 2024
766aeab
GHI #35 Add comment
doodspav Oct 30, 2024
243ff72
GHI #35 Add type param to all do_ macros in direct
doodspav Oct 30, 2024
d8fccc8
GHI #35 Define all direct ops in std impl
doodspav Oct 30, 2024
a8f032e
GHI #35 Define create functions for std impl and fix some mistakes
doodspav Oct 30, 2024
4e7e9cf
GHI #35 Implement all direct functionality for std impl
doodspav Oct 30, 2024
3694227
GHI #35 Flip rank order in std impl
doodspav Oct 30, 2024
b060e85
GHI #35 Remove scratch and temp
doodspav Oct 30, 2024
598a6bd
GHI #35 Improve direct docs
doodspav Oct 30, 2024
65f9452
GHI #35 Add cmpxchg wrapped with store
doodspav Oct 30, 2024
a70391f
GHI #35 Add exchange to cmpxchg wrapped
doodspav Oct 30, 2024
80a7eb6
GHI #35 Add cmpxchg_strong to cmpxchg wrapped
doodspav Oct 31, 2024
c5cf0eb
GHI #35 Minor tidying up
doodspav Oct 31, 2024
5cc96d4
GHI #35 Add bit-test-modify to wrapped cmpxchg
doodspav Oct 31, 2024
2d416d4
GHI #35 Add bit-test-modify ops to std impl (using cmpxchg)
doodspav Oct 31, 2024
047a5ba
GHI #35 Add define fetch ops to wrapped cmpxchg
doodspav Oct 31, 2024
2383b51
GHI #35 Add define fetch noarg ops to wrapped cmpxchg
doodspav Oct 31, 2024
c6ee31a
GHI #35 Add define void ops to wrapped cmpxchg
doodspav Oct 31, 2024
890090f
GHI #35 Add define void noarg ops to wrapped cmpxchg
doodspav Oct 31, 2024
674e6a9
GHI #35 Add binary not to std impl
doodspav Oct 31, 2024
9f2856d
GHI #35 Add missing paren to assert
doodspav Oct 31, 2024
9d377e2
GHI #35 Add arithmetic neg to std impl
doodspav Oct 31, 2024
7374624
GHI #35 Add -Wno-unused-local-typedef and /wd4668
doodspav Oct 31, 2024
d562c57
GHI #35 Add -Wno-unused-local-typedef to ansi flags
doodspav Oct 31, 2024
f4352bf
GHI #35 Improve COMPILER_HAS_ATOMIC check
doodspav Oct 31, 2024
2a5301a
GHI #35 Improve COMPILER_HAS_ATOMIC check further
doodspav Oct 31, 2024
d317f8f
GHI #35 Remove align from transaction (unnecessary)
doodspav Nov 1, 2024
03bc69f
GHI #35 Fix defines if stdatomic is supported but nothing is lock free
doodspav Nov 11, 2024
f84fa77
GHI #35 Update comment [[skip ci]]
doodspav Nov 11, 2024
bc39986
GHI #35 Disable CI jobs to build, test, and cover code
doodspav Nov 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
GHI #35 Add define fetch noarg ops to wrapped cmpxchg
doodspav committed Oct 31, 2024
commit 2383b51d28de8f7ce41e75975c5cede406f76278
125 changes: 125 additions & 0 deletions src/include/patomic/wrapped/cmpxchg.h
Original file line number Diff line number Diff line change
@@ -648,4 +648,129 @@
}


/**
* @addtogroup wrapped.cmpxchg
*
* @brief
* Defines a function which implements an atomic noarg fetch operation using
* cmpxchg_weak as the underlying atomic operation.
*
* @details
* The defined function's signature will match either
* patomic_opsig_fetch_noarg_t or patomic_opsig_explicit_fetch_noarg_t
* (depending on the value of 'vis_p').
*
* @param atomic_type
* The type of the object on which the atomic operation is to be performed.
* Must not be a VLA or an array of unknown size.
*
* @param type
* The non-atomic counterpart of 'atomic_type'. This must have the same size
* as 'atomic_type' and must not have a stricter alignment.
*
* @param fn_name
* The name of the function to be defined.
*
* @param vis_p
* Either the macro 'SHOW_P' if the function should be defined as taking a
* memory order parameter (a.k.a. explicit), or the macro 'HIDE_P' if it
* should not (a.k.a. implicit).
*
* @param order
* The literal token 'order' if 'vis_p' is 'SHOW_P', otherwise the desired
* memory order to be used implicitly by the atomic operation.
*
* @param do_atomic_cmpxchg_weak_explicit
* A macro, M, callable as 'M(type, obj, exp, des, succ, fail, ok);' in block
* scope.
*
* The arguments provided are:
* - 'type' : forwarded directly from the 'type' argument in this macro
* - 'obj' : an expression of type 'volatile atomic_type *'
* - 'exp' : the name of an identifier designating an object of type 'type'
* - 'des' : the name of an identifier designating an object of type 'type'
* - 'succ' : an expression of type 'int' whose value is a valid memory order
* - 'fail' : an expression of type 'int' whose value is a valid load memory
* order not stronger than 'succ'
* - 'ok' : the name of an identifier designating an object of type 'int'
*
* The expected behaviour of calling the macro M as above is:
* - the values of 'exp' and 'des' are read
* - in a single atomic operation, the value of the object pointed to by
* 'obj' is read and, if it compares equal to the value of 'exp', the
* value of 'des' is written to the object pointed to by 'obj'
* - the value read from 'obj' is stored in 'exp'
* - 'ok' is set to non-zero if the value of 'des' was written to the object
* pointed to by 'obj' (success), otherwise it is set to zero (failure)
* - the atomic operation uses a memory ordering at least as strong as 'succ'
* for a successful exchange, and a load memory ordering at least as strong
* as 'fail' for a failed exchange
*
* @param do_make_desired
* A macro, D, callable as 'D(type, exp, des);' in block scope.
*
* The arguments provided are:
* - 'type' : forwarded directly from the 'type' argument in this macro
* - 'exp' : the name of an identifier designating an object of type 'type'
* - 'des' : the name of an identifier designating an object of type 'type'
*
* The expected behaviour of calling the macro D as above is:
* - 'des' should be set to the value of 'exp' after the desired modify
* operation is applied
* - 'exp' and should not be modified
*/
#define PATOMIC_WRAPPED_CMPXCHG_DEFINE_OP_FETCH_NOARG( \
atomic_type, type, fn_name, vis_p, order, \
do_atomic_cmpxchg_weak_explicit, \
do_make_desired \
) \
static void \
fn_name( \
volatile void *const obj \
vis_p(_,const int order) \
,void *const ret \
) \
{ \
/* static assertions */ \
PATOMIC_STATIC_ASSERT( \
sizeof_type_eq_atype, sizeof(type) == sizeof(atomic_type)); \
\
/* declarations */ \
type exp = {0}; \
type des; \
int ok; \
const int succ = (int) order; \
const int fail = PATOMIC_CMPXCHG_FAIL_ORDER(succ); \
\
/* assertions */ \
PATOMIC_WRAPPED_DO_ASSERT(obj != NULL); \
PATOMIC_WRAPPED_DO_ASSERT(ret != NULL); \
PATOMIC_WRAPPED_DO_ASSERT_ALIGNED(obj, atomic_type); \
PATOMIC_WRAPPED_DO_ASSERT(PATOMIC_IS_VALID_ORDER((int) order)); \
\
/* operation */ \
do { \
/* make the desired value from the expected value */ \
do_make_desired( \
type, \
exp, \
des \
); \
\
/* cmpxchg_weak */ \
do_atomic_cmpxchg_weak_explicit( \
type, \
(volatile atomic_type *) obj, \
exp, des, \
succ, fail, \
ok \
); \
} \
while (!ok); \
\
/* outputs */ \
PATOMIC_WRAPPED_DO_MEMCPY(ret, &exp, sizeof(type)); \
}


#endif /* PATOMIC_WRAPPED_CMPXCHG_H */