static void _TestFlag (void *payload, void *arg) { nOS_Thread *thread = (nOS_Thread*)payload; nOS_Flag *flag = (nOS_Flag*)thread->event; nOS_FlagContext *ctx = (nOS_FlagContext*)thread->ext; nOS_FlagResult *res = (nOS_FlagResult*)arg; nOS_FlagBits r; /* Verify flags from object with wanted flags from waiting thread. */ r = flag->flags & ctx->flags; if (((ctx->opt & NOS_FLAG_WAIT) == NOS_FLAG_WAIT_ALL) && (r != ctx->flags)) { r = NOS_FLAG_NONE; } /* If conditions are met, wake up the thread and give it the result. */ if (r != NOS_FLAG_NONE) { nOS_WakeUpThread(thread, NOS_OK); *ctx->rflags = r; /* Accumulate awoken flags if waiting thread want to clear it when awoken. */ if (ctx->opt & NOS_FLAG_CLEAR_ON_EXIT) { res->rflags |= r; } #if (NOS_CONFIG_HIGHEST_THREAD_PRIO > 0) && (NOS_CONFIG_SCHED_PREEMPTIVE_ENABLE > 0) if (thread->prio > nOS_runningThread->prio) { /* Indicate that we need a preemptive scheduling. */ res->sched = true; } #endif } }
nOS_Error nOS_ThreadAbort (nOS_Thread *thread) { nOS_Error err; nOS_StatusReg sr; #if (NOS_CONFIG_SAFE > 0) if (thread == NULL) { err = NOS_E_INV_OBJ; } else if (thread == nOS_runningThread) { err = NOS_E_INV_OBJ; } else if (thread == &nOS_idleHandle) { err = NOS_E_INV_OBJ; } else #endif { nOS_EnterCritical(sr); #if (NOS_CONFIG_SAFE > 0) if (thread->state == NOS_THREAD_STOPPED) { err = NOS_E_INV_OBJ; } else if (thread->state & NOS_THREAD_SUSPENDED) { err = NOS_E_INV_STATE; } else if ( !(thread->state & NOS_THREAD_WAITING_MASK) ) { err = NOS_E_INV_STATE; } else #endif { nOS_WakeUpThread(thread, NOS_E_ABORT); #if (NOS_CONFIG_HIGHEST_THREAD_PRIO > 0) && (NOS_CONFIG_SCHED_PREEMPTIVE_ENABLE > 0) if (thread->prio > nOS_runningThread->prio) { nOS_Schedule(); } #endif err = NOS_OK; } nOS_LeaveCritical(sr); } return err; }
static void _TestFlag (void *payload, void *arg) { nOS_Thread *thread = (nOS_Thread*)payload; nOS_Flag *flag = (nOS_Flag*)thread->event; nOS_FlagContext *ctx = (nOS_FlagContext*)thread->ext; nOS_FlagBits *res = (nOS_FlagBits*)arg; nOS_FlagBits r; /* Verify flags from object with wanted flags from waiting thread. */ r = flag->flags & ctx->flags; if (((ctx->opt & NOS_FLAG_WAIT) == NOS_FLAG_WAIT_ALL) && (r != ctx->flags)) { r = NOS_FLAG_NONE; } /* If conditions are met, wake up the thread and give it the result. */ if (r != NOS_FLAG_NONE) { nOS_WakeUpThread(thread, NOS_OK); *ctx->rflags = r; /* Accumulate awoken flags if waiting thread want to clear it when awoken. */ if (ctx->opt & NOS_FLAG_CLEAR_ON_EXIT) { *res |= r; } } }
void nOS_TickThread (void *payload, void *arg) { nOS_Thread *thread = (nOS_Thread*)payload; nOS_ThreadState state = (thread->state & NOS_THREAD_WAITING_MASK); nOS_Error err = NOS_E_TIMEOUT; /* Avoid warning */ NOS_UNUSED(arg); if (thread->timeout == nOS_tickCounter) { #if (NOS_CONFIG_SLEEP_ENABLE > 0) if (state == NOS_THREAD_SLEEPING) { err = NOS_OK; } #endif #if (NOS_CONFIG_SLEEP_UNTIL_ENABLE > 0) if (state == NOS_THREAD_SLEEPING_UNTIL) { err = NOS_OK; } #endif nOS_WakeUpThread(thread, err); } }