all repos — mgba @ 51c3fca3bf79d1c4d200fcb1fd48d24dc03e5d7a

mGBA Game Boy Advance Emulator

include/mgba-util/threading.h (view raw)

  1/* Copyright (c) 2013-2015 Jeffrey Pfau
  2 *
  3 * This Source Code Form is subject to the terms of the Mozilla Public
  4 * License, v. 2.0. If a copy of the MPL was not distributed with this
  5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  6#ifndef THREADING_H
  7#define THREADING_H
  8
  9#include <mgba-util/common.h>
 10
 11CXX_GUARD_START
 12
 13#ifndef DISABLE_THREADING
 14#if __STDC_VERSION__ >= 201112L
 15#define ThreadLocal _Thread_local void*
 16#define ThreadLocalInitKey(X)
 17#define ThreadLocalSetKey(K, V) K = V
 18#define ThreadLocalGetValue(K) K
 19#endif
 20#ifdef USE_PTHREADS
 21#include <mgba-util/platform/posix/threading.h>
 22#elif defined(_WIN32)
 23#include <mgba-util/platform/windows/threading.h>
 24#elif defined(PSP2)
 25#include <mgba-util/platform/psp2/threading.h>
 26#elif defined(_3DS)
 27#include <mgba-util/platform/3ds/threading.h>
 28#elif defined(__SWITCH__)
 29#include <mgba-util/platform/switch/threading.h>
 30#else
 31#define DISABLE_THREADING
 32#endif
 33#endif
 34#ifdef DISABLE_THREADING
 35#ifdef _3DS
 36// ctrulib already has a type called Thread
 37#include <3ds/thread.h>
 38#elif defined(__SWITCH__)
 39#include <switch/kernel/thread.h>
 40#else
 41typedef void* Thread;
 42#endif
 43#ifdef __SWITCH__
 44#include <switch/kernel/mutex.h>
 45#else
 46typedef void* Mutex;
 47#endif
 48typedef void* Condition;
 49typedef int ThreadLocal;
 50
 51static inline int MutexInit(Mutex* mutex) {
 52	UNUSED(mutex);
 53	return 0;
 54}
 55
 56static inline int MutexDeinit(Mutex* mutex) {
 57	UNUSED(mutex);
 58	return 0;
 59}
 60
 61static inline int MutexLock(Mutex* mutex) {
 62	UNUSED(mutex);
 63	return 0;
 64}
 65
 66static inline int MutexTryLock(Mutex* mutex) {
 67	UNUSED(mutex);
 68	return 0;
 69}
 70
 71static inline int MutexUnlock(Mutex* mutex) {
 72	UNUSED(mutex);
 73	return 0;
 74}
 75
 76static inline int ConditionInit(Condition* cond) {
 77	UNUSED(cond);
 78	return 0;
 79}
 80
 81static inline int ConditionDeinit(Condition* cond) {
 82	UNUSED(cond);
 83	return 0;
 84}
 85
 86static inline int ConditionWait(Condition* cond, Mutex* mutex) {
 87	UNUSED(cond);
 88	UNUSED(mutex);
 89	return 0;
 90}
 91
 92static inline int ConditionWaitTimed(Condition* cond, Mutex* mutex, int32_t timeoutMs) {
 93	UNUSED(cond);
 94	UNUSED(mutex);
 95	UNUSED(timeoutMs);
 96	return 0;
 97}
 98
 99static inline int ConditionWake(Condition* cond) {
100	UNUSED(cond);
101	return 0;
102}
103
104static inline void ThreadLocalInitKey(ThreadLocal* key) {
105	UNUSED(key);
106}
107
108static inline void ThreadLocalSetKey(ThreadLocal key, void* value) {
109	UNUSED(key);
110	UNUSED(value);
111}
112
113static inline void* ThreadLocalGetValue(ThreadLocal key) {
114	UNUSED(key);
115	return NULL;
116}
117#endif
118
119CXX_GUARD_END
120
121#endif