/pidgin/main: f4924591ef06: Don't use deprecated threads API for...

Tomasz Wasilczyk tomkiewicz at cpw.pidgin.im
Wed Apr 17 19:50:38 EDT 2013


Changeset: f4924591ef06a377dc251a73f9703f8bffa87a7b
Author:	 Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date:	 2013-04-18 01:50 +0200
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/f4924591ef06

Description:

Don't use deprecated threads API for recent GLib versions

diffstat:

 libpurple/network.c |  51 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 libpurple/util.c    |  12 ++++++++++++
 2 files changed, 62 insertions(+), 1 deletions(-)

diffs (169 lines):

diff --git a/libpurple/network.c b/libpurple/network.c
--- a/libpurple/network.c
+++ b/libpurple/network.c
@@ -85,7 +85,12 @@ static gboolean have_nm_state = FALSE;
 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 @@ static gpointer wpurple_network_change_t
 		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 @@ static gpointer wpurple_network_change_t
 													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 @@ static gpointer wpurple_network_change_t
 			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 @@ static gpointer wpurple_network_change_t
 
 		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 @@ static gpointer wpurple_network_change_t
 		}
 
 		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 @@ purple_network_uninit(void)
 #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 @@ purple_network_uninit(void)
 		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(),
diff --git a/libpurple/util.c b/libpurple/util.c
--- a/libpurple/util.c
+++ b/libpurple/util.c
@@ -4328,7 +4328,11 @@ purple_utf8_strip_unprintables(const gch
 const gchar *
 purple_gai_strerror(gint errnum)
 {
+#if GLIB_CHECK_VERSION(2, 32, 0)
+	static GPrivate msg_private = G_PRIVATE_INIT(g_free);
+#else
 	static GStaticPrivate msg_private = G_STATIC_PRIVATE_INIT;
+#endif
 	char *msg;
 	int saved_errno = errno;
 
@@ -4356,11 +4360,19 @@ purple_gai_strerror(gint errnum)
 		}
 	}
 
+#if GLIB_CHECK_VERSION(2, 32, 0)
+	msg = g_private_get(&msg_private);
+#else
 	msg = g_static_private_get(&msg_private);
+#endif
 	if (!msg)
 	{
 		msg = g_new(gchar, 64);
+#if GLIB_CHECK_VERSION(2, 32, 0)
+		g_private_set(&msg_private, msg);
+#else
 		g_static_private_set(&msg_private, msg, g_free);
+#endif
 	}
 
 	sprintf(msg, "unknown error (%d)", errnum);



More information about the Commits mailing list