all repos — mgba @ 1f2bd30b14a9b957951397571ccb237c6df02ed6

mGBA Game Boy Advance Emulator

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

 1/* Copyright (c) 2013-2018 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 SWITCH_THREADING_H
 7#define SWITCH_THREADING_H
 8
 9#include <mgba-util/common.h>
10
11#include <switch.h>
12
13#define THREAD_ENTRY void
14typedef ThreadFunc ThreadEntry;
15typedef CondVar Condition;
16
17static inline int MutexInit(Mutex* mutex) {
18	mutexInit(mutex);
19	return 0;
20}
21
22static inline int MutexDeinit(Mutex* mutex) {
23	UNUSED(mutex);
24	return 0;
25}
26
27static inline int MutexLock(Mutex* mutex) {
28	mutexLock(mutex);
29	return 0;
30}
31
32static inline int MutexTryLock(Mutex* mutex) {
33	return mutexTryLock(mutex);
34}
35
36static inline int MutexUnlock(Mutex* mutex) {
37	mutexUnlock(mutex);
38	return 0;
39}
40
41static inline int ConditionInit(Condition* cond) {
42	condvarInit(cond);
43	return 0;
44}
45
46static inline int ConditionDeinit(Condition* cond) {
47	UNUSED(cond);
48	return 0;
49}
50
51static inline int ConditionWait(Condition* cond, Mutex* mutex) {
52	return condvarWait(cond, mutex);
53}
54
55static inline int ConditionWaitTimed(Condition* cond, Mutex* mutex, int32_t timeoutMs) {
56	return condvarWaitTimeout(cond, mutex, timeoutMs * 1000000LL);
57}
58
59static inline int ConditionWake(Condition* cond) {
60	return condvarWakeOne(cond);
61}
62
63static inline int ThreadCreate(Thread* thread, ThreadEntry entry, void* context) {
64	if (!entry || !thread) {
65		return 1;
66	}
67	int res = threadCreate(thread, entry, context, 0x8000, 0x3B, 1);
68	if(R_FAILED(res)) {
69		return res;
70	}
71	return threadStart(thread);
72}
73
74static inline int ThreadJoin(Thread* thread) {
75	int res = threadWaitForExit(thread);
76	if(R_FAILED(res)) {
77		return res;
78	}
79	return threadClose(thread);
80}
81
82static inline void ThreadSetName(const char* name) {
83	UNUSED(name);
84	// Unimplemented
85}
86
87#endif