CMAKE: Bring back checks for atomic CAS#595
Conversation
Testing for atomic_is_lock_free() may not be enough as it may not require `-latomic` that is otherwise needed for 128bit atomics. Signed-off-by: Joseph Schuchart <schuchart@icl.utk.edu>
| int32_t where = 0; | ||
| int32_t where = 0, expected = 0; | ||
| if( !atomic_compare_exchange_strong( (_Atomic __int32_t*)&where, &expected, 1 ) ) | ||
| return -1; |
There was a problem hiding this comment.
The original code returns 0 or 1. This patch makes it return 0 (success), 1 or -1. I guess 1 and -1 can be conflated to failure in both cases. POSIX specifies only that the 8 lower bits are meaningful (https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/functions/V2_chap02.html#tag_15_13), so -1 is not clear.
May I suggest we use EXIT_SUCCESS and EXIT_FAILURE for all return/exit values, since those are POSIX compliant?
There was a problem hiding this comment.
I thought about harmonizing them but then I realized that it might be helpful to have different return values for the two error cases. That way we can distinguish (in the CMake log) whether the operation is not lock-free or whether we failed to execute it in the first place...
There was a problem hiding this comment.
return 1 and 2 then, that's probably more clear than 1 and 254
|
In what case this is necessary ? On my tests when using the libatomic is necessary, the associated intrinsics are automatically made available, and |
|
I can only guess here based on @DSMishler issue: Either way, these checks don't hurt and may help if a weird compiler may need |
Testing for atomic_is_lock_free() may not be enough as it may not require
-latomicthat is otherwise needed for 128bit atomics.Reported by @DSMishler.