/* must be called with interrupts locked */ static inline int is_condition_met(struct k_poll_event *event, u32_t *state) { switch (event->type) { case K_POLL_TYPE_SEM_AVAILABLE: if (k_sem_count_get(event->sem) > 0) { *state = K_POLL_STATE_SEM_AVAILABLE; return 1; } break; case K_POLL_TYPE_DATA_AVAILABLE: if (!k_queue_is_empty(event->queue)) { *state = K_POLL_STATE_FIFO_DATA_AVAILABLE; return 1; } break; case K_POLL_TYPE_SIGNAL: if (event->signal->signaled) { *state = K_POLL_STATE_SIGNALED; return 1; } break; case K_POLL_TYPE_IGNORE: return 0; default: __ASSERT(0, "invalid event type (0x%x)\n", event->type); break; } return 0; }
/**************************************************************************** * Function : k_priority_queue_dequeue ****************************************************************************** * Description : This function dequeues the first pcb in the priority queue * : with the highest priority.This function is only used to * : dequeue from the readyQ and blockedQ. Because of this, * : the allQ parameter is not necessary. * * Assumptions : Will return NULL if dequeueing from an empty priority queue. * : Assumes a valid priority queue is specified. ****************************************************************************/ k_PCB_ptr k_priority_queue_dequeue(k_priority_queue_ptr PQ) { if (PQ == NULL) return NULL; // Do nothing if invalid pointer passed // If priority queue is empty, return NULL. if (k_priority_queue_is_empty(PQ)) return NULL; int i = 0; // Will iterate through PQ starting from highest priority until a non-empty queue is found. // i will always contain a valid index, because empty queue case has already been handled. while (k_queue_is_empty(PQ->array[i])) i++; // Here i is index of highest priority non-empty queue, so dequeue from there. return (k_queue_dequeue(PQ->array[i])); }