From: Petri Savolainen <petri.savolai...@linaro.org>

Use queue entry pointer as macro parameter instead of lock
pointer.

Signed-off-by: Petri Savolainen <petri.savolai...@linaro.org>
---
/** Email created from pull request 492 (psavol:master-sched-optim)
 ** https://github.com/Linaro/odp/pull/492
 ** Patch: https://github.com/Linaro/odp/pull/492.patch
 ** Base sha: 5a58bbf2bb331fd7dde2ebbc0430634ace6900fb
 ** Merge commit sha: b29563293c1bca56419d2dc355a8e64d961e024a
 **/
 platform/linux-generic/odp_queue.c | 68 +++++++++++++++++++-------------------
 1 file changed, 34 insertions(+), 34 deletions(-)

diff --git a/platform/linux-generic/odp_queue.c 
b/platform/linux-generic/odp_queue.c
index eda872321..f22b17b03 100644
--- a/platform/linux-generic/odp_queue.c
+++ b/platform/linux-generic/odp_queue.c
@@ -29,9 +29,9 @@
 #define NUM_INTERNAL_QUEUES 64
 
 #include <odp/api/plat/ticketlock_inlines.h>
-#define LOCK(a)      _odp_ticketlock_lock(a)
-#define UNLOCK(a)    _odp_ticketlock_unlock(a)
-#define LOCK_INIT(a) odp_ticketlock_init(a)
+#define LOCK(queue_ptr)      _odp_ticketlock_lock(&((queue_ptr)->s.lock))
+#define UNLOCK(queue_ptr)    _odp_ticketlock_unlock(&((queue_ptr)->s.lock))
+#define LOCK_INIT(queue_ptr)  odp_ticketlock_init(&((queue_ptr)->s.lock))
 
 #include <string.h>
 #include <inttypes.h>
@@ -88,7 +88,7 @@ static int queue_init_global(void)
        for (i = 0; i < ODP_CONFIG_QUEUES; i++) {
                /* init locks */
                queue_entry_t *queue = get_qentry(i);
-               LOCK_INIT(&queue->s.lock);
+               LOCK_INIT(queue);
                queue->s.index  = i;
                queue->s.handle = queue_from_index(i);
        }
@@ -123,12 +123,12 @@ static int queue_term_global(void)
 
        for (i = 0; i < ODP_CONFIG_QUEUES; i++) {
                queue = &queue_tbl->queue[i];
-               LOCK(&queue->s.lock);
+               LOCK(queue);
                if (queue->s.status != QUEUE_STATUS_FREE) {
                        ODP_ERR("Not destroyed queue: %s\n", queue->s.name);
                        rc = -1;
                }
-               UNLOCK(&queue->s.lock);
+               UNLOCK(queue);
        }
 
        ret = odp_shm_free(odp_shm_lookup("odp_queues"));
@@ -210,10 +210,10 @@ static odp_queue_t queue_create(const char *name,
                if (queue->s.status != QUEUE_STATUS_FREE)
                        continue;
 
-               LOCK(&queue->s.lock);
+               LOCK(queue);
                if (queue->s.status == QUEUE_STATUS_FREE) {
                        if (queue_init(queue, name, param)) {
-                               UNLOCK(&queue->s.lock);
+                               UNLOCK(queue);
                                return handle;
                        }
 
@@ -225,10 +225,10 @@ static odp_queue_t queue_create(const char *name,
                                queue->s.status = QUEUE_STATUS_READY;
 
                        handle = queue->s.handle;
-                       UNLOCK(&queue->s.lock);
+                       UNLOCK(queue);
                        break;
                }
-               UNLOCK(&queue->s.lock);
+               UNLOCK(queue);
        }
 
        if (handle != ODP_QUEUE_INVALID && type == ODP_QUEUE_TYPE_SCHED) {
@@ -247,13 +247,13 @@ void sched_cb_queue_destroy_finalize(uint32_t queue_index)
 {
        queue_entry_t *queue = get_qentry(queue_index);
 
-       LOCK(&queue->s.lock);
+       LOCK(queue);
 
        if (queue->s.status == QUEUE_STATUS_DESTROYED) {
                queue->s.status = QUEUE_STATUS_FREE;
                sched_fn->destroy_queue(queue_index);
        }
-       UNLOCK(&queue->s.lock);
+       UNLOCK(queue);
 }
 
 static int queue_destroy(odp_queue_t handle)
@@ -264,19 +264,19 @@ static int queue_destroy(odp_queue_t handle)
        if (handle == ODP_QUEUE_INVALID)
                return -1;
 
-       LOCK(&queue->s.lock);
+       LOCK(queue);
        if (queue->s.status == QUEUE_STATUS_FREE) {
-               UNLOCK(&queue->s.lock);
+               UNLOCK(queue);
                ODP_ERR("queue \"%s\" already free\n", queue->s.name);
                return -1;
        }
        if (queue->s.status == QUEUE_STATUS_DESTROYED) {
-               UNLOCK(&queue->s.lock);
+               UNLOCK(queue);
                ODP_ERR("queue \"%s\" already destroyed\n", queue->s.name);
                return -1;
        }
        if (ring_st_is_empty(&queue->s.ring_st) == 0) {
-               UNLOCK(&queue->s.lock);
+               UNLOCK(queue);
                ODP_ERR("queue \"%s\" not empty\n", queue->s.name);
                return -1;
        }
@@ -296,7 +296,7 @@ static int queue_destroy(odp_queue_t handle)
        default:
                ODP_ABORT("Unexpected queue status\n");
        }
-       UNLOCK(&queue->s.lock);
+       UNLOCK(queue);
 
        return 0;
 }
