void __ssx_thread_timeout(void *arg) { SsxThread *thread = (SsxThread *)arg; switch (thread->state) { case SSX_THREAD_STATE_MAPPED: if (!__ssx_thread_is_runnable(thread)) { thread->flags |= SSX_THREAD_FLAG_TIMED_OUT; __ssx_thread_queue_insert(&__ssx_run_queue, thread->priority); __ssx_schedule(); } break; case SSX_THREAD_STATE_SUSPENDED_RUNNABLE: break; case SSX_THREAD_STATE_SUSPENDED_BLOCKED: thread->flags |= SSX_THREAD_FLAG_TIMED_OUT; thread->state = SSX_THREAD_STATE_SUSPENDED_RUNNABLE; break; default: SSX_PANIC(SSX_THREAD_TIMEOUT_STATE); } }
void __ssx_thread_unmap(SsxThread* thread) { SsxThreadPriority priority; priority = thread->priority; __ssx_priority_map[priority] = 0; if (__ssx_thread_is_runnable(thread)) { thread->state = SSX_THREAD_STATE_SUSPENDED_RUNNABLE; __ssx_thread_queue_delete(&__ssx_run_queue, priority); } else { thread->state = SSX_THREAD_STATE_SUSPENDED_BLOCKED; if (thread->flags & SSX_THREAD_FLAG_SEMAPHORE_PEND) { __ssx_thread_queue_delete(&(thread->semaphore->pending_threads), priority); } } }
void __ssx_thread_map(SsxThread* thread) { SsxThreadPriority priority; priority = thread->priority; __ssx_priority_map[priority] = thread; if (thread->state == SSX_THREAD_STATE_SUSPENDED_RUNNABLE) { __ssx_thread_queue_insert(&__ssx_run_queue, priority); } else if (thread->flags & SSX_THREAD_FLAG_SEMAPHORE_PEND) { if (thread->semaphore->count) { thread->semaphore->count--; __ssx_thread_queue_insert(&__ssx_run_queue, priority); } else { __ssx_thread_queue_insert(&(thread->semaphore->pending_threads), priority); } } thread->state = SSX_THREAD_STATE_MAPPED; if (SSX_KERNEL_TRACE_ENABLE) { if (__ssx_thread_is_runnable(thread)) { SSX_KERN_TRACE("THREAD_MAPPED_RUNNABLE(%d)", priority); } else if (thread->flags & SSX_THREAD_FLAG_SEMAPHORE_PEND) { SSX_KERN_TRACE("THREAD_MAPPED_SEMAPHORE_PEND(%d)", priority); } else { SSX_KERN_TRACE("THREAD_MAPPED_SLEEPING(%d)", priority); } } }