#define TEST_ATOMIC_TYPE(ATOMIC_TYPE, BASE_TYPE) \
{ \
ATOMIC_TYPE x = ATOMIC_VAR_INIT(1); \
- BASE_TYPE value; \
+ BASE_TYPE value, orig; \
\
atomic_read(&x, &value); \
ovs_assert(value == 1); \
atomic_init(&x, 3); \
atomic_read(&x, &value); \
ovs_assert(value == 3); \
+ \
+ atomic_add(&x, 1, &orig); \
+ ovs_assert(orig == 3); \
+ atomic_read(&x, &value); \
+ ovs_assert(value == 4); \
+ \
+ atomic_sub(&x, 2, &orig); \
+ ovs_assert(orig == 4); \
+ atomic_read(&x, &value); \
+ ovs_assert(value == 2); \
+ \
+ atomic_or(&x, 6, &orig); \
+ ovs_assert(orig == 2); \
+ atomic_read(&x, &value); \
+ ovs_assert(value == 6); \
+ \
+ atomic_and(&x, 10, &orig); \
+ ovs_assert(orig == 6); \
+ atomic_read(&x, &value); \
+ ovs_assert(value == 2); \
+ \
+ atomic_xor(&x, 10, &orig); \
+ ovs_assert(orig == 2); \
+ atomic_read(&x, &value); \
+ ovs_assert(value == 8); \
}
+static void
+test_atomic_flag(void)
+{
+ atomic_flag flag = ATOMIC_FLAG_INIT;
+ ovs_assert(atomic_flag_test_and_set(&flag) == false);
+ ovs_assert(atomic_flag_test_and_set(&flag) == true);
+ atomic_flag_clear(&flag);
+ ovs_assert(atomic_flag_test_and_set(&flag) == false);
+}
+
int
main(void)
{
TEST_ATOMIC_TYPE(atomic_uint64_t, uint64_t);
TEST_ATOMIC_TYPE(atomic_int64_t, int64_t);
+ test_atomic_flag();
+
return 0;
}