aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXiaoming Jiang <jiangxiaoming@outlook.com>2021-07-13 03:55:59 +0000
committerFlorin Coras <florin.coras@gmail.com>2021-07-14 14:33:56 +0000
commit405debc101b20de31eda179955f7babad285cc8f (patch)
tree27949f01ff781ae63c7a794541534c0df58bdbd4
parent5cac2e819472e1723b65373f80bfd05e5cfc9996 (diff)
api: fix memory error in multi-thread environment
When reading vm->pending_rpc_requests in main thread, the content may be changed by other workers. Type: fix Signed-off-by: Xiaoming Jiang <jiangxiaoming@outlook.com> Change-Id: I27e9d357b5ecec0f97cd8b950019b35f72fc5f76
-rw-r--r--src/vlibmemory/memory_api.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/vlibmemory/memory_api.c b/src/vlibmemory/memory_api.c
index f229ecf48bd..4287bd36e5f 100644
--- a/src/vlibmemory/memory_api.c
+++ b/src/vlibmemory/memory_api.c
@@ -65,6 +65,7 @@ memclnt_queue_callback (vlib_main_t * vm)
{
int i;
api_main_t *am = vlibapi_get_main ();
+ int have_pending_rpcs;
if (PREDICT_FALSE (vec_len (vl_api_queue_cursizes) !=
1 + vec_len (am->vlib_private_rps)))
@@ -103,7 +104,12 @@ memclnt_queue_callback (vlib_main_t * vm)
break;
}
}
- if (vec_len (vm->pending_rpc_requests))
+
+ clib_spinlock_lock_if_init (&vm->pending_rpc_lock);
+ have_pending_rpcs = vec_len (vm->pending_rpc_requests) > 0;
+ clib_spinlock_unlock_if_init (&vm->pending_rpc_lock);
+
+ if (have_pending_rpcs)
{
vm->queue_signal_pending = 1;
vm->api_queue_nonempty = 1;