[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH 1/3] Revert "Wait up to 5 seconds for running threads to complete before exiting."



This reverts commit 63f0eb0889c8f8a82ba06a02a8a92d695902baad.
---
 src/internal.h    |  3 ---
 src/main.c        | 13 -------------
 src/threadlocal.c | 35 -----------------------------------
 3 files changed, 51 deletions(-)

diff --git a/src/internal.h b/src/internal.h
index b98be3d..1fc5d69 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -182,9 +182,6 @@ extern size_t threadlocal_get_instance_num (void);
 extern void threadlocal_set_error (int err);
 extern int threadlocal_get_error (void);
 /*extern void threadlocal_get_sockaddr ();*/
-extern size_t get_running_threads (void);
-extern void incr_running_threads (void);
-extern void decr_running_threads (void);
 
 /* Declare program_name. */
 #if HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME == 1
diff --git a/src/main.c b/src/main.c
index 6ab556f..c9f08ab 100644
--- a/src/main.c
+++ b/src/main.c
@@ -189,7 +189,6 @@ main (int argc, char *argv[])
   int option_index;
   int help = 0, version = 0, dump_plugin = 0;
   int tls_set_on_cli = 0;
-  size_t count;
 
   threadlocal_init ();
 
@@ -492,12 +491,6 @@ main (int argc, char *argv[])
 
   start_serving ();
 
-  /* Wait, but not forever, for all threads to complete. */
-  debug ("waiting for running threads to complete");
-  for (count = 0; count < 5 && get_running_threads (); ++count)
-    sleep (1);
-  debug ("waited %zus for running threads to complete", count);
-
   plugin_cleanup ();
 
   free (unixsocket);
@@ -643,12 +636,6 @@ start_serving (void)
     threadlocal_new_server_thread ();
     if (handle_single_connection (0, 1) == -1)
       exit (EXIT_FAILURE);
-    /* When handling a single connection we reuse the main thread as
-     * the server thread.  We don't want to count it as a running
-     * thread, but it hasn't called pthread_exit(), so we need to
-     * explicitly decrement the running threads here.
-     */
-    decr_running_threads ();
     return;
   }
 
diff --git a/src/threadlocal.c b/src/threadlocal.c
index cc19d48..d6e3942 100644
--- a/src/threadlocal.c
+++ b/src/threadlocal.c
@@ -71,8 +71,6 @@ free_threadlocal (void *threadlocalv)
 
   free (threadlocal->addr);
   free (threadlocal);
-
-  decr_running_threads ();
 }
 
 void
@@ -93,8 +91,6 @@ threadlocal_new_server_thread (void)
 {
   struct threadlocal *threadlocal;
 
-  incr_running_threads ();
-
   threadlocal = calloc (1, sizeof *threadlocal);
   if (threadlocal == NULL) {
     perror ("malloc");
@@ -181,34 +177,3 @@ threadlocal_get_error (void)
   errno = err;
   return threadlocal ? threadlocal->err : 0;
 }
-
-/* These functions keep track of the number of running threads. */
-static pthread_mutex_t running_threads_lock = PTHREAD_MUTEX_INITIALIZER;
-static size_t running_threads = 0;
-
-size_t
-get_running_threads (void)
-{
-  size_t r;
-
-  pthread_mutex_lock (&running_threads_lock);
-  r = running_threads;
-  pthread_mutex_unlock (&running_threads_lock);
-  return r;
-}
-
-void
-incr_running_threads (void)
-{
-  pthread_mutex_lock (&running_threads_lock);
-  running_threads++;
-  pthread_mutex_unlock (&running_threads_lock);
-}
-
-void
-decr_running_threads (void)
-{
-  pthread_mutex_lock (&running_threads_lock);
-  running_threads--;
-  pthread_mutex_unlock (&running_threads_lock);
-}
-- 
2.13.2


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]