void *nano_fiber_lifo_get_wait_timeout(struct nano_lifo *lifo, int32_t timeout_in_ticks) { unsigned int key = irq_lock_inline(); void *data; if (!lifo->list) { if (unlikely(TICKS_NONE == timeout_in_ticks)) { irq_unlock_inline(key); return NULL; } if (likely(timeout_in_ticks != TICKS_UNLIMITED)) { _nano_timeout_add(_nanokernel.current, &lifo->wait_q, timeout_in_ticks); } _nano_wait_q_put(&lifo->wait_q); data = (void *)_Swap(key); } else { data = lifo->list; lifo->list = *(void **)data; irq_unlock_inline(key); } return data; }
void fiber_sleep(int32_t timeout_in_ticks) { int key; if (timeout_in_ticks == TICKS_NONE) { fiber_yield(); return; } key = irq_lock(); _nano_timeout_add(_nanokernel.current, NULL, timeout_in_ticks); _Swap(key); }
void *fiber_delayed_start(char *stack, unsigned int stack_size_in_bytes, nano_fiber_entry_t entry_point, int param1, int param2, unsigned int priority, unsigned int options, int32_t timeout_in_ticks) { unsigned int key; struct tcs *tcs; tcs = (struct tcs *)stack; _new_thread(stack, stack_size_in_bytes, (_thread_entry_t)entry_point, (void *)param1, (void *)param2, (void *)0, priority, options); key = irq_lock(); _nano_timeout_add(tcs, NULL, timeout_in_ticks); irq_unlock(key); return tcs; }
int nano_fiber_sem_take_wait_timeout(struct nano_sem *sem, int32_t timeout_in_ticks) { unsigned int key = irq_lock_inline(); if (sem->nsig == 0) { if (unlikely(TICKS_NONE == timeout_in_ticks)) { irq_unlock_inline(key); return 0; } if (likely(timeout_in_ticks != TICKS_UNLIMITED)) { _nano_timeout_add(_nanokernel.current, &sem->wait_q, timeout_in_ticks); } _nano_wait_q_put(&sem->wait_q); return _Swap(key); } sem->nsig--; irq_unlock_inline(key); return 1; }