@@ -18,9 +18,6 @@ extern "C" {
#include <odp/api/plat/atomic_inlines.h>
#include <odp/api/plat/cpu_inlines.h>
-/* Ring empty, not a valid data value. */
-#define RING_EMPTY ((uint32_t)-1)
-
/* Ring of uint32_t data
*
* Ring stores head and tail counters. Ring indexes are formed from these
@@ -59,7 +56,7 @@ static inline void ring_init(ring_t *ring)
}
/* Dequeue data from the ring head */
-static inline uint32_t ring_deq(ring_t *ring, uint32_t mask)
+static inline uint32_t ring_deq(ring_t *ring, uint32_t mask, uint32_t *data)
{
uint32_t head, tail, new_head;
@@ -73,7 +70,7 @@ static inline uint32_t ring_deq(ring_t *ring, uint32_t mask)
tail = odp_atomic_load_acq_u32(&ring->w_tail);
if (head == tail)
- return RING_EMPTY;
+ return 0;
new_head = head + 1;
@@ -83,7 +80,8 @@ static inline uint32_t ring_deq(ring_t *ring, uint32_t mask)
/* Read data. CAS acquire-release ensures that data read
* does not move above from here. */
- return ring->data[new_head & mask];
+ *data = ring->data[new_head & mask];
+ return 1;
}
/* Dequeue multiple data from the ring head. Num is smaller than ring size. */
@@ -416,8 +416,7 @@ static int schedule_term_global(void)
ring_t *ring = &sched->prio_q[grp][i][j].ring;
uint32_t qi;
- while ((qi = ring_deq(ring, ring_mask)) !=
- RING_EMPTY) {
+ while (ring_deq(ring, ring_mask, &qi)) {
odp_event_t events[1];
int num;
@@ -907,10 +906,9 @@ static inline int do_schedule_grp(odp_queue_t *out_queue, odp_event_t out_ev[],
/* Get queue index from the priority queue */
ring = &sched->prio_q[grp][prio][id].ring;
- qi = ring_deq(ring, ring_mask);
- /* Priority queue empty */
- if (qi == RING_EMPTY) {
+ if (ring_deq(ring, ring_mask, &qi) == 0) {
+ /* Priority queue empty */
i++;
id++;
continue;
@@ -271,7 +271,7 @@ static int schedule_init_global(void)
ring_init(&queue->ring);
for (k = 0; k < PKTIO_RING_SIZE; k++)
- queue->cmd_index[k] = RING_EMPTY;
+ queue->cmd_index[k] = -1;
}
for (i = 0; i < NUM_PKTIO_CMD; i++)
@@ -668,9 +668,8 @@ static inline void pktio_poll_input(void)
for (i = 0; i < PKTIO_CMD_QUEUES; i++,
hash = (hash + 1) % PKTIO_CMD_QUEUES) {
ring = &sched->pktio_poll.queues[hash].ring;
- index = ring_deq(ring, PKTIO_RING_MASK);
- if (odp_unlikely(index == RING_EMPTY))
+ if (odp_unlikely(ring_deq(ring, PKTIO_RING_MASK, &index) == 0))
continue;
cmd = &sched->pktio_poll.commands[index];
@@ -401,9 +401,8 @@ static inline sched_cmd_t *rem_head(int group, int prio)
int pktio;
prio_queue = &sched_global->prio_queue[group][prio];
- ring_idx = ring_deq(&prio_queue->ring, RING_MASK);
- if (ring_idx == RING_EMPTY)
+ if (ring_deq(&prio_queue->ring, RING_MASK, &ring_idx) == 0)
return NULL;
pktio = index_from_ring_idx(&index, ring_idx);