mirror of
https://github.com/thunderbrewhq/bc.git
synced 2025-12-12 01:52:30 +00:00
feat(lock): add basic lock functions
This commit is contained in:
parent
3b5da1af9c
commit
e8d3709d31
8 changed files with 207 additions and 0 deletions
39
test/Lock.cpp
Normal file
39
test/Lock.cpp
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
#include "bc/Lock.hpp"
|
||||
#include "test/Test.hpp"
|
||||
|
||||
TEST_CASE("Blizzard::Lock::Atomic::Increment", "[lock]") {
|
||||
SECTION("increments -1") {
|
||||
int32_t value = -1;
|
||||
REQUIRE(Blizzard::Lock::Atomic::Increment(&value) == 0);
|
||||
}
|
||||
|
||||
SECTION("increments 0") {
|
||||
int32_t value = 0;
|
||||
REQUIRE(Blizzard::Lock::Atomic::Increment(&value) == 1);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Blizzard::Lock::MutexCreate", "[lock]") {
|
||||
SECTION("creates mutex") {
|
||||
Blizzard::Lock::Mutex mutex1;
|
||||
REQUIRE(Blizzard::Lock::MutexCreate(mutex1) == 0);
|
||||
|
||||
Blizzard::Lock::Mutex mutex2;
|
||||
REQUIRE(Blizzard::Lock::MutexCreate(mutex2) == 0);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Blizzard::Lock::MutexEnter", "[lock]") {
|
||||
SECTION("enters and leaves mutex") {
|
||||
Blizzard::Lock::Mutex mutex;
|
||||
Blizzard::Lock::MutexCreate(mutex);
|
||||
|
||||
int32_t mutexEntered = 0;
|
||||
|
||||
Blizzard::Lock::MutexEnter(mutex);
|
||||
mutexEntered = 1;
|
||||
Blizzard::Lock::MutexLeave(mutex);
|
||||
|
||||
REQUIRE(mutexEntered == 1);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue