vls_main_t *vlsm;
+static pthread_key_t vls_mt_pthread_stop_key;
+
typedef enum
{
VLS_RPC_STATE_INIT,
/* Only allow new pthread to be cancled in vls_mt_mq_lock */
if (vlsl->vls_mt_n_threads >= 2)
pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, NULL);
+
+ if (pthread_setspecific (vls_mt_pthread_stop_key, vcl_worker_get_current ()))
+ VDBG (0, "failed to setup key value");
+}
+
+static void
+vls_mt_del (void *arg)
+{
+ vcl_worker_t *wrk = (vcl_worker_t *) arg;
+
+ VDBG (0, "vls worker %u vcl worker %u nthreads %u cleaning up pthread",
+ vlsl->vls_wrk_index, vcl_get_worker_index (), vlsl->vls_mt_n_threads);
+
+ if (wrk != vcl_worker_get_current ())
+ {
+ VDBG (0, "vls_mt_del called with wrong worker %u != %u", wrk->wrk_index,
+ vcl_get_worker_index ());
+ return;
+ }
+
+ vlsl->vls_mt_n_threads -= 1;
+
+ if (vls_mt_wrk_supported ())
+ {
+ vppcom_worker_unregister ();
+ }
+ else
+ {
+ if (!vlsl->vls_mt_n_threads)
+ vppcom_worker_unregister ();
+ }
}
static inline void
{
int rv;
+ if (pthread_key_create (&vls_mt_pthread_stop_key, vls_mt_del))
+ {
+ VDBG (0, "failed to add pthread cleanup function");
+ return -1;
+ }
+
if ((rv = vppcom_app_create (app_name)))
return rv;
vls_worker_alloc ();
vlsl->vls_wrk_index = vcl_get_worker_index ();
vlsl->vls_mt_n_threads = 1;
+ if (pthread_setspecific (vls_mt_pthread_stop_key, vcl_worker_get_current ()))
+ VDBG (0, "failed to setup key value");
clib_rwlock_init (&vlsl->vls_pool_lock);
vls_mt_locks_init ();
vcm->wrk_rpc_fn = vls_rpc_handler;
#include <vcl/vcl_private.h>
-static pthread_key_t vcl_worker_stop_key;
-
vcl_mq_evt_conn_t *
vcl_mq_evt_conn_alloc (vcl_worker_t * wrk)
{
clib_spinlock_unlock (&vcm->workers_lock);
}
-static void
-vcl_worker_cleanup_cb (void *arg)
-{
- vcl_worker_t *wrk;
- u32 wrk_index;
-
- wrk_index = vcl_get_worker_index ();
- wrk = vcl_worker_get_if_valid (wrk_index);
- if (!wrk)
- return;
-
- vcl_worker_cleanup (wrk, 1 /* notify vpp */ );
- vcl_set_worker_index (~0);
- VDBG (0, "cleaned up worker %u", wrk_index);
-}
-
void
vcl_worker_detached_start_signal_mq (vcl_worker_t *wrk)
{
clib_spinlock_unlock (&vcm->workers_lock);
return -1;
}
- if (pthread_key_create (&vcl_worker_stop_key, vcl_worker_cleanup_cb))
- VDBG (0, "failed to add pthread cleanup function");
- if (pthread_setspecific (vcl_worker_stop_key, &wrk->thread_id))
- VDBG (0, "failed to setup key value");
clib_spinlock_unlock (&vcm->workers_lock);