helper_thread: Introduce a function for blocking Unix signals
authorBart Van Assche <bvanassche@acm.org>
Sat, 12 Sep 2020 14:43:56 +0000 (07:43 -0700)
committerBart Van Assche <bvanassche@acm.org>
Sun, 20 Sep 2020 23:09:45 +0000 (16:09 -0700)
This patch reworks commit c31092b8ac06 ("Block signals for the helper
thread") but does not change any functionality.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
helper_thread.c

index c5ca23e0640197e07043697b0c3be125e6f78609..88937ade0decf9e9f6d6200879eee6a751543157 100644 (file)
@@ -83,6 +83,18 @@ static int read_from_pipe(int fd, void *buf, size_t len)
 }
 #endif
 
+static void block_signals(void)
+{
+#ifdef HAVE_PTHREAD_SIGMASK
+       sigset_t sigmask;
+
+       ret = pthread_sigmask(SIG_UNBLOCK, NULL, &sigmask);
+       assert(ret == 0);
+       ret = pthread_sigmask(SIG_BLOCK, &sigmask, NULL);
+       assert(ret == 0);
+#endif
+}
+
 static void submit_action(enum action a)
 {
        const char data = a;
@@ -157,17 +169,8 @@ static void *helper_thread_main(void *data)
 
        sk_out_assign(hd->sk_out);
 
-#ifdef HAVE_PTHREAD_SIGMASK
-       {
-       sigset_t sigmask;
-
        /* Let another thread handle signals. */
-       ret = pthread_sigmask(SIG_UNBLOCK, NULL, &sigmask);
-       assert(ret == 0);
-       ret = pthread_sigmask(SIG_BLOCK, &sigmask, NULL);
-       assert(ret == 0);
-       }
-#endif
+       block_signals();
 
        fio_get_mono_time(&ts);
        memcpy(&last_du, &ts, sizeof(ts));