mirror of
https://github.com/RPCSX/rpcsx.git
synced 2026-01-02 14:50:05 +01:00
[orbis-kernel] Evf: don't use thread retval to store result
This commit is contained in:
parent
1bf88f6fe8
commit
5f5538cc68
|
|
@ -12,7 +12,6 @@ namespace orbis {
|
|||
struct Process;
|
||||
struct Thread {
|
||||
utils::shared_mutex mtx;
|
||||
utils::shared_cv sync_cv;
|
||||
Process *tproc = nullptr;
|
||||
uint64_t retval[2]{};
|
||||
void *context{};
|
||||
|
|
@ -28,6 +27,11 @@ struct Thread {
|
|||
ThreadState state = ThreadState::INACTIVE;
|
||||
std::thread handle;
|
||||
|
||||
// Used to wake up thread in sleep queue
|
||||
utils::shared_cv sync_cv;
|
||||
uint64_t evfResultPattern;
|
||||
uint64_t evfIsCancelled;
|
||||
|
||||
// FIXME: implement thread destruction
|
||||
void incRef() {}
|
||||
void decRef() {}
|
||||
|
|
|
|||
|
|
@ -29,16 +29,15 @@ orbis::ErrorCode orbis::EventFlag::wait(Thread *thread, std::uint8_t waitMode,
|
|||
*timeout = 0;
|
||||
};
|
||||
|
||||
// Use retval to pass information between threads
|
||||
thread->retval[0] = 0; // resultPattern
|
||||
thread->retval[1] = 0; // isCanceled
|
||||
thread->evfResultPattern = 0;
|
||||
thread->evfIsCancelled = 0;
|
||||
|
||||
std::unique_lock lock(queueMtx);
|
||||
while (true) {
|
||||
if (isDeleted) {
|
||||
return ErrorCode::ACCES;
|
||||
}
|
||||
if (thread->retval[1]) {
|
||||
if (thread->evfIsCancelled) {
|
||||
return ErrorCode::CANCELED;
|
||||
}
|
||||
|
||||
|
|
@ -49,7 +48,7 @@ orbis::ErrorCode orbis::EventFlag::wait(Thread *thread, std::uint8_t waitMode,
|
|||
waitingThread.test(patValue)) {
|
||||
auto resultValue = waitingThread.applyClear(patValue);
|
||||
value.store(resultValue, std::memory_order::relaxed);
|
||||
thread->retval[0] = resultValue;
|
||||
thread->evfResultPattern = resultValue;
|
||||
// Success
|
||||
break;
|
||||
}
|
||||
|
|
@ -111,7 +110,7 @@ orbis::ErrorCode orbis::EventFlag::tryWait(Thread *thread,
|
|||
waitingThread.test(patValue)) {
|
||||
auto resultValue = waitingThread.applyClear(patValue);
|
||||
value.store(resultValue, std::memory_order::relaxed);
|
||||
thread->retval[0] = resultValue;
|
||||
thread->evfResultPattern = resultValue;
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
@ -136,9 +135,9 @@ std::size_t orbis::EventFlag::notify(NotifyType type, std::uint64_t bits) {
|
|||
|
||||
auto resultValue = thread->applyClear(patValue);
|
||||
patValue = resultValue;
|
||||
thread->thread->retval[0] = resultValue;
|
||||
thread->thread->evfResultPattern = resultValue;
|
||||
if (type == NotifyType::Cancel) {
|
||||
thread->thread->retval[1] = true;
|
||||
thread->thread->evfIsCancelled = 1;
|
||||
}
|
||||
|
||||
// TODO: update thread state
|
||||
|
|
|
|||
|
|
@ -207,23 +207,19 @@ orbis::SysResult orbis::sys_evf_wait(Thread *thread, sint id,
|
|||
}
|
||||
|
||||
std::uint32_t resultTimeout{};
|
||||
std::uint64_t resultPattern{};
|
||||
auto result = evf->wait(thread, mode, patternSet,
|
||||
pTimeout != nullptr ? &resultTimeout : nullptr);
|
||||
resultPattern = thread->retval[0];
|
||||
|
||||
ORBIS_LOG_NOTICE("sys_evf_wait wakeup", thread, resultPattern, resultTimeout);
|
||||
ORBIS_LOG_NOTICE("sys_evf_wait wakeup", thread, thread->evfResultPattern);
|
||||
|
||||
if (pPatternSet != nullptr) {
|
||||
uwrite(pPatternSet, (uint64_t)resultPattern);
|
||||
uwrite(pPatternSet, thread->evfResultPattern);
|
||||
}
|
||||
|
||||
if (pTimeout != nullptr) {
|
||||
uwrite(pTimeout, (uint32_t)resultTimeout);
|
||||
uwrite(pTimeout, resultTimeout);
|
||||
}
|
||||
|
||||
thread->retval[0] = 0;
|
||||
thread->retval[1] = 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -244,15 +240,12 @@ orbis::SysResult orbis::sys_evf_trywait(Thread *thread, sint id,
|
|||
return ErrorCode::SRCH;
|
||||
}
|
||||
|
||||
std::uint64_t resultPattern{};
|
||||
auto result = evf->tryWait(thread, mode, patternSet);
|
||||
resultPattern = thread->retval[0];
|
||||
|
||||
if (pPatternSet != nullptr) {
|
||||
uwrite(pPatternSet, (uint64_t)resultPattern);
|
||||
uwrite(pPatternSet, thread->evfResultPattern);
|
||||
}
|
||||
|
||||
thread->retval[0] = 0;
|
||||
return result;
|
||||
}
|
||||
orbis::SysResult orbis::sys_evf_set(Thread *thread, sint id, uint64_t value) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue