Skip to content

gatomic: Add APIs to perform atomic int / pointer exchanges

Marco Trevisan requested to merge 3v1n0/glib:gatomic-exchange into main

Atomic APIs provide a way to exchange values only if we compare a value that is equal to the old value, but not to just exchange the value returning the old one.

However, compilers provide such built-in functions, so we can use them to expose such functionality to GLib.

The only drawback is that when using an old version of gcc not providing atomic APIs to swap values, we need to re-implement it with an implementation that may not be fully atomic, but that is safe enough.

However this codepath should really not be used currently as gcc introduced __atomic_exchange_n() at version 4.7.4, so 8 years ago.

Merge request reports