Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gnome-vfs/ChangeLog,v
retrieving revision 1.1334.2.8
diff -u -p -r1.1334.2.8 ChangeLog
--- ChangeLog	21 Jun 2002 17:39:23 -0000	1.1334.2.8
+++ ChangeLog	25 Jun 2002 18:43:52 -0000
@@ -1,3 +1,19 @@
+2002-06-25  Damon Chaplin  <damon@ximian.com>
+
+	* libgnomevfs/gnome-vfs-async-job-map.c (gnome_vfs_async_job_map_init):
+	initialize the async_job_callback_map_lock mutex here, instead of in
+	gnome_vfs_async_job_add_callback(), so we can use it even when
+	async_job_callback_map is NULL.
+	(gnome_vfs_async_job_add_callback): lock the above mutex before
+	checking & creating the async_job_callback_map hash table, to avoid
+	a tiny race condition.
+	(gnome_vfs_async_job_cancel_job_and_callbacks): lock the above mutex
+	first and set job->cancelled. Previously it was just returning if
+	async_job_callback_map was NULL, which meant that job->cancelled
+	didn't get set.
+	(async_job_callback_map_destroy): don't destroy the
+	async_job_callback_map_lock mutex here. We keep it around forever.
+
 2002-06-21  Stephen Browne <stephen.browne@sun.com>
 
 	* modules/cdemenu-desktop-method.c (find_all_included_files): fix for
Index: libgnomevfs/gnome-vfs-async-job-map.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-async-job-map.c,v
retrieving revision 1.7
diff -u -p -r1.7 gnome-vfs-async-job-map.c
--- libgnomevfs/gnome-vfs-async-job-map.c	3 Aug 2001 19:03:53 -0000	1.7
+++ libgnomevfs/gnome-vfs-async-job-map.c	25 Jun 2002 18:43:52 -0000
@@ -44,6 +44,7 @@ void 
 gnome_vfs_async_job_map_init (void)
 {
 	gnome_vfs_pthread_recursive_mutex_init (&async_job_map_lock);
+	pthread_mutex_init (&async_job_callback_map_lock, NULL);
 }
 
 GnomeVFSJob *
@@ -206,15 +207,13 @@ gnome_vfs_async_job_add_callback (GnomeV
 
 	JOB_DEBUG (("adding callback %d ", notify_result->callback_id));
 
-	/* FIXME potential startup race here! */
+	pthread_mutex_lock (&async_job_callback_map_lock);
+	
 	if (async_job_callback_map == NULL) {
 		/* First job, allocate a new hash table. */
 		async_job_callback_map = g_hash_table_new (NULL, NULL);
-		pthread_mutex_init (&async_job_callback_map_lock, NULL);
 	}
 
-	pthread_mutex_lock (&async_job_callback_map_lock);
-	
 	/* we are using async_job_callback_map_lock to ensure atomicity of
 	 * checking/clearing job->cancelled and adding/cancelling callbacks
 	 */
@@ -258,20 +257,20 @@ callback_map_cancel_one (gpointer key, g
 void
 gnome_vfs_async_job_cancel_job_and_callbacks (GnomeVFSAsyncHandle *job_handle, GnomeVFSJob *job)
 {
-	if (async_job_callback_map == NULL) {
-		JOB_DEBUG (("job %u, no callbacks scheduled yet",
-			    GPOINTER_TO_UINT (job_handle)));
-		return;
-	}
-
 	pthread_mutex_lock (&async_job_callback_map_lock);
 	
 	if (job != NULL) {
 		job->cancelled = TRUE;
 	}
 	
-	g_hash_table_foreach (async_job_callback_map,
-		callback_map_cancel_one, job_handle);
+	if (async_job_callback_map == NULL) {
+		JOB_DEBUG (("job %u, no callbacks scheduled yet",
+			    GPOINTER_TO_UINT (job_handle)));
+	} else {
+		g_hash_table_foreach (async_job_callback_map,
+				      callback_map_cancel_one, job_handle);
+	}
+
 	pthread_mutex_unlock (&async_job_callback_map_lock);
 }
 
@@ -284,5 +283,4 @@ async_job_callback_map_destroy (void)
 	g_hash_table_destroy (async_job_callback_map);
 	async_job_callback_map = NULL;
 	pthread_mutex_unlock (&async_job_callback_map_lock);
-	pthread_mutex_destroy (&async_job_callback_map_lock);
 }
