[brasero] Don't let anything (except a final unref) interrupt the initial thread that initializes the drive ca



commit 9c322edfa61ae76ebdee69f920099976e7a757bc
Author: Philippe Rouquier <bonfire-app wanadoo fr>
Date:   Thu Oct 15 13:23:26 2009 +0200

    Don't let anything (except a final unref) interrupt the initial thread that initializes the drive capabilities
    Suppress a warning
    Make sure that whenever we restart a probe thread we have the cancelled variable properly initialize

 libbrasero-media/brasero-drive.c |   30 ++++++++++++++++++++++++------
 1 files changed, 24 insertions(+), 6 deletions(-)
---
diff --git a/libbrasero-media/brasero-drive.c b/libbrasero-media/brasero-drive.c
index 9915dc5..faa9b98 100644
--- a/libbrasero-media/brasero-drive.c
+++ b/libbrasero-media/brasero-drive.c
@@ -55,6 +55,7 @@
 #include "brasero-volume.h"
 #include "brasero-drive.h"
 
+#include "brasero-drive-priv.h"
 #include "scsi-device.h"
 #include "scsi-utils.h"
 #include "scsi-spc1.h"
@@ -87,6 +88,9 @@ struct _BraseroDrivePrivate
 
 	GCancellable *cancel;
 
+	guint initial_probe:1;
+	guint initial_probe_cancelled:1;
+
 	guint probed:1;
 	guint has_medium:1;
 	guint probe_cancelled:1;
@@ -208,6 +212,7 @@ brasero_drive_cancel_probing (BraseroDrive *drive)
 	if (priv->probe) {
 		/* This to signal that we are cancelling */
 		priv->probe_cancelled = TRUE;
+		priv->initial_probe_cancelled = TRUE;
 
 		/* This is to wake up the thread if it
 		 * was asleep waiting to retry to get
@@ -1027,6 +1032,11 @@ brasero_drive_probe_inside (BraseroDrive *drive)
 
 	priv = BRASERO_DRIVE_PRIVATE (drive);
 
+	if (priv->initial_probe) {
+		BRASERO_MEDIA_LOG ("Still initializing the drive properties");
+		return;
+	}
+
 	/* Check that a probe is not already being performed */
 	if (priv->probe) {
 		BRASERO_MEDIA_LOG ("Ongoing probe");
@@ -1035,14 +1045,17 @@ brasero_drive_probe_inside (BraseroDrive *drive)
 
 	BRASERO_MEDIA_LOG ("Setting new probe");
 
+	g_mutex_lock (priv->mutex);
+
 	priv->probed = FALSE;
 	priv->probe_waiting = FALSE;
+	priv->probe_cancelled = FALSE;
 
-	g_mutex_lock (priv->mutex);
 	priv->probe = g_thread_create (brasero_drive_probe_inside_thread,
 	                               drive,
 				       FALSE,
 				       NULL);
+
 	g_mutex_unlock (priv->mutex);
 }
 
@@ -1170,7 +1183,9 @@ brasero_drive_probed (gpointer data)
 	if (!g_mutex_trylock (priv->mutex))
 		return TRUE;
 
+	priv->initial_probe = FALSE;
 	priv->probe_id = 0;
+
 	g_mutex_unlock (priv->mutex);
 
 	brasero_drive_probe_inside (BRASERO_DRIVE (data));
@@ -1252,7 +1267,7 @@ brasero_drive_get_caps_profiles (BraseroDrive *self,
 				break;
 		}
 
-		if (priv->probe_cancelled)
+		if (priv->initial_probe_cancelled)
 			break;
 
 		/* Move the pointer to the next features */
@@ -1325,7 +1340,7 @@ brasero_drive_probe_thread (gpointer data)
 	while (!handle && counter <= BRASERO_DRIVE_OPEN_ATTEMPTS) {
 		sleep (1);
 
-		if (priv->probe_cancelled) {
+		if (priv->initial_probe_cancelled) {
 			BRASERO_MEDIA_LOG ("Open () cancelled");
 			goto end;
 		}
@@ -1334,7 +1349,7 @@ brasero_drive_probe_thread (gpointer data)
 		handle = brasero_device_handle_open (device, FALSE, &code);
 	}
 
-	if (priv->probe_cancelled) {
+	if (priv->initial_probe_cancelled) {
 		BRASERO_MEDIA_LOG ("Open () cancelled");
 		goto end;
 	}
@@ -1365,7 +1380,7 @@ brasero_drive_probe_thread (gpointer data)
 		                   &wait_time);
 		g_mutex_unlock (priv->mutex);
 
-		if (priv->probe_cancelled) {
+		if (priv->initial_probe_cancelled) {
 			brasero_device_handle_close (handle);
 			BRASERO_MEDIA_LOG ("Device probing cancelled");
 			goto end;
@@ -1414,7 +1429,7 @@ end:
 
 	g_mutex_lock (priv->mutex);
 
-	if (!priv->probe_cancelled)
+	if (!priv->initial_probe_cancelled)
 		priv->probe_id = g_idle_add (brasero_drive_probed, drive);
 
 	priv->probe = NULL;
@@ -1452,10 +1467,13 @@ brasero_drive_init_real_device (BraseroDrive *drive,
 	 * BraseroDrive that exported until it returns PROBED signal.
 	 * One (good) side effect is that it also improves start time. */
 	g_mutex_lock (priv->mutex);
+
+	priv->initial_probe = TRUE;
 	priv->probe = g_thread_create (brasero_drive_probe_thread,
 				       drive,
 				       FALSE,
 				       NULL);
+
 	g_mutex_unlock (priv->mutex);
 }
 



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