Tactility/Tests/TactilityCore/MutexTest.cpp
Ken Van Hoeylandt 42e843b463
C++ conversions (#111)
* Remove version from artifact name
* Target C++ 20 and higher
* Use cpp string
* Better crash implementation
* String utils in cpp style
* Replace parameter methods with start() method
* MutexType to Mutex::Type
* Kernel c to cpp style
* Cleanup event flag
* More cpp conversions
* Test fixes
* Updated ideas docs
2024-12-07 12:24:28 +01:00

37 lines
798 B
C++

#include "doctest.h"
#include "TactilityCore.h"
#include "Mutex.h"
using namespace tt;
static int thread_with_mutex_parameter(void* parameter) {
auto* mutex = (Mutex*)parameter;
tt_mutex_acquire(mutex, TtWaitForever);
return 0;
}
TEST_CASE("a mutex can block a thread") {
auto* mutex = tt_mutex_alloc(Mutex::TypeNormal);
tt_mutex_acquire(mutex, TtWaitForever);
Thread* thread = new Thread(
"thread",
1024,
&thread_with_mutex_parameter,
mutex
);
thread->start();
kernel::delayMillis(5);
CHECK_EQ(thread->getState(), Thread::StateRunning);
tt_mutex_release(mutex);
kernel::delayMillis(5);
CHECK_EQ(thread->getState(), Thread::StateStopped);
thread->join();
delete thread;
tt_mutex_free(mutex);
}