int queue_enq(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr) { int sched = 0; LOCK(queue); int status = LOAD_S32(queue->s.status); if (odp_unlikely(status < QUEUE_STATUS_READY)) { UNLOCK(queue); ODP_ERR("Bad queue status\n"); return -1; } if (LOAD_PTR(queue->s.head) == NULL) { /* Empty queue */ STORE_PTR(queue->s.head, buf_hdr); STORE_PTR(queue->s.tail, buf_hdr); buf_hdr->next = NULL; } else { STORE_PTR(((typeof(queue->s.tail))LOAD_PTR(queue->s.tail))->next, buf_hdr); STORE_PTR(queue->s.tail, buf_hdr); buf_hdr->next = NULL; } if (status == QUEUE_STATUS_NOTSCHED) { STORE_S32(queue->s.status, QUEUE_STATUS_SCHED); sched = 1; /* retval: schedule queue */ } UNLOCK(queue); /* Add queue to scheduling */ if (sched) schedule_queue(queue); return 0; }
odp_buffer_hdr_t *queue_deq(queue_entry_t *queue) { odp_buffer_hdr_t *buf_hdr; if (LOAD_PTR(queue->s.head) == NULL) return NULL; LOCK(queue); buf_hdr = LOAD_PTR(queue->s.head); if (buf_hdr == NULL) { UNLOCK(queue); return NULL; } INVALIDATE(buf_hdr); STORE_PTR(queue->s.head, buf_hdr->next); if (buf_hdr->next == NULL) { /* Queue is now empty */ STORE_PTR(queue->s.tail, NULL); if (LOAD_S32(queue->s.status) == QUEUE_STATUS_SCHED) STORE_S32(queue->s.status, QUEUE_STATUS_NOTSCHED); } buf_hdr->next = NULL; UNLOCK(queue); return buf_hdr; }
void odp_rwlock_recursive_write_unlock(odp_rwlock_recursive_t *rlock) { rlock->wr_cnt--; if (rlock->wr_cnt > 0) return; STORE_S32(rlock->wr_owner, NO_OWNER); odp_rwlock_write_unlock(&rlock->lock); }
int queue_deq_multi(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr[], int num) { odp_buffer_hdr_t *hdr; int i; LOCK(queue); int status = LOAD_S32(queue->s.status); if (odp_unlikely(status < QUEUE_STATUS_READY)) { /* Bad queue, or queue has been destroyed. * Scheduler finalizes queue destroy after this. */ UNLOCK(queue); return -1; } hdr = LOAD_PTR(queue->s.head); if (hdr == NULL) { /* Already empty queue */ if (status == QUEUE_STATUS_SCHED) STORE_S32(queue->s.status, QUEUE_STATUS_NOTSCHED); UNLOCK(queue); return 0; } for (i = 0; i < num && hdr; i++) { INVALIDATE(hdr); buf_hdr[i] = hdr; hdr = hdr->next; buf_hdr[i]->next = NULL; } STORE_PTR(queue->s.head, hdr); if (hdr == NULL) { /* Queue is now empty */ STORE_PTR(queue->s.tail, NULL); } UNLOCK(queue); return i; }