2015-06-18 08:00:35 +00:00
|
|
|
/* Copyright (c) 2013-2015 Jeffrey Pfau
|
2014-12-03 08:39:06 +00:00
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2014-01-16 07:46:47 +00:00
|
|
|
#ifndef THREADING_H
|
|
|
|
#define THREADING_H
|
|
|
|
|
2016-12-31 01:00:22 +00:00
|
|
|
#include <mgba-util/common.h>
|
2014-01-16 07:46:47 +00:00
|
|
|
|
2016-12-27 05:01:55 +00:00
|
|
|
CXX_GUARD_START
|
|
|
|
|
2015-06-04 03:37:45 +00:00
|
|
|
#ifndef DISABLE_THREADING
|
2014-01-16 07:46:47 +00:00
|
|
|
#ifdef USE_PTHREADS
|
2016-12-31 01:00:22 +00:00
|
|
|
#include <mgba-util/platform/posix/threading.h>
|
2018-09-14 01:12:32 +00:00
|
|
|
#elif defined(_WIN32)
|
2016-12-31 01:00:22 +00:00
|
|
|
#include <mgba-util/platform/windows/threading.h>
|
2018-09-14 01:12:32 +00:00
|
|
|
#elif defined(PSP2)
|
2016-12-31 01:00:22 +00:00
|
|
|
#include <mgba-util/platform/psp2/threading.h>
|
2022-02-15 04:41:44 +00:00
|
|
|
#elif defined(__3DS__)
|
2016-12-31 01:00:22 +00:00
|
|
|
#include <mgba-util/platform/3ds/threading.h>
|
2018-09-14 01:12:32 +00:00
|
|
|
#elif defined(__SWITCH__)
|
|
|
|
#include <mgba-util/platform/switch/threading.h>
|
2014-12-09 00:00:08 +00:00
|
|
|
#else
|
|
|
|
#define DISABLE_THREADING
|
2015-06-04 03:37:45 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
2022-08-08 20:05:32 +00:00
|
|
|
|
|
|
|
#ifndef DISABLE_THREADING
|
|
|
|
#if (__STDC_VERSION__ >= 201112L) && (__STDC_NO_THREADS__ != 1)
|
|
|
|
#define ThreadLocal _Thread_local void*
|
|
|
|
#define ThreadLocalInitKey(X)
|
|
|
|
#define ThreadLocalSetKey(K, V) K = V
|
|
|
|
#define ThreadLocalGetValue(K) K
|
|
|
|
#endif
|
|
|
|
#else
|
2022-02-15 04:41:44 +00:00
|
|
|
#ifdef __3DS__
|
2016-01-03 18:34:25 +00:00
|
|
|
// ctrulib already has a type called Thread
|
|
|
|
#include <3ds/thread.h>
|
2019-05-26 21:26:35 +00:00
|
|
|
#elif defined(__SWITCH__)
|
|
|
|
#include <switch/kernel/thread.h>
|
2016-01-03 18:34:25 +00:00
|
|
|
#else
|
2014-12-09 00:00:08 +00:00
|
|
|
typedef void* Thread;
|
2016-01-03 18:34:25 +00:00
|
|
|
#endif
|
2019-05-26 21:26:35 +00:00
|
|
|
#ifdef __SWITCH__
|
|
|
|
#include <switch/kernel/mutex.h>
|
|
|
|
#else
|
2014-12-09 00:00:08 +00:00
|
|
|
typedef void* Mutex;
|
2019-05-26 21:26:35 +00:00
|
|
|
#endif
|
2014-12-09 00:00:08 +00:00
|
|
|
typedef void* Condition;
|
2020-07-12 23:57:09 +00:00
|
|
|
typedef int ThreadLocal;
|
2014-12-09 02:49:05 +00:00
|
|
|
|
|
|
|
static inline int MutexInit(Mutex* mutex) {
|
|
|
|
UNUSED(mutex);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int MutexDeinit(Mutex* mutex) {
|
|
|
|
UNUSED(mutex);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int MutexLock(Mutex* mutex) {
|
|
|
|
UNUSED(mutex);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-13 06:50:09 +00:00
|
|
|
static inline int MutexTryLock(Mutex* mutex) {
|
|
|
|
UNUSED(mutex);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-12-09 02:49:05 +00:00
|
|
|
static inline int MutexUnlock(Mutex* mutex) {
|
|
|
|
UNUSED(mutex);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int ConditionInit(Condition* cond) {
|
|
|
|
UNUSED(cond);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int ConditionDeinit(Condition* cond) {
|
|
|
|
UNUSED(cond);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int ConditionWait(Condition* cond, Mutex* mutex) {
|
|
|
|
UNUSED(cond);
|
|
|
|
UNUSED(mutex);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-02-21 11:44:15 +00:00
|
|
|
static inline int ConditionWaitTimed(Condition* cond, Mutex* mutex, int32_t timeoutMs) {
|
|
|
|
UNUSED(cond);
|
|
|
|
UNUSED(mutex);
|
|
|
|
UNUSED(timeoutMs);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-12-09 02:49:05 +00:00
|
|
|
static inline int ConditionWake(Condition* cond) {
|
|
|
|
UNUSED(cond);
|
|
|
|
return 0;
|
|
|
|
}
|
2020-07-12 23:57:09 +00:00
|
|
|
|
|
|
|
static inline void ThreadLocalInitKey(ThreadLocal* key) {
|
|
|
|
UNUSED(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void ThreadLocalSetKey(ThreadLocal key, void* value) {
|
|
|
|
UNUSED(key);
|
|
|
|
UNUSED(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void* ThreadLocalGetValue(ThreadLocal key) {
|
|
|
|
UNUSED(key);
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-01-16 07:46:47 +00:00
|
|
|
#endif
|
|
|
|
|
2016-12-27 05:01:55 +00:00
|
|
|
CXX_GUARD_END
|
|
|
|
|
2014-01-16 07:46:47 +00:00
|
|
|
#endif
|