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; }
int queue_enq(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr) { int sched = 0; LOCK(&queue->s.lock); if (odp_unlikely(queue->s.status < QUEUE_STATUS_READY)) { UNLOCK(&queue->s.lock); ODP_ERR("Bad queue status\n"); return -1; } if (queue->s.head == NULL) { /* Empty queue */ queue->s.head = buf_hdr; queue->s.tail = buf_hdr; buf_hdr->next = NULL; } else { queue->s.tail->next = buf_hdr; queue->s.tail = buf_hdr; buf_hdr->next = NULL; } if (queue->s.status == QUEUE_STATUS_NOTSCHED) { queue->s.status = QUEUE_STATUS_SCHED; sched = 1; /* retval: schedule queue */ } UNLOCK(&queue->s.lock); /* Add queue to scheduling */ if (sched && schedule_queue(queue)) ODP_ABORT("schedule_queue failed\n"); return 0; }
int queue_enq_multi(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr[], int num) { int sched = 0; int i; odp_buffer_hdr_t *tail; for (i = 0; i < num - 1; i++) buf_hdr[i]->next = buf_hdr[i+1]; tail = buf_hdr[num-1]; buf_hdr[num-1]->next = NULL; 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; } /* Empty queue */ if (LOAD_PTR(queue->s.head) == NULL) STORE_PTR(queue->s.head, buf_hdr[0]); else STORE_PTR(((typeof(queue->s.tail))LOAD_PTR(queue->s.tail))->next, buf_hdr[0]); STORE_PTR(queue->s.tail, tail); if (status == QUEUE_STATUS_NOTSCHED) { STORE_PTR(queue->s.status, QUEUE_STATUS_SCHED); sched = 1; /* retval: schedule queue */ } UNLOCK(queue); /* Add queue to scheduling */ if (sched) schedule_queue(queue); return num; /* All events enqueued */ }
int queue_enq_multi(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr[], int num) { int sched = 0; int i; odp_buffer_hdr_t *tail; for (i = 0; i < num - 1; i++) buf_hdr[i]->next = buf_hdr[i+1]; tail = buf_hdr[num-1]; buf_hdr[num-1]->next = NULL; LOCK(&queue->s.lock); if (odp_unlikely(queue->s.status < QUEUE_STATUS_READY)) { UNLOCK(&queue->s.lock); ODP_ERR("Bad queue status\n"); return -1; } /* Empty queue */ if (queue->s.head == NULL) queue->s.head = buf_hdr[0]; else queue->s.tail->next = buf_hdr[0]; queue->s.tail = tail; if (queue->s.status == QUEUE_STATUS_NOTSCHED) { queue->s.status = QUEUE_STATUS_SCHED; sched = 1; /* retval: schedule queue */ } UNLOCK(&queue->s.lock); /* Add queue to scheduling */ if (sched && schedule_queue(queue)) ODP_ABORT("schedule_queue failed\n"); return num; /* All events enqueued */ }
queue ser_queue( ) { auto comm = std::make_shared< ser_queue_comm >( ); queue q( queue_type::serial, [comm = std::move( comm )]( queue & q ) { boost::lock_guard< boost::mutex > lock( comm->mt_qu ); comm->qu.append_queue( { steal_work, q } ); if ( comm->cor_sched ) { return; } queue q_ser( queue_type::serial ); q_ser.submit_work( [comm]( ) mutable { boost::lock_guard< event::mutex > lock_exec( comm->mt_exec ); boost::unique_lock< boost::mutex > lock( comm->mt_qu ); assert( comm->cor_sched ); comm->cor_sched = false; auto q_work = std::move( comm->qu ); comm->qu = queue( queue_type::serial ); lock.unlock( ); q_work.run_until_empty( ); } ); schedule_queue( std::move( q_ser ) ); comm->cor_sched = true; } ); return q; }
static void sch_par_queue( queue& q ) { queue qw( steal_work, q ); schedule_queue( std::move( qw ) ); }