libpurple/network.c

changeset 33900
f4924591ef06
parent 33894
7e3ea8475aad
child 34820
7a89045601ae
--- a/libpurple/network.c	Thu Apr 18 00:12:59 2013 +0200
+++ b/libpurple/network.c	Thu Apr 18 01:50:30 2013 +0200
@@ -85,7 +85,12 @@
 static int current_network_count;
 
 /* Mutex for the other global vars */
+#if GLIB_CHECK_VERSION(2, 32, 0)
+static GMutex mutex;
+#else
 static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
+#endif
+
 static gboolean network_initialized = FALSE;
 static HANDLE network_change_handle = NULL;
 static int (WSAAPI *MyWSANSPIoctl) (
@@ -700,11 +705,19 @@
 		WSACOMPLETION completion;
 		WSAOVERLAPPED overlapped;
 
+#if GLIB_CHECK_VERSION(2, 32, 0)
+		g_mutex_lock(&mutex);
+#else
 		g_static_mutex_lock(&mutex);
+#endif
 		if (network_initialized == FALSE) {
 			/* purple_network_uninit has been called */
 			WSACloseEvent(nla_event);
+#if GLIB_CHECK_VERSION(2, 32, 0)
+			g_mutex_unlock(&mutex);
+#else
 			g_static_mutex_unlock(&mutex);
+#endif
 			g_thread_exit(NULL);
 			return NULL;
 		}
@@ -722,13 +735,21 @@
 													msg, errorid));
 				g_free(msg);
 				WSACloseEvent(nla_event);
+#if GLIB_CHECK_VERSION(2, 32, 0)
+				g_mutex_unlock(&mutex);
+#else
 				g_static_mutex_unlock(&mutex);
+#endif
 				g_thread_exit(NULL);
 				return NULL;
 			}
 		}
+#if GLIB_CHECK_VERSION(2, 32, 0)
+		g_mutex_unlock(&mutex);
+#else
 		g_static_mutex_unlock(&mutex);
-
+#endif
+		
 		memset(&completion, 0, sizeof(WSACOMPLETION));
 		completion.Type = NSP_NOTIFY_EVENT;
 		overlapped.hEvent = nla_event;
@@ -739,10 +760,18 @@
 			if (errorid == WSA_INVALID_HANDLE) {
 				purple_timeout_add(0, _print_debug_msg,
 								   g_strdup("Invalid NLA handle; resetting.\n"));
+#if GLIB_CHECK_VERSION(2, 32, 0)
+				g_mutex_lock(&mutex);
+#else
 				g_static_mutex_lock(&mutex);
+#endif
 				retval = WSALookupServiceEnd(network_change_handle);
 				network_change_handle = NULL;
+#if GLIB_CHECK_VERSION(2, 32, 0)
+				g_mutex_unlock(&mutex);
+#else
 				g_static_mutex_unlock(&mutex);
+#endif
 				continue;
 			/* WSA_IO_PENDING indicates successful async notification will happen */
 			} else if (errorid != WSA_IO_PENDING) {
@@ -764,11 +793,19 @@
 
 		last_trigger = time(NULL);
 
+#if GLIB_CHECK_VERSION(2, 32, 0)
+		g_mutex_lock(&mutex);
+#else
 		g_static_mutex_lock(&mutex);
+#endif
 		if (network_initialized == FALSE) {
 			/* Time to die */
 			WSACloseEvent(nla_event);
+#if GLIB_CHECK_VERSION(2, 32, 0)
+			g_mutex_unlock(&mutex);
+#else
 			g_static_mutex_unlock(&mutex);
+#endif
 			g_thread_exit(NULL);
 			return NULL;
 		}
@@ -782,7 +819,11 @@
 		}
 
 		WSAResetEvent(nla_event);
+#if GLIB_CHECK_VERSION(2, 32, 0)
+		g_mutex_unlock(&mutex);
+#else
 		g_static_mutex_unlock(&mutex);
+#endif
 
 		purple_timeout_add(0, wpurple_network_change_thread_cb, NULL);
 	}
@@ -1214,7 +1255,11 @@
 #endif
 
 #ifdef _WIN32
+#if GLIB_CHECK_VERSION(2, 32, 0)
+	g_mutex_lock(&mutex);
+#else
 	g_static_mutex_lock(&mutex);
+#endif
 	network_initialized = FALSE;
 	if (network_change_handle != NULL) {
 		int retval;
@@ -1231,7 +1276,11 @@
 		network_change_handle = NULL;
 
 	}
+#if GLIB_CHECK_VERSION(2, 32, 0)
+	g_mutex_unlock(&mutex);
+#else
 	g_static_mutex_unlock(&mutex);
+#endif
 
 #endif
 	purple_signal_unregister(purple_network_get_handle(),

mercurial