vcl: improve handling of thread cancelation in vls 75/41975/3
authorFlorin Coras <[email protected]>
Sat, 7 Dec 2024 21:20:46 +0000 (16:20 -0500)
committerFlorin Coras <[email protected]>
Sat, 7 Dec 2024 21:27:22 +0000 (16:27 -0500)
Meant for multi-threaded applications that share a vls and vcl worker.
Disable thread cancelation on thread new thread detection and add a new
pthread cancelation point in vls_mt_mq_lock

Type: improvement

Change-Id: I21b16ee7c6a5ec31b8f6363325cc7ffa463c7b5c
Signed-off-by: Florin Coras <[email protected]>
src/vcl/vcl_locked.c

index bae1c0d..f8a306c 100644 (file)
@@ -301,11 +301,18 @@ vls_mt_add (void)
     }
   else
     vcl_set_worker_index (vlsl->vls_wrk_index);
+
+  /* Only allow new pthread to be cancled in vls_mt_mq_lock */
+  int old_state;
+  if (vlsl->vls_mt_n_threads >= 2)
+    pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &old_state);
 }
 
 static inline void
 vls_mt_mq_lock (void)
 {
+  /* Allow controlled cancelation of thread before grabbing mutex */
+  pthread_testcancel ();
   pthread_mutex_lock (&vlsl->vls_mt_mq_mlock);
 }