/** * Wait for kernel object to synchronize * @param wait Boolean wait set if current thread should wait as a result of sync operation * @return Result of operation, 0 on success, otherwise error code */ Result WaitSynchronization(bool* wait) { if (status != THREADSTATUS_DORMANT) { Handle thread = GetCurrentThreadHandle(); if (std::find(waiting_threads.begin(), waiting_threads.end(), thread) == waiting_threads.end()) { waiting_threads.push_back(thread); } WaitCurrentThread(WAITTYPE_THREADEND, this->GetHandle()); *wait = true; } return 0; }
ResultVal<bool> WaitSynchronization() override { bool wait = !IsAvailable(); if (wait) { Kernel::WaitCurrentThread(WAITTYPE_SEMA, GetHandle()); waiting_threads.push(GetCurrentThreadHandle()); } else { --available_count; } return MakeResult<bool>(wait); }
/// Prints the thread queue for debugging purposes void DebugThreadQueue() { Thread* thread = GetCurrentThread(); if (!thread) { return; } INFO_LOG(KERNEL, "0x%02X 0x%08X (current)", thread->current_priority, GetCurrentThreadHandle()); for (u32 i = 0; i < g_thread_queue.size(); i++) { Handle handle = g_thread_queue[i]; s32 priority = g_thread_ready_queue.contains(handle); if (priority != -1) { INFO_LOG(KERNEL, "0x%02X 0x%08X", priority, handle); } } }
/** * Wait for kernel object to synchronize * @param wait Boolean wait set if current thread should wait as a result of sync operation * @return Result of operation, 0 on success, otherwise error code */ Result WaitSynchronization(bool* wait) override { *wait = locked; if (locked) { Handle thread = GetCurrentThreadHandle(); if (std::find(waiting_threads.begin(), waiting_threads.end(), thread) == waiting_threads.end()) { waiting_threads.push_back(thread); } Kernel::WaitCurrentThread(WAITTYPE_EVENT, GetHandle()); } if (reset_type != RESETTYPE_STICKY && !permanent_locked) { locked = true; } return 0; }