From 6baa6841e670767d8a8d3c920ae2ce63aedb74ce Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Thu, 24 Mar 2022 13:22:51 +0100 Subject: Add precompiler guards to disable setRealtimeScheduling under macOS This function seems to be unused in this repository, and does not compile under macOS because sched_setscheduler() is not present in the macOS implementation of the POSIX standard. --- helpers.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/helpers.c b/helpers.c index 533769d..104828d 100644 --- a/helpers.c +++ b/helpers.c @@ -390,7 +390,23 @@ int setRealtimeScheduling(char *p_name, int prio) { printf("%s: process name is too long\n", __func__); return -1; } - + +#ifdef __APPLE__ + /* setRealtimeScheduling() requires the function sched_setscheduler() from the + * header, which is part of the POSIX Realtime Extension [1]. However + * sched_setscheduler() is part of the optional process scheduling features + * [1][2], and does not seems to be implemented in macOS 12. Furthermore, the + * pidof program is also unavailable in a standard macOS install. + * + * This functionality could be implemented only for thread using + * pthread_attr_setschedparam() and pthread_attr_setschedpolicy(), which are + * available in the macOS implementation of POSIX. + * + * [1]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sched.h.html + * [2]: https://unix.org/version2/whatsnew/realtime.html + */ +#pragma message ("setRealtimeScheduling() is not implemented (does nothing) in macOS") +#else sprintf(shell_cmd, "pidof %s", p_name); if(exec_shell_command(shell_cmd, str, sizeof(str))) { printf("%s: Setting realtime scheduling for '%s' failed: '%s'\n", __func__, p_name, str); @@ -403,5 +419,8 @@ int setRealtimeScheduling(char *p_name, int prio) { printf("%s: sched_setscheduler failed: %s\n", __func__, strerror(errno)); return -1; } +#endif + return 0; } + -- cgit v1.2.1