#include #include #include #include #include #include gboolean arv_make_realtime (void) { struct sched_param p; memset (&p, 0, sizeof(p)); p.sched_priority = 3; if (sched_setscheduler (0, SCHED_RR|SCHED_RESET_ON_FORK, &p) < 0 && errno == EPERM) { GDBusProxy *proxy; GVariant *answer; pid_t thread_id; GError *error = NULL; gint32 priority = p.sched_priority; thread_id = syscall(SYS_gettid); proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, NULL, "org.freedesktop.RealtimeKit1", "/org/freedesktop/RealtimeKit1", "org.freedesktop.RealtimeKit1", NULL, &error); if (error != NULL) { g_warning ("[::make_realtime] Failed to create dbus proxy (%s)", error->message); g_clear_pointer (&error, g_error_free); } answer = g_dbus_proxy_get_cached_property (proxy, "MaxRealtimePriority"); if (answer == NULL) { g_warning ("[::make_realtime] Failed to get MaxRealtimePriority"); } else { priority = g_variant_get_int32 (answer); g_variant_unref (answer); } answer = g_dbus_proxy_call_sync (proxy, "MakeThreadRealtime", g_variant_new ("(tu)", thread_id, priority), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (error != NULL) { g_warning ("[::make_realtime] Failed to set realtime scheduling using rtkit (%s)", error->message); g_clear_pointer (&error, g_error_free); } g_object_unref (proxy); if (answer != NULL) g_variant_unref (answer); else return FALSE; } return TRUE; } int main (int argc, char **argv) { arv_make_realtime (); }