#include <vcl/vcl_private.h>
-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)
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);
vec_reset_length (wrk->mq_msg_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))
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);