@@ -19,30 +19,25 @@ extern "C" {
typedef struct {
uint32_t head;
uint32_t tail;
- uint32_t mask;
- uint32_t *data;
-
} ring_st_t;
/* Initialize ring. Ring size must be a power of two. */
-static inline void ring_st_init(ring_st_t *ring, uint32_t *data, uint32_t size)
+static inline void ring_st_init(ring_st_t *ring)
{
ring->head = 0;
ring->tail = 0;
- ring->mask = size - 1;
- ring->data = data;
}
/* Dequeue data from the ring head. Max_num is smaller than ring size.*/
-static inline uint32_t ring_st_deq_multi(ring_st_t *ring, uint32_t data[],
+static inline uint32_t ring_st_deq_multi(ring_st_t *ring, uint32_t *ring_data,
+ uint32_t ring_mask, uint32_t data[],
uint32_t max_num)
{
- uint32_t head, tail, mask, idx;
+ uint32_t head, tail, idx;
uint32_t num, i;
head = ring->head;
tail = ring->tail;
- mask = ring->mask;
num = tail - head;
/* Empty */
@@ -52,11 +47,11 @@ static inline uint32_t ring_st_deq_multi(ring_st_t *ring, uint32_t data[],
if (num > max_num)
num = max_num;
- idx = head & mask;
+ idx = head & ring_mask;
for (i = 0; i < num; i++) {
- data[i] = ring->data[idx];
- idx = (idx + 1) & mask;
+ data[i] = ring_data[idx];
+ idx = (idx + 1) & ring_mask;
}
ring->head = head + num;
@@ -65,16 +60,17 @@ static inline uint32_t ring_st_deq_multi(ring_st_t *ring, uint32_t data[],
}
/* Enqueue data into the ring tail. Num_data is smaller than ring size. */
-static inline uint32_t ring_st_enq_multi(ring_st_t *ring, const uint32_t data[],
+static inline uint32_t ring_st_enq_multi(ring_st_t *ring, uint32_t *ring_data,
+ uint32_t ring_mask,
+ const uint32_t data[],
uint32_t num_data)
{
- uint32_t head, tail, mask, size, idx;
+ uint32_t head, tail, size, idx;
uint32_t num, i;
head = ring->head;
tail = ring->tail;
- mask = ring->mask;
- size = mask + 1;
+ size = ring_mask + 1;
num = size - (tail - head);
/* Full */
@@ -84,11 +80,11 @@ static inline uint32_t ring_st_enq_multi(ring_st_t *ring, const uint32_t data[],
if (num > num_data)
num = num_data;
- idx = tail & mask;
+ idx = tail & ring_mask;
for (i = 0; i < num; i++) {
- ring->data[idx] = data[i];
- idx = (idx + 1) & mask;
+ ring_data[idx] = data[i];
+ idx = (idx + 1) & ring_mask;
}
ring->tail = tail + num;
@@ -687,7 +687,8 @@ static inline int _sched_queue_enq_multi(odp_queue_t handle,
return -1;
}
- num_enq = ring_st_enq_multi(ring_st, buf_idx, num);
+ num_enq = ring_st_enq_multi(ring_st, queue->s.ring_data,
+ queue->s.ring_mask, buf_idx, num);
if (odp_unlikely(num_enq == 0)) {
UNLOCK(queue);
@@ -728,7 +729,8 @@ int sched_queue_deq(uint32_t queue_index, odp_event_t ev[], int max_num,
return -1;
}
- num_deq = ring_st_deq_multi(ring_st, buf_idx, max_num);
+ num_deq = ring_st_deq_multi(ring_st, queue->s.ring_data,
+ queue->s.ring_mask, buf_idx, max_num);
if (num_deq == 0) {
/* Already empty queue */
@@ -875,8 +877,10 @@ static int queue_init(queue_entry_t *queue, const char *name,
} else {
queue->s.enqueue = sched_queue_enq;
queue->s.enqueue_multi = sched_queue_enq_multi;
- ring_st_init(&queue->s.ring_st,
- &queue_glb->ring_data[offset], queue_size);
+
+ queue->s.ring_data = &queue_glb->ring_data[offset];
+ queue->s.ring_mask = queue_size - 1;
+ ring_st_init(&queue->s.ring_st);
}
}