Skip to content

Commit

Permalink
core: use pthread_setschedparam on OpenBSD
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Yuxuan Shui <[email protected]>
  • Loading branch information
yukiteruamano authored and yshui committed Feb 10, 2024
1 parent 0f22b70 commit 023103c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 17 additions & 1 deletion src/picom.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
#include <xcb/render.h>
#include <xcb/sync.h>
#include <xcb/xfixes.h>
#ifdef __OpenBSD__
#include <pthread.h>
#endif

#include <ev.h>
#include <test.h>
Expand Down Expand Up @@ -2588,17 +2591,30 @@ void set_rr_scheduling(void) {
int ret;
struct sched_param param;

#ifndef __OpenBSD__
ret = sched_getparam(0, &param);
#else
int old_policy;
ret = pthread_getschedparam(pthread_self(), &old_policy, &param);
#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, &param);
#else
ret = pthread_setschedparam(pthread_self(), SCHED_RR, &param);
#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;
}
Expand Down

0 comments on commit 023103c

Please sign in to comment.