Add posibility for user to select Thread backend directly

This commit is contained in:
Patrick Pelissier committed 2020-07-02 00:09:54 +02:00
1 parent 4aa93325e9
commit 6743cb9456
2 files changed
+21 -9

No files matched your search

+6 -3
View File
@@ -6040,9 +6040,12 @@ If the C11 implementation does not respect the C standard
(i.e. the compiler targets C11 mode
the \_\_STDC\_NO\_THREADS\_\_ macro is not defined
but the header threads.h is not available or not working),
then the user shall define manually the M\_USE\_C11\_NO\_THREADS
macro before including any M\*LIB header to disable it, so that
M\*LIB can select another implementation.
then the user shall define manually the M\_USE\_THREAD\_BACKEND
macro to select the back end to use:
* 1: for C11
* 2: for WINDOWS
* 3: for PTHREAD
Example:
+15 -6
View File
@@ -25,11 +25,21 @@
#ifndef MSTARLIB_MUTEX_H
#define MSTARLIB_MUTEX_H
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L \
&& !defined(__STDC_NO_THREADS__) \
&& !defined(M_USE_C11_NO_THREADS)
/* Auto-detect the thread backend to use if the user has not override it */
#ifndef M_USE_THREAD_BACKEND
# 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 ********************************/
#if M_USE_THREAD_BACKEND == 1
#include <threads.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
// MSYS2 doesn't define _WIN32 by default but __CYGWIN__
#elif defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__)
/****************************** WIN32 version ******************************/
#elif M_USE_THREAD_BACKEND == 2
/* CLANG provides some useless and wrong warnings:
* - _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
#else
/**************************** PTHREAD version ******************************/
#else
#include <pthread.h>
#ifdef _POSIX_PRIORITY_SCHEDULING