@@ -326,13 +326,13 @@ static odp_queue_t queue_lookup(const char *name)
                    queue->s.status == QUEUE_STATUS_DESTROYED)
                        continue;
 
-               LOCK(&queue->s.lock);
+               LOCK(queue);
                if (strcmp(name, queue->s.name) == 0) {
                        /* found it */
-                       UNLOCK(&queue->s.lock);
+                       UNLOCK(queue);
                        return queue->s.handle;
                }
-               UNLOCK(&queue->s.lock);
+               UNLOCK(queue);
        }
 
        return ODP_QUEUE_INVALID;
@@ -376,10 +376,10 @@ static inline int enq_multi(queue_t q_int, 
odp_buffer_hdr_t *buf_hdr[],
 
        buffer_index_from_buf(buf_idx, buf_hdr, num);
 
-       LOCK(&queue->s.lock);
+       LOCK(queue);
 
        if (odp_unlikely(queue->s.status < QUEUE_STATUS_READY)) {
-               UNLOCK(&queue->s.lock);
+               UNLOCK(queue);
                ODP_ERR("Bad queue status\n");
                return -1;
        }
@@ -387,7 +387,7 @@ static inline int enq_multi(queue_t q_int, odp_buffer_hdr_t 
*buf_hdr[],
        num_enq = ring_st_enq_multi(ring_st, buf_idx, num);
 
        if (odp_unlikely(num_enq == 0)) {
-               UNLOCK(&queue->s.lock);
+               UNLOCK(queue);
                return 0;
        }
 
@@ -396,7 +396,7 @@ static inline int enq_multi(queue_t q_int, odp_buffer_hdr_t 
*buf_hdr[],
                sched = 1;
        }
 
-       UNLOCK(&queue->s.lock);
+       UNLOCK(queue);
 
        /* Add queue to scheduling */
        if (sched && sched_fn->sched_queue(queue->s.index))
@@ -455,12 +455,12 @@ static inline int deq_multi(queue_entry_t *queue, 
odp_buffer_hdr_t *buf_hdr[],
 
        ring_st = &queue->s.ring_st;
 
-       LOCK(&queue->s.lock);
+       LOCK(queue);
 
        if (odp_unlikely(queue->s.status < QUEUE_STATUS_READY)) {
                /* Bad queue, or queue has been destroyed.
                 * Scheduler finalizes queue destroy after this. */
-               UNLOCK(&queue->s.lock);
+               UNLOCK(queue);
                return -1;
        }
 
@@ -475,7 +475,7 @@ static inline int deq_multi(queue_entry_t *queue, 
odp_buffer_hdr_t *buf_hdr[],
                                sched_fn->unsched_queue(queue->s.index);
                }
 
-               UNLOCK(&queue->s.lock);
+               UNLOCK(queue);
 
                return 0;
        }
@@ -483,7 +483,7 @@ static inline int deq_multi(queue_entry_t *queue, 
odp_buffer_hdr_t *buf_hdr[],
        if (status_sync && queue->s.type == ODP_QUEUE_TYPE_SCHED)
                sched_fn->save_context(queue->s.index);
 
-       UNLOCK(&queue->s.lock);
+       UNLOCK(queue);
 
        buffer_index_to_buf(buf_hdr, buf_idx, num_deq);
 
@@ -596,12 +596,12 @@ static int queue_info(odp_queue_t handle, 
odp_queue_info_t *info)
 
        queue = get_qentry(queue_id);
 
-       LOCK(&queue->s.lock);
+       LOCK(queue);
        status = queue->s.status;
 
        if (odp_unlikely(status == QUEUE_STATUS_FREE ||
                         status == QUEUE_STATUS_DESTROYED)) {
-               UNLOCK(&queue->s.lock);
+               UNLOCK(queue);
                ODP_ERR("Invalid queue status:%d\n", status);
                return -1;
        }
@@ -609,7 +609,7 @@ static int queue_info(odp_queue_t handle, odp_queue_info_t 
*info)
        info->name = queue->s.name;
        info->param = queue->s.param;
 
-       UNLOCK(&queue->s.lock);
+       UNLOCK(queue);
 
        return 0;
 }
@@ -626,11 +626,11 @@ int sched_cb_queue_empty(uint32_t queue_index)
        queue_entry_t *queue = get_qentry(queue_index);
        int ret = 0;
 
-       LOCK(&queue->s.lock);
+       LOCK(queue);
 
        if (odp_unlikely(queue->s.status < QUEUE_STATUS_READY)) {
                /* Bad queue, or queue has been destroyed. */
-               UNLOCK(&queue->s.lock);
+               UNLOCK(queue);
                return -1;
        }
 
@@ -642,7 +642,7 @@ int sched_cb_queue_empty(uint32_t queue_index)
                ret = 1;
        }
 
-       UNLOCK(&queue->s.lock);
+       UNLOCK(queue);
 
        return ret;
 }

Reply via email to