More cleanup (worker thread)



The nm_device_worker() thread within NetworkManagerDevice is checked for shutdown by polling worker_done repeatedly. This is a) inefficient, and b) doesn't ever clean up the GThread* and associated things properly. I've fixed this by using g_thread_join() to wait for completion instead. Patch attached.

Tom
--
palfrey tevp net - http://tevp.net
Illegitimus non carborundum
Index: src/NetworkManagerDevice.c
===================================================================
RCS file: /cvs/gnome/NetworkManager/src/NetworkManagerDevice.c,v
retrieving revision 1.121
diff -u -r1.121 NetworkManagerDevice.c
--- src/NetworkManagerDevice.c	6 Apr 2005 19:16:31 -0000	1.121
+++ src/NetworkManagerDevice.c	14 Apr 2005 14:13:32 -0000
@@ -381,7 +381,8 @@
 		nm_system_device_update_config_info (dev);
 	}
 
-	if (!g_thread_create (nm_device_worker, dev, FALSE, &error))
+	dev->worker = g_thread_create (nm_device_worker, dev, TRUE, &error);
+	if (!dev->worker)
 	{
 		nm_error ("could not create device worker thread. (glib said: '%s')", error->message);
 		g_error_free (error);
@@ -512,7 +513,6 @@
 	dev->loop = NULL;
 	dev->context = NULL;
 
-	dev->worker_done = TRUE;
 	nm_device_unref (dev);
 
 	return NULL;
@@ -525,9 +525,8 @@
 
 	if (dev->loop)
 		g_main_loop_quit (dev->loop);
-	nm_wait_for_completion(NM_COMPLETION_TRIES_INFINITY, 300,
-			nm_completion_boolean_test, NULL, &dev->worker_done,
-			NULL, NULL, 0);
+	g_thread_join(dev->worker);
+	dev->worker = NULL;
 }
 
 
Index: src/NetworkManagerDevicePrivate.h
===================================================================
RCS file: /cvs/gnome/NetworkManager/src/NetworkManagerDevicePrivate.h,v
retrieving revision 1.11
diff -u -r1.11 NetworkManagerDevicePrivate.h
--- src/NetworkManagerDevicePrivate.h	1 Apr 2005 21:30:12 -0000	1.11
+++ src/NetworkManagerDevicePrivate.h	14 Apr 2005 14:13:32 -0000
@@ -106,7 +106,7 @@
 
 	GMainContext			*context;
 	GMainLoop				*loop;
-	gboolean				 worker_done;
+	GThread					*worker;
 	gboolean				 worker_started;
 	guint		 		 renew_timeout;
 	guint				 rebind_timeout;


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