Repository navigation
Expand file tree
/
Copy pathCond.cpp
More file actions
95 lines (74 loc) · 3.35 KB
/
Copy pathCond.cpp
File metadata and controls
95 lines (74 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "prx/libkernel/Pthread/include/Pthread.hpp"
#include "prx/libkernel/Pthread/include/Cond.hpp"
#include "Common.hpp"
#include <cstdint>
#include <stdexcept>
namespace {
constexpr int POSIX_PROCESS_PRIVATE = 0;
int toPosix(int result) {
if (result == 0)
return 0;
const auto error = static_cast<std::uint32_t>(result);
if ((error & 0xffff0000u) != 0x80020000u)
throw std::runtime_error("Unexpected SCE condition variable error");
return static_cast<int>(error & 0xffffu);
}
}
extern "C" {
int APS5_VABI pthread_cond_destroy_nid_postfix(PthreadCond* cond) {
if (!cond) return PosixThread::GUEST_EINVAL;
return toPosix(scePthreadCondDestroy(cond));
}
int APS5_VABI pthread_cond_broadcast_nid_postfix(PthreadCond* cond) {
return toPosix(scePthreadCondBroadcast(cond));
}
int APS5_VABI pthread_cond_init_nid_postfix(PthreadCond* cond, const PthreadCondattr* attr) {
return toPosix(scePthreadCondInit(cond, attr, nullptr));
}
int APS5_VABI pthread_cond_signal_nid_postfix(PthreadCond* cond) {
return toPosix(scePthreadCondSignal(cond));
}
int APS5_VABI pthread_cond_timedwait_nid_postfix(PthreadCond* cond, PthreadMutex* mutex, const KernelTimespec* abstime) {
if (!abstime || abstime->tv_sec < 0 || abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000) return PosixThread::GUEST_EINVAL;
return toPosix(CondOperations::AbsoluteTimedwait(cond, mutex, abstime));
}
int APS5_VABI pthread_cond_reltimedwait_np_nid_postfix(PthreadCond* cond, PthreadMutex* mutex, KernelUseconds usec) {
return toPosix(scePthreadCondTimedwait(cond, mutex, usec));
}
int APS5_VABI pthread_cond_wait_nid_postfix(PthreadCond* cond, PthreadMutex* mutex) {
return toPosix(scePthreadCondWait(cond, mutex));
}
int APS5_VABI pthread_condattr_destroy_nid_postfix(PthreadCondattr* attr) {
if (!attr || !*attr) return PosixThread::GUEST_EINVAL;
return toPosix(scePthreadCondattrDestroy(attr));
}
int APS5_VABI pthread_condattr_init_nid_postfix(PthreadCondattr* attr) {
if (!attr) return PosixThread::GUEST_EINVAL;
return toPosix(scePthreadCondattrInit(attr));
}
int APS5_VABI pthread_condattr_setclock_nid_postfix(PthreadCondattr* attr, KernelClockid clock_id) {
if (!attr || !*attr) return PosixThread::GUEST_EINVAL;
return toPosix(scePthreadCondattrSetclock(attr, clock_id));
}
int APS5_VABI pthread_condattr_setpshared_nid_postfix(PthreadCondattr* attr, int pshared) {
if (!attr || !*attr) return PosixThread::GUEST_EINVAL;
if (pshared != POSIX_PROCESS_PRIVATE) return PosixThread::GUEST_EINVAL;
(*attr)->_pshared = pshared;
return 0;
}
int APS5_VABI pthread_condattr_getpshared_nid_postfix(const PthreadCondattr* attr, int* pshared) {
if (!attr || !*attr) return PosixThread::GUEST_EINVAL;
if (!pshared) throw std::runtime_error("pthread_condattr_getpshared: null pshared");
*pshared = (*attr)->_pshared;
return 0;
}
int APS5_VABI pthread_cond_signalto_np_nid_postfix(PthreadCond* cond, Pthread thread) {
return toPosix(scePthreadCondSignalto(cond, thread));
}
int APS5_VABI scePthreadCondattrSetpshared(PthreadCondattr* attr, int pshared) {
return PosixThread::ToSce(pthread_condattr_setpshared_nid_postfix(attr, pshared));
}
int APS5_VABI scePthreadCondattrGetpshared(const PthreadCondattr* attr, int* pshared) {
return PosixThread::ToSce(pthread_condattr_getpshared_nid_postfix(attr, pshared));
}
}