pidgin/android/libpurple

f4924591ef06
Parents df88eed08123
Children dc332f0b7318
Don't use deprecated threads API for recent GLib versions
--- 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(),
--- a/libpurple/util.c Thu Apr 18 00:12:59 2013 +0200
+++ b/libpurple/util.c Thu Apr 18 01:50:30 2013 +0200
@@ -4328,7 +4328,11 @@
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 @@
}
}
+#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);