From 023103c620749fd5eb1956c255a9cc5fcd6903a4 Mon Sep 17 00:00:00 2001 From: Jose Maldonado aka Yukiteru Date: Fri, 9 Feb 2024 14:16:07 -0400 Subject: [PATCH] core: use pthread_setschedparam on OpenBSD OpenBSD don't have support for sched_getparam(), sched_setparam(), or sched_setscheduler() functions (yet). In this case, we need use pthead-equivalents for real-time sched for picom. Theses changes add this support. Authored-by: Jose Maldonado aka Yukiteru Signed-off-by: Yuxuan Shui --- src/meson.build | 4 ++++ src/picom.c | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/meson.build b/src/meson.build index a2f9c36c73..b9a5a77171 100644 --- a/src/meson.build +++ b/src/meson.build @@ -86,6 +86,10 @@ elif (host_system == 'freebsd' or host_system == 'netbsd' or cflags += ['-DHAS_KQUEUE'] endif +if host_system == 'openbsd' + deps += [dependency('threads', required: true)] +endif + subdir('backend') picom = executable('picom', srcs, c_args: cflags, diff --git a/src/picom.c b/src/picom.c index 13dd0a183d..c2c17e2824 100644 --- a/src/picom.c +++ b/src/picom.c @@ -35,6 +35,9 @@ #include #include #include +#ifdef __OpenBSD__ +#include +#endif #include #include @@ -2588,17 +2591,30 @@ void set_rr_scheduling(void) { int ret; struct sched_param param; +#ifndef __OpenBSD__ ret = sched_getparam(0, ¶m); +#else + int old_policy; + ret = pthread_getschedparam(pthread_self(), &old_policy, ¶m); +#endif + if (ret != 0) { log_debug("Failed to get old scheduling priority"); return; } param.sched_priority = priority; + +#ifndef __OpenBSD__ ret = sched_setscheduler(0, SCHED_RR, ¶m); +#else + ret = pthread_setschedparam(pthread_self(), SCHED_RR, ¶m); +#endif + if (ret != 0) { log_info("Failed to set real-time scheduling priority to %d. Consider " - "giving picom the CAP_SYS_NICE capability", + "giving picom the CAP_SYS_NICE capability or equivalent " + "support.", priority); return; }