void tcp_sleep(void * event) { int i; /* search event array for an unused slot */ for (i = 0; i < MAX_EVENTS; i++) { if (tk_eventlist[i].event == 0) /* found a slot */ { tk_eventlist[i].event = event; /* save event to wake up on */ tk_eventlist[i].task = TK_THIS; /* save calling task */ UNLOCK_NET_RESOURCE(NET_RESID); /* free stack mutex */ TK_BLOCK(); /* suspend calling task */ LOCK_NET_RESOURCE(NET_RESID); /* we woke up - reenter stack */ tk_eventlist[i].event = NULL; /* clear array entry */ return; } } /* fall to here if we ran out of free event slots. Best thing to do is * let system spin, then return to caller for another sleep test. */ tcp_no_taskslot++; tk_yield(); }
void tk_exit(void) { tk_kill(tk_cur); /* kill current task, save in tk_to_die */ TK_BLOCK(); /* this should delete tk_to_die */ panic("tk_exit"); /* should never return from block */ }
void tk_sleep(u_long ticks) { tk_cur->tk_flags &= ~TF_AWAKE; /* put task to sleep */ tk_cur->tk_flags |= TF_TIMER; tk_cur->tk_waketick = TIME_ADD(CTICKS, ticks); /* set wake time */ TK_BLOCK(); tk_cur->tk_flags &= ~TF_TIMEOUT; /* clear timeout flag */ }
/* FUNCTION: tk_suspend() * * Suspend a task * * PARAM1: task * task handle * * RETURN: none */ void tk_suspend(TASK *tk) { if (tk == (TASK *)NULL) tk = tk_cur; #ifdef DEBUG_TASK dprintf("tk_suspend(%s)\n", tk->tk_name); #endif tk->tk_flags &= ~TF_AWAKE; tk->tk_flags |= TF_SUSPEND; #ifndef SUPERLOOP if (iniche_os_ready == TRUE) { /* are we suspending ourself? */ if (tk == tk_cur) TK_BLOCK(); } #endif /* not SUPERLOOP */ }