summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2021-09-23 15:08:05 -0700
committerFlorin Coras <florin.coras@gmail.com>2021-09-24 16:37:13 +0000
commitc1931b2f0932d29f3ea73452b497a3d05eca9352 (patch)
tree8963f345557557c50de76f6c061530a656167ea4 /src
parentfd9d936b3c58d914f5ee5eccf14739d1d3b35e2c (diff)
vcl: grab wrk create lock soonerv21.10-rc2
Type: fix Signed-off-by: Florin Coras <fcoras@cisco.com> Change-Id: I0faeef20c57486564122e39f01f31c8c45f38014 (cherry picked from commit 94fef3e67662c6a92e32164d8db6fcf4bc83e79e)
Diffstat (limited to 'src')
-rw-r--r--src/vcl/vcl_private.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/vcl/vcl_private.c b/src/vcl/vcl_private.c
index 8f8ebf9d2e8..3cbf02532cd 100644
--- a/src/vcl/vcl_private.c
+++ b/src/vcl/vcl_private.c
@@ -167,16 +167,19 @@ vcl_worker_alloc_and_init ()
if (vcl_get_worker_index () != ~0)
return 0;
+ /* Grab lock before selecting mem thread index */
+ clib_spinlock_lock (&vcm->workers_lock);
+
/* Use separate heap map entry for worker */
clib_mem_set_thread_index ();
if (pool_elts (vcm->workers) == vcm->cfg.max_workers)
{
VDBG (0, "max-workers %u limit reached", vcm->cfg.max_workers);
- return 0;
+ wrk = 0;
+ goto done;
}
- clib_spinlock_lock (&vcm->workers_lock);
wrk = vcl_worker_alloc ();
vcl_set_worker_index (wrk->wrk_index);
wrk->thread_id = pthread_self ();
@@ -203,9 +206,9 @@ vcl_worker_alloc_and_init ()
vec_reset_length (wrk->mq_msg_vector);
vec_validate (wrk->unhandled_evts_vector, 128);
vec_reset_length (wrk->unhandled_evts_vector);
- clib_spinlock_unlock (&vcm->workers_lock);
done:
+ clib_spinlock_unlock (&vcm->workers_lock);
return wrk;
}