MCPcopy Create free account
hub / github.com/RPCSX/rpcsx / _sys_lwcond_queue_wait

Function _sys_lwcond_queue_wait

kernel/cellos/src/sys_lwcond.cpp:383–565  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

381}
382
383error_code _sys_lwcond_queue_wait(ppu_thread &ppu, u32 lwcond_id,
384 u32 lwmutex_id, u64 timeout) {
385 ppu.state += cpu_flag::wait;
386
387 sys_lwcond.trace(
388 "_sys_lwcond_queue_wait(lwcond_id=0x%x, lwmutex_id=0x%x, timeout=0x%llx)",
389 lwcond_id, lwmutex_id, timeout);
390
391 ppu.gpr[3] = CELL_OK;
392
393 shared_ptr<lv2_lwmutex> mutex;
394
395 auto &sstate = *ppu.optional_savestate_state;
396
397 const auto cond = idm::get<lv2_obj, lv2_lwcond>(
398 lwcond_id, [&, notify = lv2_obj::notify_all_t()](lv2_lwcond &cond) {
399 mutex = idm::get_unlocked<lv2_obj, lv2_lwmutex>(lwmutex_id);
400
401 if (!mutex) {
402 return;
403 }
404
405 // Increment lwmutex's lwcond's waiters count
406 mutex->lwcond_waiters++;
407
408 lv2_obj::prepare_for_sleep(ppu);
409
410 std::lock_guard lock(cond.mutex);
411
412 cond.lwmutex_waiters++;
413
414 const bool mutex_sleep = sstate.try_read<bool>().second;
415 sstate.clear();
416
417 if (mutex_sleep) {
418 // Special: loading state from the point of waiting on lwmutex sleep
419 // queue
420 mutex->try_own(&ppu, true);
421 } else {
422 // Add a waiter
423 lv2_obj::emplace(cond.sq, &ppu);
424 }
425
426 if (!ppu.loaded_from_savestate && !mutex->try_unlock(false)) {
427 std::lock_guard lock2(mutex->mutex);
428
429 // Process lwmutex sleep queue
430 if (const auto cpu = mutex->reown<ppu_thread>()) {
431 if (static_cast<ppu_thread *>(cpu)->state & cpu_flag::again) {
432 ensure(cond.unqueue(cond.sq, &ppu));
433 ppu.state += cpu_flag::again;
434 return;
435 }
436
437 // Put the current thread to sleep and schedule lwmutex waiter
438 // atomically
439 cond.append(cpu);
440 cond.sleep(ppu, timeout);

Callers 1

sys_lwcond_waitFunction · 0.85

Calls 15

notify_all_tClass · 0.85
is_stoppedFunction · 0.85
busy_waitFunction · 0.85
unqueueMethod · 0.80
sleepMethod · 0.80
load_sqMethod · 0.80
ensureFunction · 0.50
loadFunction · 0.50
clearMethod · 0.45
try_ownMethod · 0.45
try_unlockMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected