X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvcl%2Fvcl_private.c;h=d159a49a89cffd212fa581984ced5eee40bb3e52;hb=9f3b14e311155cb9beb43d6d4f9f775c6be4b187;hp=f997c23aee2c9a7a7f054e3d3bf0423094a82454;hpb=134a996a0279577080b626d5172c1739efa00b92;p=vpp.git diff --git a/src/vcl/vcl_private.c b/src/vcl/vcl_private.c index f997c23aee2..d159a49a89c 100644 --- a/src/vcl/vcl_private.c +++ b/src/vcl/vcl_private.c @@ -15,7 +15,7 @@ #include -pthread_key_t vcl_worker_stop_key; +static pthread_key_t vcl_worker_stop_key; static const char * vppcom_app_state_str (app_state_t state) @@ -246,6 +246,13 @@ vcl_worker_alloc_and_init () if (vcl_get_worker_index () != ~0) return 0; + if (pool_elts (vcm->workers) == vcm->cfg.max_workers) + { + VDBG (0, "max-workers %u limit reached", vcm->cfg.max_workers); + return 0; + } + + clib_spinlock_lock (&vcm->workers_lock); wrk = vcl_worker_alloc (); vcl_set_worker_index (wrk->wrk_index); @@ -267,12 +274,15 @@ vcl_worker_alloc_and_init () vec_validate (wrk->mq_events, 64); vec_validate (wrk->mq_msg_vector, 128); vec_reset_length (wrk->mq_msg_vector); + vec_validate (wrk->unhandled_evts_vector, 128); + vec_reset_length (wrk->unhandled_evts_vector); if (wrk->wrk_index == 0) - return wrk; + { + clib_spinlock_unlock (&vcm->workers_lock); + return wrk; + } - while (vcm->app_state == STATE_APP_ADDING_WORKER) - ; vcm->app_state = STATE_APP_ADDING_WORKER; vcl_send_app_worker_add_del (1 /* is_add */ ); if (vcl_wait_for_app_state_change (STATE_APP_READY)) @@ -283,6 +293,11 @@ vcl_worker_alloc_and_init () if (pthread_key_create (&vcl_worker_stop_key, vcl_worker_cleanup)) clib_warning ("failed to add pthread cleanup function"); + if (pthread_setspecific (vcl_worker_stop_key, &wrk->thread_id)) + clib_warning ("failed to setup key value"); + wrk->thread_id = pthread_self (); + + clib_spinlock_unlock (&vcm->workers_lock); VDBG (0, "added worker %u", wrk->wrk_index);