/*============================================================== Abs: Sets the real-time priority (????) Name: compilerDependencies.h Side: must have macro linuxRT defined as USR_CFLAGS in Makefile Facility: SLAC Auth: 06-Jul-2012, Till Straumann (straumann@slac.stanford.edu) Rev: dd-mmm-yyyy, Reviewer's Name (USERNAME) -------------------------------------------------------------- Mod: (newest-to-oldest) dd-mmm-yyyy, First Lastname (USERNAME): comment ============================================================== */ #ifndef compilerDependenciesPrio_h #define compilerDependenciesPrio_h #include #include "shareLib.h" #ifdef __cplusplus extern "C" { #endif #if defined(linuxRT) /* Add support for linuxRT */ #include #if _POSIX_MEMLOCK > 0 #include #endif #include #include /* We must make sure this code is executed *before* * the epicsThread machinery is. * Not so easy since the latter eventually is fired * up by a c++ static constructor. * It is not possible in a portable way to enforce * an order of execution among such constructors if * they are defined in different compilation units. * Under GNU c++ we may use the 'init_priority' * attribute. * However, if this code is dynamically linked * against EPICS base then this doesn't work either * since the shared-library is initialized before * this code here. * Hence we stick a function pointer into the * '.preinit_array' section which is executed * before any shared libraries are. */ static void set_rtprio(int argc, char **argv, char **envp) { struct rlimit l; if ( getrlimit(RLIMIT_RTPRIO, &l) ) { perror("Warning: retrieving real-time priority limits failed"); } /* If the current hard limit is unset the set to the maximum * otherwise leave it alone. */ if ( 0 == l.rlim_max ) l.rlim_max = sched_get_priority_max(SCHED_FIFO); l.rlim_cur = l.rlim_max; if ( setrlimit(RLIMIT_RTPRIO, &l) ) { perror("Warning: setting real-time priority limit failed"); } } static void (*set_rtprio_hook)(int, char**, char**) __attribute__((section(".preinit_array"),used)) = set_rtprio; #endif #ifdef __cplusplus } #endif #endif /* compilerDependenciesPrio_h */