adium 4032:05c0fc8e80aa: Don't try to use the src after it has b...

commits at adium.im commits at adium.im
Mon Jun 27 11:37:15 UTC 2011


details:	http://hg.adium.im/adium/rev/05c0fc8e80aa
revision:	4032:05c0fc8e80aa
branch:		(none)
author:		Thijs Alkemade <thijsalkemade at gmail.com>
date:		Mon Jun 27 13:37:05 2011 +0200

Don't try to use the src after it has been released. Add some more comments to the GCD eventloop.

diffs (55 lines):

diff -r ae24b8d1c83a -r 05c0fc8e80aa Plugins/Purple Service/adiumPurpleEventloop.m
--- a/Plugins/Purple Service/adiumPurpleEventloop.m	Mon Jun 27 13:19:17 2011 +0200
+++ b/Plugins/Purple Service/adiumPurpleEventloop.m	Mon Jun 27 13:37:05 2011 +0200
@@ -23,6 +23,9 @@
 
 #include <dispatch/dispatch.h>
 
+// This one is missing from the headers...
+#define NSEC_PER_MSEC (NSEC_PER_SEC / 1000)
+
 //#define PURPLE_SOCKET_DEBUG
 
 static guint				sourceId = 0;		//The next source key; continuously incrementing
@@ -45,11 +48,14 @@
 	
 	dispatch_source_t src = (dispatch_source_t)[srcPointer pointerValue];
     dispatch_source_cancel(src);
-    dispatch_release(src);
+    
+	BOOL success = (dispatch_source_testcancel(src) != 0);
+	
+	dispatch_release(src);
 	
     [sourceInfoDict removeObjectForKey:[NSNumber numberWithUnsignedInt:tag]];
 
-	return (dispatch_source_testcancel(src) != 0);
+	return success;
 }
 
 //Like g_source_remove, return TRUE if successful, FALSE if not
@@ -57,6 +63,9 @@
     return adium_source_remove(tag);
 }
 
+/* Extra function to generalize adium_timeout_add and adium_timeout_add_seconds,
+ * making the permitted leeway explicit.
+ */
 guint addTimer(uint64_t interval, uint64_t leeway, GSourceFunc function, gpointer data)
 {
 	dispatch_source_t src;
@@ -87,11 +96,13 @@
     return tag;
 }
 
+// Add a timer in miliseconds
 guint adium_timeout_add(guint interval, GSourceFunc function, gpointer data)
 {
-	return addTimer(((uint64_t)interval) * (NSEC_PER_SEC / 1000), NSEC_PER_USEC, function, data);
+	return addTimer(((uint64_t)interval) * NSEC_PER_MSEC, NSEC_PER_USEC, function, data);
 }
 
+// Add a timer in seconds (allowing more leeway, therefore allowing the OS to group events and save power)
 guint adium_timeout_add_seconds(guint interval, GSourceFunc function, gpointer data)
 {
 	return addTimer(((uint64_t)interval) * NSEC_PER_SEC, NSEC_PER_SEC, function, data);




More information about the commits mailing list