From 8c2f35bd1f18b62fff609f3a7d77d4e85b706916 Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Wed, 5 Feb 2020 18:58:55 +0100 Subject: refactor --- src/windows/thread.c | 102 --------------------------------------------------- 1 file changed, 102 deletions(-) delete mode 100644 src/windows/thread.c (limited to 'src/windows/thread.c') diff --git a/src/windows/thread.c b/src/windows/thread.c deleted file mode 100644 index 9669158..0000000 --- a/src/windows/thread.c +++ /dev/null @@ -1,102 +0,0 @@ -/* -* BSD 2-Clause “Simplified” License -* Copyright (c) 2019, Aldrik Ramaekers, aldrik.ramaekers@protonmail.com -* All rights reserved. -*/ - -#include - -thread thread_start(void *(*start_routine) (void *), void *arg) -{ - thread result; - result.valid = false; - - result.thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)start_routine, - arg, 0, NULL); - result.valid = true; - - return result; -} - -void thread_join(thread *thread) -{ - if (thread->valid) - { - WaitForSingleObject(thread->thread, INFINITE); - CloseHandle(thread->thread); - } -} - -bool thread_tryjoin(thread *thread) -{ - if (thread->valid) - { - s32 result = WaitForSingleObject(thread->thread, 0); - return result == WAIT_OBJECT_0; - } - return false; -} - -void thread_detach(thread *thread) -{ - if (thread->valid) - { - CloseHandle(thread->thread); - } -} - -void thread_stop(thread *thread) -{ - if (thread->valid) - { - SuspendThread(thread->thread); - } -} - -u32 thread_get_id() -{ - return GetCurrentThreadId(); -} - -void thread_sleep(u64 microseconds) -{ - Sleep(microseconds/1000); -} - -mutex mutex_create() -{ - mutex result; - result.mutex = CreateMutex( - NULL, // default security attributes - FALSE, // initially not owned - NULL); // unnamed mutex - - return result; -} - -mutex mutex_create_recursive() -{ - return mutex_create(); -} - -void mutex_lock(mutex *mutex) -{ - WaitForSingleObject( - mutex->mutex, // handle to mutex - INFINITE); // no time-out interval -} - -bool mutex_trylock(mutex *mutex) -{ - return WaitForSingleObject(mutex->mutex, 1) == WAIT_OBJECT_0; -} - -void mutex_unlock(mutex *mutex) -{ - ReleaseMutex(mutex->mutex); -} - -void mutex_destroy(mutex *mutex) -{ - CloseHandle(mutex->mutex); -} -- cgit v1.2.3-70-g09d2