port: add eventdev port type
[dpdk.git] / lib / librte_eventdev / rte_event_ring.c
index b14c212..50190de 100644 (file)
@@ -1,33 +1,5 @@
-/*-
- *   BSD LICENSE
- *
- *   Copyright(c) 2017 Intel Corporation. All rights reserved.
- *
- *   Redistribution and use in source and binary forms, with or without
- *   modification, are permitted provided that the following conditions
- *   are met:
- *
- *     * Redistributions of source code must retain the above copyright
- *       notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright
- *       notice, this list of conditions and the following disclaimer in
- *       the documentation and/or other materials provided with the
- *       distribution.
- *     * Neither the name of Intel Corporation nor the names of its
- *       contributors may be used to endorse or promote products derived
- *       from this software without specific prior written permission.
- *
- *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2017 Intel Corporation
  */
 
 #include <sys/queue.h>
@@ -100,7 +72,7 @@ rte_event_ring_create(const char *name, unsigned int count, int socket_id,
                return NULL;
        }
 
-       rte_rwlock_write_lock(RTE_EAL_TAILQ_RWLOCK);
+       rte_mcfg_tailq_write_lock();
 
        /*
         * reserve a memory zone for this ring. If we can't get rte_config or
@@ -110,11 +82,16 @@ rte_event_ring_create(const char *name, unsigned int count, int socket_id,
        mz = rte_memzone_reserve(mz_name, ring_size, socket_id, mz_flags);
        if (mz != NULL) {
                r = mz->addr;
-               /*
-                * no need to check return value here, we already checked the
-                * arguments above
-                */
-               rte_event_ring_init(r, name, requested_count, flags);
+               /* Check return value in case rte_ring_init() fails on size */
+               int err = rte_event_ring_init(r, name, requested_count, flags);
+               if (err) {
+                       RTE_LOG(ERR, RING, "Ring init failed\n");
+                       if (rte_memzone_free(mz) != 0)
+                               RTE_LOG(ERR, RING, "Cannot free memzone\n");
+                       rte_free(te);
+                       rte_mcfg_tailq_write_unlock();
+                       return NULL;
+               }
 
                te->data = (void *) r;
                r->r.memzone = mz;
@@ -125,7 +102,7 @@ rte_event_ring_create(const char *name, unsigned int count, int socket_id,
                RTE_LOG(ERR, RING, "Cannot reserve memory\n");
                rte_free(te);
        }
-       rte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK);
+       rte_mcfg_tailq_write_unlock();
 
        return r;
 }
@@ -141,7 +118,7 @@ rte_event_ring_lookup(const char *name)
        ring_list = RTE_TAILQ_CAST(rte_event_ring_tailq.head,
                        rte_event_ring_list);
 
-       rte_rwlock_read_lock(RTE_EAL_TAILQ_RWLOCK);
+       rte_mcfg_tailq_read_lock();
 
        TAILQ_FOREACH(te, ring_list, next) {
                r = (struct rte_event_ring *) te->data;
@@ -149,7 +126,7 @@ rte_event_ring_lookup(const char *name)
                        break;
        }
 
-       rte_rwlock_read_unlock(RTE_EAL_TAILQ_RWLOCK);
+       rte_mcfg_tailq_read_unlock();
 
        if (te == NULL) {
                rte_errno = ENOENT;
@@ -186,7 +163,7 @@ rte_event_ring_free(struct rte_event_ring *r)
 
        ring_list = RTE_TAILQ_CAST(rte_event_ring_tailq.head,
                        rte_event_ring_list);
-       rte_rwlock_write_lock(RTE_EAL_TAILQ_RWLOCK);
+       rte_mcfg_tailq_write_lock();
 
        /* find out tailq entry */
        TAILQ_FOREACH(te, ring_list, next) {
@@ -195,13 +172,13 @@ rte_event_ring_free(struct rte_event_ring *r)
        }
 
        if (te == NULL) {
-               rte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK);
+               rte_mcfg_tailq_write_unlock();
                return;
        }
 
        TAILQ_REMOVE(ring_list, te, next);
 
-       rte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK);
+       rte_mcfg_tailq_write_unlock();
 
        rte_free(te);
 }