Skip to content
Snippets Groups Projects
Commit 001c818b authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Added an atomic max for chars

parent 64a8d3a3
Branches
Tags
1 merge request!1048Atomic gravity and time-step limiter
...@@ -121,6 +121,27 @@ __attribute__((always_inline)) INLINE static void atomic_min_d( ...@@ -121,6 +121,27 @@ __attribute__((always_inline)) INLINE static void atomic_min_d(
} while (test_val.as_long_long != old_val.as_long_long); } 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. * @brief Atomic max operation on floats.
* *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment