polling in the inotify code



In response to Ryans finding, I wrote a small patch
to address the first part of the polling-in-inotify
problem in gnome-vfs. This patch has not been tested 
at all, but it looks correct to me.

Matthias
Index: inotify-missing.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/modules/inotify-missing.c,v
retrieving revision 1.3
diff -u -p -r1.3 inotify-missing.c
--- inotify-missing.c	20 Dec 2005 03:50:01 -0000	1.3
+++ inotify-missing.c	27 Jul 2006 14:32:06 -0000
@@ -39,6 +39,7 @@ static gboolean     im_debug_enabled = F
 static GList *missing_sub_list = NULL;
 static gboolean im_scan_missing (gpointer user_data);
 static void (*missing_cb)(ih_sub_t *sub) = NULL;
+static guint timout_id = 0;
 
 G_LOCK_EXTERN (inotify_lock);
 
@@ -50,7 +51,6 @@ void im_startup (void (*callback)(ih_sub
 	if (!initialized) {
 		initialized = TRUE;
 		missing_cb = callback;
-		g_timeout_add (SCAN_MISSING_TIME, im_scan_missing, NULL);
 	}
 }
 
@@ -64,6 +64,11 @@ void im_add (ih_sub_t *sub)
 
 	IM_W("adding %s to missing list\n", sub->dirname);
 	missing_sub_list = g_list_prepend (missing_sub_list, sub);
+	if (timeout_id == 0) {
+		IM_W("start missing timeout\n");
+		timout_id = g_timeout_add (SCAN_MISSING_TIME, 
+					   im_scan_missing, NULL);
+	}
 }
 
 /* inotify_lock must be held before calling */
@@ -82,6 +87,12 @@ void im_rm (ih_sub_t *sub)
 
 	missing_sub_list = g_list_remove_link (missing_sub_list, link);
 	g_list_free_1 (link);
+
+	if (missing_sub_list == NULL && timeout_id != 0) {
+		IM_W("stop missing timeout\n");
+		g_source_remove (timeout_id);
+		timeout_id = 0;
+	}
 }
 
 /* Scans the list of missing subscriptions checking if they
@@ -126,7 +137,13 @@ static gboolean im_scan_missing (gpointe
 	g_list_free (nolonger_missing);
 
 	G_UNLOCK(inotify_lock);
-	return TRUE;
 
+	if (missing_sub_list == NULL) {
+		IM_W("stop missing timeout\n");
+		timeout_id = 0;
+		return FALSE;
+	}
+	
+	return TRUE;
 }
 


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