本文整理汇总了C++中Thread::IsRunning方法的典型用法代码示例。如果您正苦于以下问题:C++ Thread::IsRunning方法的具体用法?C++ Thread::IsRunning怎么用?C++ Thread::IsRunning使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Thread
的用法示例。
在下文中一共展示了Thread::IsRunning方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetThreadPriority
/// Set the priority of the thread specified by handle
Result SetThreadPriority(Handle handle, s32 priority) {
Thread* thread = nullptr;
if (!handle) {
thread = GetCurrentThread(); // TODO(bunnei): Is this correct behavior?
} else {
thread = g_object_pool.GetFast<Thread>(handle);
}
_assert_msg_(KERNEL, (thread != nullptr), "called, but thread is nullptr!");
// If priority is invalid, clamp to valid range
if (priority < THREADPRIO_HIGHEST || priority > THREADPRIO_LOWEST) {
s32 new_priority = CLAMP(priority, THREADPRIO_HIGHEST, THREADPRIO_LOWEST);
WARN_LOG(KERNEL, "invalid priority=0x%08X, clamping to %08X", priority, new_priority);
// TODO(bunnei): Clamping to a valid priority is not necessarily correct behavior... Confirm
// validity of this
priority = new_priority;
}
// Change thread priority
s32 old = thread->current_priority;
g_thread_ready_queue.remove(old, handle);
thread->current_priority = priority;
g_thread_ready_queue.prepare(thread->current_priority);
// Change thread status to "ready" and push to ready queue
if (thread->IsRunning()) {
thread->status = (thread->status & ~THREADSTATUS_RUNNING) | THREADSTATUS_READY;
}
if (thread->IsReady()) {
g_thread_ready_queue.push_back(thread->current_priority, handle);
}
return 0;
}
示例2: NextThread
/// Gets the next thread that is ready to be run by priority
Thread* NextThread() {
Handle next;
Thread* cur = GetCurrentThread();
if (cur && cur->IsRunning()) {
next = g_thread_ready_queue.pop_first_better(cur->current_priority);
} else {
next = g_thread_ready_queue.pop_first();
}
if (next == 0) {
return nullptr;
}
return Kernel::g_object_pool.GetFast<Thread>(next);
}
示例3: SetupMainThread
/// Sets up the primary application thread
Handle SetupMainThread(s32 priority, int stack_size) {
Handle handle;
// Initialize new "main" thread
Thread* thread = CreateThread(handle, "main", Core::g_app_core->GetPC(), priority,
THREADPROCESSORID_0, Memory::SCRATCHPAD_VADDR_END, stack_size);
ResetThread(thread, 0, 0);
// If running another thread already, set it to "ready" state
Thread* cur = GetCurrentThread();
if (cur && cur->IsRunning()) {
ChangeReadyState(cur, true);
}
// Run new "main" thread
SetCurrentThread(thread);
thread->status = THREADSTATUS_RUNNING;
LoadContext(thread->context);
return handle;
}
示例4: SwitchContext
/// Switches CPU context to that of the specified thread
void SwitchContext(Thread* t) {
Thread* cur = GetCurrentThread();
// Save context for current thread
if (cur) {
SaveContext(cur->context);
if (cur->IsRunning()) {
ChangeReadyState(cur, true);
}
}
// Load context of new thread
if (t) {
SetCurrentThread(t);
ChangeReadyState(t, false);
t->status = (t->status | THREADSTATUS_RUNNING) & ~THREADSTATUS_READY;
t->wait_type = WAITTYPE_NONE;
LoadContext(t->context);
} else {
SetCurrentThread(nullptr);
}
}