forked from bkaradzic/bx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatomic_test.cpp
46 lines (35 loc) · 1.05 KB
/
atomic_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
* Copyright 2010-2023 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bx/blob/master/LICENSE
*/
#include "test.h"
#include <bx/cpu.h>
TEST_CASE("atomic", "")
{
uint32_t test = 1337;
uint32_t fetched;
fetched = bx::atomicFetchAndAdd(&test, 52u);
REQUIRE(fetched == 1337);
REQUIRE(test == 1389);
fetched = bx::atomicAddAndFetch(&test, 64u);
REQUIRE(fetched == 1453);
REQUIRE(test == 1453);
fetched = bx::atomicFetchAndSub(&test, 64u);
REQUIRE(fetched == 1453);
REQUIRE(test == 1389);
fetched = bx::atomicSubAndFetch(&test, 52u);
REQUIRE(fetched == 1337);
REQUIRE(test == 1337);
fetched = bx::atomicFetchAndAddsat(&test, 52u, 1453u);
REQUIRE(fetched == 1337);
REQUIRE(test == 1389);
fetched = bx::atomicFetchAndAddsat(&test, 1000u, 1453u);
REQUIRE(fetched == 1389);
REQUIRE(test == 1453);
fetched = bx::atomicFetchAndSubsat(&test, 64u, 1337u);
REQUIRE(fetched == 1453);
REQUIRE(test == 1389);
fetched = bx::atomicFetchAndSubsat(&test, 1000u, 1337u);
REQUIRE(fetched == 1389);
REQUIRE(test == 1337);
}