Timer fixes & tests added

This commit is contained in:
Ken Van Hoeylandt
2024-02-02 22:19:36 +01:00
committed by GitHub
parent 47377439dd
commit 4f89918e91
5 changed files with 168 additions and 43 deletions
+34
View File
@@ -0,0 +1,34 @@
#include "doctest.h"
#include "tactility_core.h"
#include "mutex.h"
static int thread_with_mutex_parameter(void* parameter) {
Mutex mutex = (Mutex)parameter;
tt_mutex_acquire(mutex, TtWaitForever);
return 0;
}
TEST_CASE("a mutex can block a thread") {
Mutex mutex = tt_mutex_alloc(MutexTypeNormal);
tt_mutex_acquire(mutex, TtWaitForever);
Thread* thread = tt_thread_alloc_ex(
"thread",
1024,
&thread_with_mutex_parameter,
mutex
);
tt_thread_start(thread);
tt_delay_ms(5);
CHECK_EQ(tt_thread_get_state(thread), ThreadStateRunning);
tt_mutex_release(mutex);
tt_delay_ms(5);
CHECK_EQ(tt_thread_get_state(thread), ThreadStateStopped);
tt_thread_join(thread);
tt_thread_free(thread);
tt_mutex_free(mutex);
}