]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: threads: Define the sync-point inside run_poll_loop
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 19 Oct 2017 09:59:44 +0000 (11:59 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 31 Oct 2017 12:58:29 +0000 (13:58 +0100)
The function sync_poll_loop is called at the end of each loop inside
run_poll_loop function. It is a protected area where all threads have a chance
to execute tricky tasks with the warranty that no concurrent access is
possible. Of course, it comes with a cost because all threads must be
syncrhonized. So changes must be uncommon.

src/haproxy.c

index c145639508de9797ae229e3a5d8683160504ab17..080cb6f01a1f330f59de8179cf9c8d03cbad3bfe 100644 (file)
@@ -2203,6 +2203,26 @@ void deinit(void)
 } /* end deinit() */
 
 
+
+static void sync_poll_loop()
+{
+       if (THREAD_NO_SYNC())
+               return;
+
+       THREAD_ENTER_SYNC();
+
+       if (!THREAD_NEED_SYNC())
+               goto exit;
+
+       /* *** { */
+       /* Put here all sync functions */
+
+
+       /* *** } */
+  exit:
+       THREAD_EXIT_SYNC();
+}
+
 /* Runs the polling loop */
 static void run_poll_loop()
 {
@@ -2234,6 +2254,10 @@ static void run_poll_loop()
 
                /* Commit server status changes */
                servers_update_status();
+
+               /* Synchronize all polling loops */
+               sync_poll_loop();
+
        }
 }
 
@@ -2254,6 +2278,7 @@ static void *run_thread_poll_loop(void *data)
                }
        }
 
+       THREAD_SYNC_ENABLE();
        run_poll_loop();
 
        list_for_each_entry(ptdf, &per_thread_deinit_list, list)
@@ -2787,6 +2812,7 @@ int main(int argc, char **argv)
                pthread_t    *threads = calloc(global.nbthread, sizeof(pthread_t));
                int          i;
 
+               THREAD_SYNC_INIT((1UL << global.nbthread) - 1);
                for (i = 0; i < global.nbthread; i++) {
                        tids[i] = i;
                        pthread_create(&threads[i], NULL, &run_thread_poll_loop, &tids[i]);