diff options
author | Dan Winship <danw@gnome.org> | 2011-11-30 21:59:55 +0100 |
---|---|---|
committer | Dan Winship <danw@gnome.org> | 2011-12-01 11:09:21 +0100 |
commit | 60a4fd63d411fb5b12cfd9e27b111b0ec476a87f (patch) | |
tree | 6003d1b0378ad18a6fe2fc2f953cbac17aee749e /tests | |
parent | 9afab51d38c0c7d75ce0fb50902b729f1450bbd3 (diff) | |
download | libsoup-60a4fd63d411fb5b12cfd9e27b111b0ec476a87f.tar.gz libsoup-60a4fd63d411fb5b12cfd9e27b111b0ec476a87f.tar.bz2 libsoup-60a4fd63d411fb5b12cfd9e27b111b0ec476a87f.zip |
Require glib 2.31 and update to new thread APIs
Diffstat (limited to 'tests')
-rw-r--r-- | tests/context-test.c | 30 | ||||
-rw-r--r-- | tests/misc-test.c | 15 | ||||
-rw-r--r-- | tests/requester-test.c | 5 | ||||
-rw-r--r-- | tests/test-utils.c | 3 |
4 files changed, 22 insertions, 31 deletions
diff --git a/tests/context-test.c b/tests/context-test.c index c1884de7..673ae215 100644 --- a/tests/context-test.c +++ b/tests/context-test.c @@ -97,8 +97,8 @@ server_callback (SoupServer *server, SoupMessage *msg, static gboolean idle_start_test1_thread (gpointer loop); static gpointer test1_thread (gpointer user_data); -static GCond *test1_cond; -static GMutex *test1_mutex; +static GCond test1_cond; +static GMutex test1_mutex; static GMainLoop *test1_loop; static void @@ -110,37 +110,31 @@ do_test1 (int n, gboolean use_thread_context) else debug_printf (1, "(Using SOUP_SESSION_ASYNC_CONTEXT)\n"); - test1_cond = g_cond_new (); - test1_mutex = g_mutex_new (); - test1_loop = g_main_loop_new (NULL, FALSE); g_idle_add (idle_start_test1_thread, GINT_TO_POINTER (use_thread_context)); g_main_loop_run (test1_loop); g_main_loop_unref (test1_loop); - - g_mutex_free (test1_mutex); - g_cond_free (test1_cond); } static gboolean idle_start_test1_thread (gpointer use_thread_context) { - GTimeVal time; + guint64 time; GThread *thread; - g_mutex_lock (test1_mutex); - thread = g_thread_create (test1_thread, use_thread_context, TRUE, NULL); + g_mutex_lock (&test1_mutex); + thread = g_thread_new ("test1_thread", test1_thread, use_thread_context); - g_get_current_time (&time); - time.tv_sec += 5; - if (g_cond_timed_wait (test1_cond, test1_mutex, &time)) + time = g_get_monotonic_time () + 5000000; + if (g_cond_wait_until (&test1_cond, &test1_mutex, time)) g_thread_join (thread); else { debug_printf (1, " timeout!\n"); + g_thread_unref (thread); errors++; } - g_mutex_unlock (test1_mutex); + g_mutex_unlock (&test1_mutex); g_main_loop_quit (test1_loop); return FALSE; } @@ -161,8 +155,8 @@ test1_thread (gpointer use_thread_context) GMainLoop *loop; /* Wait for main thread to be waiting on test1_cond */ - g_mutex_lock (test1_mutex); - g_mutex_unlock (test1_mutex); + g_mutex_lock (&test1_mutex); + g_mutex_unlock (&test1_mutex); async_context = g_main_context_new (); if (use_thread_context) { @@ -206,7 +200,7 @@ test1_thread (gpointer use_thread_context) soup_test_session_abort_unref (session); g_free (uri); - g_cond_signal (test1_cond); + g_cond_signal (&test1_cond); if (use_thread_context) g_main_context_pop_thread_default (async_context); diff --git a/tests/misc-test.c b/tests/misc-test.c index 907e3386..495c33f5 100644 --- a/tests/misc-test.c +++ b/tests/misc-test.c @@ -20,7 +20,7 @@ SoupServer *server; SoupURI *base_uri; -GMutex *server_mutex; +GMutex server_mutex; static gboolean auth_callback (SoupAuthDomain *auth_domain, SoupMessage *msg, @@ -122,8 +122,8 @@ server_callback (SoupServer *server, SoupMessage *msg, * need to hold it through the whole function, so it's simpler * to just release it right away. */ - g_mutex_lock (server_mutex); - g_mutex_unlock (server_mutex); + g_mutex_lock (&server_mutex); + g_mutex_unlock (&server_mutex); soup_message_headers_append (msg->response_headers, "X-Handled-By", "server_callback"); @@ -826,7 +826,7 @@ static int msgs_done; static gboolean idle_start_server (gpointer data) { - g_mutex_unlock (server_mutex); + g_mutex_unlock (&server_mutex); return FALSE; } @@ -861,7 +861,7 @@ do_max_conns_test_for_session (SoupSession *session) max_conns_loop = g_main_loop_new (NULL, TRUE); - g_mutex_lock (server_mutex); + g_mutex_lock (&server_mutex); g_signal_connect (session, "request-started", G_CALLBACK (max_conns_request_started), NULL); @@ -973,7 +973,7 @@ do_cancel_while_reading_test_for_session (SoupSession *session) if (SOUP_IS_SESSION_ASYNC (session)) g_timeout_add (100, cancel_message_timeout, msg); else - thread = g_thread_create (cancel_message_thread, msg, TRUE, NULL); + thread = g_thread_new ("cancel_message_thread", cancel_message_thread, msg); soup_session_send_message (session, msg); @@ -1013,8 +1013,6 @@ main (int argc, char **argv) test_init (argc, argv, NULL); - server_mutex = g_mutex_new (); - server = soup_test_server_new (TRUE); soup_server_add_handler (server, NULL, server_callback, NULL, NULL); base_uri = soup_uri_new ("http://127.0.0.1/"); @@ -1041,7 +1039,6 @@ main (int argc, char **argv) soup_uri_free (base_uri); soup_test_server_quit_unref (server); - g_mutex_free (server_mutex); test_cleanup (); return errors != 0; diff --git a/tests/requester-test.c b/tests/requester-test.c index 2c578afd..c5565405 100644 --- a/tests/requester-test.c +++ b/tests/requester-test.c @@ -185,8 +185,9 @@ do_thread_test (const char *uri) debug_printf (1, "Streaming in another thread\n"); - thread = g_thread_create ((GThreadFunc)do_test_with_context, - (gpointer)uri, TRUE, NULL); + thread = g_thread_new ("do_test_with_context", + (GThreadFunc)do_test_with_context, + (gpointer)uri); g_thread_join (thread); } diff --git a/tests/test-utils.c b/tests/test-utils.c index 05eaba0a..47f1db01 100644 --- a/tests/test-utils.c +++ b/tests/test-utils.c @@ -296,8 +296,7 @@ test_server_new (gboolean in_own_thread, gboolean ssl) if (in_own_thread) { GThread *thread; - thread = g_thread_create (run_server_thread, server, - TRUE, NULL); + thread = g_thread_new ("server_thread", run_server_thread, server); g_object_set_data (G_OBJECT (server), "thread", thread); } else soup_server_run_async (server); |