-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nicolas Laurent
committed
Nov 23, 2024
1 parent
6b23d8b
commit 18bd181
Showing
8 changed files
with
164 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#include <stdarg.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#include "thread.h" | ||
|
||
|
||
thread_t thread_new(thread_function_t function, void *data) { | ||
#ifdef WIN32 | ||
HANDLE thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)function, data, 0, NULL); /* Thread should be create _after_ mutexes */ | ||
SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); | ||
SetThreadPriority(fmu->thread, THREAD_PRIORITY_HIGHEST); | ||
SetThreadPriority(fmu->thread, THREAD_PRIORITY_TIME_CRITICAL); /* Try RT ! */ | ||
#else | ||
pthread_t thread; | ||
pthread_create(&thread, NULL, (void *(*)(void*))function, data); | ||
#endif | ||
return thread; | ||
} | ||
|
||
|
||
mutex_t thread_mutex_new(void) { | ||
#ifdef WIN32 | ||
return CreateEventA(NULL, FALSE, FALSE, NULL); | ||
#else | ||
pthread_mutex_t mutex; | ||
pthread_mutex_init(&mutex, NULL); | ||
return mutex; | ||
#endif | ||
} | ||
|
||
|
||
void thread_mutex_free(mutex_t *mutex) { | ||
#ifdef WIN32 | ||
CloseHandle(*mutex); | ||
#else | ||
pthread_mutex_destroy(mutex); | ||
#endif | ||
|
||
return; | ||
} | ||
|
||
|
||
void thread_mutex_lock(mutex_t *mutex) { | ||
#ifdef WIN32 | ||
WaitForSingleObject(*mutex, INFINITE); | ||
#else | ||
pthread_mutex_lock(mutex); | ||
#endif | ||
|
||
return; | ||
} | ||
|
||
|
||
void thread_mutex_unlock(mutex_t *mutex) { | ||
#ifdef WIN32 | ||
SetEvent(*mutex); | ||
#else | ||
pthread_mutex_unlock(mutex); | ||
#endif | ||
|
||
return; | ||
} |
Oops, something went wrong.