Commit 001c818b authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Added an atomic max for chars

parent 64a8d3a3
......@@ -121,6 +121,27 @@ __attribute__((always_inline)) INLINE static void atomic_min_d(
} while (test_val.as_long_long != old_val.as_long_long);
}
/**
* @brief Atomic max operation on chars.
*
* This is a text-book implementation based on an atomic CAS.
*
* @param address The address to update.
* @param y The value to update the address with.
*/
__attribute__((always_inline)) INLINE static void atomic_max_c(
volatile char *const address, const char y) {
char test_val, old_val, new_val;
old_val = *address;
do {
test_val = old_val;
new_val = max(old_val, y);
old_val = atomic_cas(address, test_val, new_val);
} while (test_val != old_val);
}
/**
* @brief Atomic max operation on floats.
*
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment