diff --git a/src/backends/native/meta-thread-impl.c b/src/backends/native/meta-thread-impl.c index 4355e3cad..763233739 100644 --- a/src/backends/native/meta-thread-impl.c +++ b/src/backends/native/meta-thread-impl.c @@ -56,6 +56,8 @@ typedef struct _MetaThreadImplPrivate GMainContext *thread_context; GSource *impl_source; GAsyncQueue *task_queue; + + gboolean is_realtime; } MetaThreadImplPrivate; struct _MetaThreadTask @@ -551,7 +553,8 @@ meta_thread_impl_dispatch (MetaThreadImpl *thread_impl) } void -meta_thread_impl_run (MetaThreadImpl *thread_impl) +meta_thread_impl_run (MetaThreadImpl *thread_impl, + MetaThreadImplRunFlags flags) { MetaThreadImplPrivate *priv = meta_thread_impl_get_instance_private (thread_impl); @@ -559,7 +562,9 @@ meta_thread_impl_run (MetaThreadImpl *thread_impl) meta_assert_in_thread_impl (priv->thread); priv->loop = g_main_loop_new (priv->thread_context, FALSE); + priv->is_realtime = !!(flags & META_THREAD_IMPL_RUN_FLAG_REALTIME); g_main_loop_run (priv->loop); + priv->is_realtime = FALSE; } void @@ -572,3 +577,12 @@ meta_thread_impl_queue_task (MetaThreadImpl *thread_impl, g_async_queue_push (priv->task_queue, task); g_main_context_wakeup (priv->thread_context); } + +gboolean +meta_thread_impl_is_realtime (MetaThreadImpl *thread_impl) +{ + MetaThreadImplPrivate *priv = + meta_thread_impl_get_instance_private (thread_impl); + + return priv->is_realtime; +} diff --git a/src/backends/native/meta-thread-impl.h b/src/backends/native/meta-thread-impl.h index 0a8c2c2ef..4d36949eb 100644 --- a/src/backends/native/meta-thread-impl.h +++ b/src/backends/native/meta-thread-impl.h @@ -27,6 +27,12 @@ typedef struct _MetaThread MetaThread; +typedef enum _MetaThreadImplRunFlags +{ + META_THREAD_IMPL_RUN_FLAG_NONE = 0, + META_THREAD_IMPL_RUN_FLAG_REALTIME = 1 << 0, +} MetaThreadImplRunFlags; + #define META_TYPE_THREAD_IMPL (meta_thread_impl_get_type ()) META_EXPORT_TEST G_DECLARE_DERIVABLE_TYPE (MetaThreadImpl, meta_thread_impl, @@ -67,12 +73,16 @@ void meta_thread_impl_queue_task (MetaThreadImpl *thread_impl, void meta_thread_impl_terminate (MetaThreadImpl *thread_impl); -void meta_thread_impl_run (MetaThreadImpl *thread_impl); +void meta_thread_impl_run (MetaThreadImpl *thread_impl, + MetaThreadImplRunFlags flags); int meta_thread_impl_dispatch (MetaThreadImpl *thread_impl); gboolean meta_thread_impl_is_in_impl (MetaThreadImpl *thread_impl); +META_EXPORT_TEST +gboolean meta_thread_impl_is_realtime (MetaThreadImpl *thread_impl); + MetaThreadTask * meta_thread_task_new (MetaThreadTaskFunc func, gpointer user_data, GDestroyNotify user_data_destroy, diff --git a/src/backends/native/meta-thread.c b/src/backends/native/meta-thread.c index bc192b42a..5ca35b7da 100644 --- a/src/backends/native/meta-thread.c +++ b/src/backends/native/meta-thread.c @@ -296,6 +296,7 @@ thread_impl_func (gpointer user_data) MetaThreadPrivate *priv = meta_thread_get_instance_private (thread); MetaContext *context = meta_backend_get_context (priv->backend); MetaThreadImpl *impl = priv->impl; + MetaThreadImplRunFlags run_flags = META_THREAD_IMPL_RUN_FLAG_NONE; #ifdef HAVE_PROFILER GMainContext *thread_context = meta_thread_impl_get_main_context (impl); MetaProfiler *profiler = meta_context_get_profiler (context); @@ -320,10 +321,11 @@ thread_impl_func (gpointer user_data) else { g_message ("Made thread '%s' realtime scheduled", priv->name); + run_flags |= META_THREAD_IMPL_RUN_FLAG_REALTIME; } } - meta_thread_impl_run (impl); + meta_thread_impl_run (impl, run_flags); #ifdef HAVE_PROFILER meta_profiler_unregister_thread (profiler, thread_context); diff --git a/src/tests/native-thread.c b/src/tests/native-thread.c index 2596b1418..2be9c0acc 100644 --- a/src/tests/native-thread.c +++ b/src/tests/native-thread.c @@ -1152,6 +1152,8 @@ assert_realtime (MetaThreadImpl *thread_impl, g_autoptr (GVariant) priority_variant = NULL; uint32_t priority = 0; + g_assert_true (meta_thread_impl_is_realtime (thread_impl)); + ret = call_rtkit_mock_method ("GetThreadPriority", g_variant_new ("(t)", gettid ())); @@ -1199,6 +1201,8 @@ assert_no_realtime (MetaThreadImpl *thread_impl, g_autoptr (GVariant) priority_variant = NULL; uint32_t priority = UINT32_MAX; + g_assert_false (meta_thread_impl_is_realtime (thread_impl)); + ret = call_rtkit_mock_method ("GetThreadPriority", g_variant_new ("(t)", gettid ()));