Add posibility for user to select Thread backend directly
This commit is contained in:
1 parent
4aa93325e9
commit
6743cb9456
2 files changed
+21
-9
No files matched your search
@@ -6040,9 +6040,12 @@ If the C11 implementation does not respect the C standard
|
|||||||
(i.e. the compiler targets C11 mode
|
(i.e. the compiler targets C11 mode
|
||||||
the \_\_STDC\_NO\_THREADS\_\_ macro is not defined
|
the \_\_STDC\_NO\_THREADS\_\_ macro is not defined
|
||||||
but the header threads.h is not available or not working),
|
but the header threads.h is not available or not working),
|
||||||
then the user shall define manually the M\_USE\_C11\_NO\_THREADS
|
then the user shall define manually the M\_USE\_THREAD\_BACKEND
|
||||||
macro before including any M\*LIB header to disable it, so that
|
macro to select the back end to use:
|
||||||
M\*LIB can select another implementation.
|
|
||||||
|
* 1: for C11
|
||||||
|
* 2: for WINDOWS
|
||||||
|
* 3: for PTHREAD
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
|
|||||||
@@ -25,11 +25,21 @@
|
|||||||
#ifndef MSTARLIB_MUTEX_H
|
#ifndef MSTARLIB_MUTEX_H
|
||||||
#define MSTARLIB_MUTEX_H
|
#define MSTARLIB_MUTEX_H
|
||||||
|
|
||||||
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L \
|
/* Auto-detect the thread backend to use if the user has not override it */
|
||||||
&& !defined(__STDC_NO_THREADS__) \
|
#ifndef M_USE_THREAD_BACKEND
|
||||||
&& !defined(M_USE_C11_NO_THREADS)
|
# if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L \
|
||||||
|
&& !defined(__STDC_NO_THREADS__)
|
||||||
|
# define M_USE_THREAD_BACKEND 1
|
||||||
|
# elif defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__)
|
||||||
|
# define M_USE_THREAD_BACKEND 2
|
||||||
|
# else
|
||||||
|
# define M_USE_THREAD_BACKEND 3
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/****************************** C11 version ********************************/
|
/****************************** C11 version ********************************/
|
||||||
|
#if M_USE_THREAD_BACKEND == 1
|
||||||
|
|
||||||
#include <threads.h>
|
#include <threads.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@@ -159,10 +169,9 @@ static inline void m_oncei_call(m_oncei_t o, void (*func)(void))
|
|||||||
|
|
||||||
M_END_PROTECTED_CODE
|
M_END_PROTECTED_CODE
|
||||||
|
|
||||||
// MSYS2 doesn't define _WIN32 by default but __CYGWIN__
|
|
||||||
#elif defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__)
|
|
||||||
|
|
||||||
/****************************** WIN32 version ******************************/
|
/****************************** WIN32 version ******************************/
|
||||||
|
#elif M_USE_THREAD_BACKEND == 2
|
||||||
|
|
||||||
/* CLANG provides some useless and wrong warnings:
|
/* CLANG provides some useless and wrong warnings:
|
||||||
* - _WIN32_WINNT starts with '_' which is reserved by the standard
|
* - _WIN32_WINNT starts with '_' which is reserved by the standard
|
||||||
@@ -333,9 +342,9 @@ static inline void m_oncei_call(m_oncei_t o, void (*func)(void))
|
|||||||
|
|
||||||
M_END_PROTECTED_CODE
|
M_END_PROTECTED_CODE
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
/**************************** PTHREAD version ******************************/
|
/**************************** PTHREAD version ******************************/
|
||||||
|
#else
|
||||||
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#ifdef _POSIX_PRIORITY_SCHEDULING
|
#ifdef _POSIX_PRIORITY_SCHEDULING
|
||||||
|
|||||||
Reference in new issue
Block a user