mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-10 01:28:44 +02:00
test(libkernel): wait for the host-blocked worker to take the mutex before relocking
In the host-blocked phase of guest_raise_exception, the redirected handler runs as soon as the worker wakes inside pthread_mutex_lock, before it owns hostLock. ExpectDelivery then returns and main relocks hostLock right away. If main wins that race, the worker stays blocked in the previous round's lock_guard, so it never sets started for the next round and main spins forever. The run hangs until the 30 s ctest timeout, with only three RunThread lines in the log. The worker now publishes the round after it acquires the mutex, and main waits for that before relocking. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -73,6 +73,7 @@ static std::mutex hostLock;
|
||||
|
||||
static constexpr int HostRounds = 20;
|
||||
static std::atomic<int> hostRound{0};
|
||||
static std::atomic<int> hostAcquired{0};
|
||||
|
||||
static void* APS5_VABI HostBlocked(void* arg) {
|
||||
auto& worker = *static_cast<Worker*>(arg);
|
||||
@@ -81,6 +82,7 @@ static void* APS5_VABI HostBlocked(void* arg) {
|
||||
while (hostRound.load() != round) std::this_thread::yield();
|
||||
worker.started.store(true);
|
||||
std::lock_guard lock(hostLock);
|
||||
hostAcquired.store(round + 1);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@@ -164,6 +166,7 @@ int main() {
|
||||
Require(sceKernelRaiseException(blockedThread, SIGUSR1) == 0);
|
||||
hostLock.unlock();
|
||||
ExpectDelivery(1 + 2 * Repeats + round, blocked.id);
|
||||
while (hostAcquired.load() != round + 1) std::this_thread::yield();
|
||||
hostLock.lock();
|
||||
blocked.started.store(false);
|
||||
hostRound.store(round + 1);
|
||||
|
||||
Reference in New Issue
Block a user