summaryrefslogtreecommitdiff
path: root/egg
diff options
context:
space:
mode:
authorStef Walter <stefw@collabora.co.uk>2011-12-06 16:49:39 +0100
committerStef Walter <stefw@collabora.co.uk>2011-12-07 11:43:47 +0100
commitbde64e94f83a6da4eaff6503744e200c9f1f0081 (patch)
tree54abfc92ef0b1acca156e9d69bbdd131dd1d1a40 /egg
parent592ab2513d0738deaa7078c0fdf73bf0f4005a5f (diff)
downloadgnome-keyring-bde64e94f83a6da4eaff6503744e200c9f1f0081.tar.gz
Fix for deprecations in glib 2.31.x
* Mainly g_mutex_new/g_mutex_free g_cond_new/g_cond_free * Since we like to build with the last stable version of glib, using #ifdef until these glib changes make it into a stable release.
Diffstat (limited to 'egg')
-rw-r--r--egg/egg-libgcrypt.c10
-rw-r--r--egg/egg-testing.c90
2 files changed, 82 insertions, 18 deletions
diff --git a/egg/egg-libgcrypt.c b/egg/egg-libgcrypt.c
index e5b3f558..63411639 100644
--- a/egg/egg-libgcrypt.c
+++ b/egg/egg-libgcrypt.c
@@ -56,14 +56,24 @@ fatal_handler (gpointer unused, int unknown, const gchar *msg)
static int
glib_thread_mutex_init (void **lock)
{
+#if GLIB_CHECK_VERSION(2,31,3)
+ *lock = g_new0 (GMutex, 1);
+ g_mutex_init (*lock);
+#else
*lock = g_mutex_new ();
+#endif
return 0;
}
static int
glib_thread_mutex_destroy (void **lock)
{
+#if GLIB_CHECK_VERSION(2,31,3)
+ g_mutex_clear (*lock);
+ g_free (*lock);
+#else
g_mutex_free (*lock);
+#endif
return 0;
}
diff --git a/egg/egg-testing.c b/egg/egg-testing.c
index 0235ac09..0269af6e 100644
--- a/egg/egg-testing.c
+++ b/egg/egg-testing.c
@@ -28,9 +28,16 @@
#include <errno.h>
#include <unistd.h>
+#if GLIB_CHECK_VERSION(2,31,3)
+static GCond wait_condition;
+static GCond wait_start;
+static GMutex wait_mutex;
+#else
static GCond *wait_condition = NULL;
static GCond *wait_start = NULL;
static GMutex *wait_mutex = NULL;
+#endif
+
static gboolean wait_waiting = FALSE;
static const char HEXC[] = "0123456789ABCDEF";
@@ -82,40 +89,73 @@ egg_assertion_message_cmpmem (const char *domain,
void
egg_test_wait_stop (void)
{
- GTimeVal tv;
-
- g_get_current_time (&tv);
- g_time_val_add (&tv, 1000);
-
+#if GLIB_CHECK_VERSION(2,31,3)
+ g_mutex_lock (&wait_mutex);
+#else
g_assert (wait_mutex);
g_assert (wait_condition);
g_mutex_lock (wait_mutex);
- if (!wait_waiting)
- g_cond_timed_wait (wait_start, wait_mutex, &tv);
- g_assert (wait_waiting);
- g_cond_broadcast (wait_condition);
+#endif
+
+ if (!wait_waiting) {
+#if GLIB_CHECK_VERSION(2,31,3)
+ gint64 time = g_get_monotonic_time () + 1 * G_TIME_SPAN_SECOND;
+ g_cond_wait_until (&wait_start, &wait_mutex, time);
+#else
+ GTimeVal tv;
+ g_get_current_time (&tv);
+ g_time_val_add (&tv, 1000);
+ g_cond_timed_wait (wait_start, wait_mutex, &tv);
+#endif
+ }
+ g_assert (wait_waiting);
+
+#if GLIB_CHECK_VERSION(2,31,3)
+ g_cond_broadcast (&wait_condition);
+ g_mutex_unlock (&wait_mutex);
+#else
+ g_cond_broadcast (wait_condition);
g_mutex_unlock (wait_mutex);
+#endif
}
gboolean
egg_test_wait_until (int timeout)
{
- GTimeVal tv;
gboolean ret;
- g_get_current_time (&tv);
- g_time_val_add (&tv, timeout * 1000);
-
+#if GLIB_CHECK_VERSION(2,31,3)
+ g_mutex_lock (&wait_mutex);
+#else
g_assert (wait_mutex);
g_assert (wait_condition);
g_mutex_lock (wait_mutex);
- g_assert (!wait_waiting);
- wait_waiting = TRUE;
+#endif
+
+ g_assert (!wait_waiting);
+ wait_waiting = TRUE;
+
+ {
+#if GLIB_CHECK_VERSION(2,31,3)
+ gint64 time = g_get_monotonic_time () + ((timeout + 1000) * G_TIME_SPAN_MILLISECOND);
+ g_cond_broadcast (&wait_start);
+ ret = g_cond_wait_until (&wait_start, &wait_mutex, time);
+#else
+ GTimeVal tv;
+ g_get_current_time (&tv);
+ g_time_val_add (&tv, timeout * 1000);
g_cond_broadcast (wait_start);
ret = g_cond_timed_wait (wait_condition, wait_mutex, &tv);
- g_assert (wait_waiting);
- wait_waiting = FALSE;
+#endif
+ }
+
+ g_assert (wait_waiting);
+ wait_waiting = FALSE;
+#if GLIB_CHECK_VERSION(2,31,3)
+ g_mutex_unlock (&wait_mutex);
+#else
g_mutex_unlock (wait_mutex);
+#endif
return ret;
}
@@ -136,22 +176,36 @@ egg_tests_run_in_thread_with_loop (void)
GMainLoop *loop;
gpointer ret;
+#if !GLIB_CHECK_VERSION(2,31,3)
g_thread_init (NULL);
+#endif
loop = g_main_loop_new (NULL, FALSE);
+#if GLIB_CHECK_VERSION(2,31,3)
+ g_cond_init (&wait_condition);
+ g_cond_init (&wait_start);
+ g_mutex_init (&wait_mutex);
+ thread = g_thread_new ("testing", testing_thread, loop);
+#else
wait_condition = g_cond_new ();
wait_start = g_cond_new ();
wait_mutex = g_mutex_new ();
-
thread = g_thread_create (testing_thread, loop, TRUE, NULL);
+#endif
+
g_assert (thread);
g_main_loop_run (loop);
ret = g_thread_join (thread);
g_main_loop_unref (loop);
+#if GLIB_CHECK_VERSION(2,31,2)
+ g_cond_clear (&wait_condition);
+ g_mutex_clear (&wait_mutex);
+#else
g_cond_free (wait_condition);
g_mutex_free (wait_mutex);
+#endif
return GPOINTER_TO_INT (ret);
}