valkey icon indicating copy to clipboard operation
valkey copied to clipboard

Move to C11 and adopt _Atomic, static_asserts, and thread_local

Open madolson opened this issue 1 year ago • 3 comments

As per https://github.com/valkey-io/valkey/commit/445a4b669a3a7232a18bf23340c5f7d580aa92c7, we implemented custom logic to compile with C11 when atomics were available, and C99 when they were not available. However, with the EoL of CentOS 7, we believe that all default compilers should be able to compile with C99. This gives us access to three pieces of functionality we use:

  1. Static asserts, we have some custom code defined to support it but now we can standardize on the C11 functionality.
  2. native thread_local support. We can avoid _thread.
  3. Native atomics support, so we can remove our custom logic supporting atomics.

This change should target Valkey 8. We will continue to use the old gcc version on Valkey 7.2.

madolson avatar May 10 '24 02:05 madolson

@madolson Are we sticking to the default memory ordering for _Atomic operations (ex: incr, decr, ....) for C11 which is sequentially consistent memory ordering memory_order_seq_cst, or are we going with the one used for the custom logic which is relaxed (memory_order_relaxed).

See: https://en.cppreference.com/w/c/atomic/memory_order

adetunjii avatar May 11 '24 22:05 adetunjii

Historically we have predominantly used atomics for counters in other threads, which are fine with memory_order_relaxed and see better performance.

madolson avatar May 12 '24 17:05 madolson

@madolson please take a look at the PR to see if it's good, so I can finish up the remaining parts

adetunjii avatar May 12 '24 18:05 adetunjii