VPP-API client: timeout thread loop variable 38/13738/1
authorNeale Ranns <neale.ranns@cisco.com>
Thu, 26 Jul 2018 15:05:53 +0000 (08:05 -0700)
committerNeale Ranns <neale.ranns@cisco.com>
Thu, 26 Jul 2018 15:05:57 +0000 (08:05 -0700)
calling thread cancel on the timeout thread whilst it was
sleep on condwait and then send the cond signal did not reliably
wake up the thread.
instead don;t cancel the thread, use a loop variable to terminate it.

Change-Id: Ibc8ab6f21db7e4a98266bdf88b8b208b887820dd
Signed-off-by: Neale Ranns <neale.ranns@cisco.com>
src/vpp-api/client/client.c

index f1488e2..16c980e 100644 (file)
@@ -62,6 +62,7 @@ typedef struct {
   pthread_cond_t suspend_cv;
   pthread_cond_t resume_cv;
   pthread_mutex_t timeout_lock;
+  u8 timeout_loop;
   pthread_cond_t timeout_cv;
   pthread_cond_t timeout_cancel_cv;
   pthread_cond_t terminate_cv;
@@ -115,6 +116,7 @@ init (void)
   pthread_cond_init(&pm->suspend_cv, NULL);
   pthread_cond_init(&pm->resume_cv, NULL);
   pthread_mutex_init(&pm->timeout_lock, NULL);
+  pm->timeout_loop = 1;
   pthread_cond_init(&pm->timeout_cv, NULL);
   pthread_cond_init(&pm->timeout_cancel_cv, NULL);
   pthread_cond_init(&pm->terminate_cv, NULL);
@@ -234,7 +236,7 @@ vac_timeout_thread_fn (void *arg)
   u16 timeout;
   int rv;
 
-  while (1)
+  while (pm->timeout_loop)
     {
       /* Wait for poke */
       pthread_mutex_lock(&pm->timeout_lock);
@@ -402,7 +404,8 @@ vac_disconnect (void)
   }
   if (pm->timeout_thread_handle) {
     /* cancel, wake then join the timeout thread */
-    pthread_cancel(pm->timeout_thread_handle);
+    clib_warning("vac_disconnect cnacel");
+    pm->timeout_loop = 0;
     set_timeout(0);
     pthread_join(pm->timeout_thread_handle, (void **) &junk);
   }