mirror of
https://github.com/brl/mutter.git
synced 2025-02-16 21:34:09 +00:00
tests/thread: Test multiple queued tasks
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
This commit is contained in:
parent
aa723e7207
commit
069bee0ce8
@ -235,6 +235,101 @@ async_feedback_func (gpointer retval,
|
||||
g_mutex_unlock (&async_data->mutex);
|
||||
}
|
||||
|
||||
static gpointer
|
||||
multiple_async_func1 (MetaThreadImpl *thread_impl,
|
||||
gpointer user_data,
|
||||
GError **error)
|
||||
{
|
||||
AsyncData *async_data = user_data;
|
||||
|
||||
meta_assert_in_thread_impl (async_data->thread);
|
||||
|
||||
g_mutex_lock (&async_data->mutex);
|
||||
g_assert_cmpint (async_data->state, ==, 0);
|
||||
async_data->state = 1;
|
||||
g_mutex_unlock (&async_data->mutex);
|
||||
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Sample error");
|
||||
return GINT_TO_POINTER (1);
|
||||
}
|
||||
|
||||
static void
|
||||
multiple_async_feedback_func1 (gpointer retval,
|
||||
const GError *error,
|
||||
gpointer user_data)
|
||||
{
|
||||
AsyncData *async_data = user_data;
|
||||
|
||||
meta_assert_not_in_thread_impl (async_data->thread);
|
||||
|
||||
g_assert_true (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_FAILED));
|
||||
g_assert_cmpint (GPOINTER_TO_INT (retval), ==, 1);
|
||||
}
|
||||
|
||||
static gpointer
|
||||
multiple_async_func2 (MetaThreadImpl *thread_impl,
|
||||
gpointer user_data,
|
||||
GError **error)
|
||||
{
|
||||
AsyncData *async_data = user_data;
|
||||
|
||||
meta_assert_in_thread_impl (async_data->thread);
|
||||
|
||||
g_mutex_lock (&async_data->mutex);
|
||||
g_assert_cmpint (async_data->state, ==, 1);
|
||||
async_data->state = 2;
|
||||
g_mutex_unlock (&async_data->mutex);
|
||||
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "Sample error");
|
||||
return GINT_TO_POINTER (2);
|
||||
}
|
||||
|
||||
static void
|
||||
multiple_async_feedback_func2 (gpointer retval,
|
||||
const GError *error,
|
||||
gpointer user_data)
|
||||
{
|
||||
AsyncData *async_data = user_data;
|
||||
|
||||
meta_assert_not_in_thread_impl (async_data->thread);
|
||||
|
||||
g_assert_true (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED));
|
||||
g_assert_cmpint (GPOINTER_TO_INT (retval), ==, 2);
|
||||
}
|
||||
|
||||
static gpointer
|
||||
multiple_async_func3 (MetaThreadImpl *thread_impl,
|
||||
gpointer user_data,
|
||||
GError **error)
|
||||
{
|
||||
AsyncData *async_data = user_data;
|
||||
|
||||
meta_assert_in_thread_impl (async_data->thread);
|
||||
|
||||
g_mutex_lock (&async_data->mutex);
|
||||
g_assert_cmpint (async_data->state, ==, 2);
|
||||
async_data->state = 3;
|
||||
g_mutex_unlock (&async_data->mutex);
|
||||
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_CONNECTED, "Sample error");
|
||||
return GINT_TO_POINTER (3);
|
||||
}
|
||||
|
||||
static void
|
||||
multiple_async_feedback_func3 (gpointer retval,
|
||||
const GError *error,
|
||||
gpointer user_data)
|
||||
{
|
||||
AsyncData *async_data = user_data;
|
||||
|
||||
meta_assert_not_in_thread_impl (async_data->thread);
|
||||
|
||||
g_assert_true (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_CONNECTED));
|
||||
g_assert_cmpint (GPOINTER_TO_INT (retval), ==, 3);
|
||||
|
||||
g_main_loop_quit (async_data->loop);
|
||||
}
|
||||
|
||||
static void
|
||||
run_thread_tests (MetaThread *thread)
|
||||
{
|
||||
@ -315,6 +410,28 @@ run_thread_tests (MetaThread *thread)
|
||||
g_mutex_unlock (&async_data.mutex);
|
||||
g_main_loop_unref (async_data.loop);
|
||||
g_mutex_clear (&async_data.mutex);
|
||||
|
||||
/* Multiple async tasks */
|
||||
g_debug ("Test multiple async tasks");
|
||||
async_data = (AsyncData) { 0 };
|
||||
g_mutex_init (&async_data.mutex);
|
||||
async_data.thread = thread;
|
||||
async_data.loop = g_main_loop_new (NULL, FALSE);
|
||||
g_mutex_lock (&async_data.mutex);
|
||||
meta_thread_post_impl_task (thread, multiple_async_func1, &async_data,
|
||||
multiple_async_feedback_func1, &async_data);
|
||||
meta_thread_post_impl_task (thread, multiple_async_func2, &async_data,
|
||||
multiple_async_feedback_func2, &async_data);
|
||||
meta_thread_post_impl_task (thread, multiple_async_func3, &async_data,
|
||||
multiple_async_feedback_func3, &async_data);
|
||||
g_assert_cmpint (async_data.state, ==, 0);
|
||||
g_mutex_unlock (&async_data.mutex);
|
||||
g_main_loop_run (async_data.loop);
|
||||
g_mutex_lock (&async_data.mutex);
|
||||
g_assert_cmpint (async_data.state, ==, 3);
|
||||
g_mutex_unlock (&async_data.mutex);
|
||||
g_main_loop_unref (async_data.loop);
|
||||
g_mutex_clear (&async_data.mutex);
|
||||
}
|
||||
|
||||
static void
|
||||
|
Loading…
x
Reference in New Issue
Block a user