static void wait_for_async()
{
- GMainContext *context = g_main_context_new();
- GSource *source = g_timeout_source_new(5000);
-
- /* attach source to context */
- g_source_attach (source, context);
-
- g_mainloop = g_main_loop_new(context, FALSE);
-
- /* set the callback for this source */
- g_source_set_callback (source, timeout_func, g_mainloop, NULL);
-
- g_main_loop_run(g_mainloop);
-
- /* after attaching with the GSource, destroy() is needed */
- g_source_destroy(source);
-
- /* unref the last reference we got for GSource */
- g_source_unref(source);
-
- /* main loop should be destroyed before unref the context */
- g_main_loop_unref(g_mainloop);
- g_main_context_unref(context);
+ int timeout_id;
+ g_mainloop = g_main_loop_new(NULL, FALSE);
+
+ timeout_id = g_timeout_add(5000, timeout_func, g_mainloop);
+ g_main_loop_run(g_mainloop);
+ g_source_remove(timeout_id);
+ g_main_loop_unref(g_mainloop);
+ g_mainloop = NULL;
}
/**