From 6cd3cb4c65496ad932f8f2b2fd0009e9bac5cf20 Mon Sep 17 00:00:00 2001 From: Brendan Le Foll Date: Wed, 4 Jun 2014 14:39:41 +0100 Subject: [PATCH] maa: add maa_set_priority call Signed-off-by: Brendan Le Foll --- api/maa.h | 11 +++++++++++ src/maa.c | 18 ++++++++++++++++++ src/maa.i | 3 +++ 3 files changed, 32 insertions(+) diff --git a/api/maa.h b/api/maa.h index 63f7b53..19ba2d3 100644 --- a/api/maa.h +++ b/api/maa.h @@ -195,6 +195,17 @@ maa_result_t maa_init() __attribute__((constructor)); maa_result_t maa_init(); #endif +/** + * This function attempts to set the maa process to a given priority and the + * scheduler to SCHED_RR. Highest * priority is typically 99 and minimum is 0. + * This function * will set to MAX if * priority is > MAX. Function will return + * -1 on failure. + + * @param priority Value from typically 0 to 99 + * @return The priority value set + */ +int maa_set_priority(const unsigned int priority); + /** Get the version string of maa autogenerated from git tag * * The version returned may not be what is expected however it is a reliable diff --git a/src/maa.c b/src/maa.c index 0757356..e917029 100644 --- a/src/maa.c +++ b/src/maa.c @@ -25,6 +25,8 @@ #include #include +#include +#include #include "maa.h" #include "maa_internal.h" @@ -65,6 +67,22 @@ maa_init() return MAA_SUCCESS; } +int +maa_set_priority(const unsigned int priority) +{ + struct sched_param sched_s; + + memset(&sched_s, 0, sizeof(struct sched_param)); + if (priority > sched_get_priority_max(SCHED_RR)) { + sched_s.sched_priority = sched_get_priority_max(SCHED_RR); + } + else { + sched_s.sched_priority = priority; + } + + return sched_setscheduler(0, SCHED_RR, &sched_s); +} + static maa_result_t maa_setup_mux_mapped(maa_pin_t meta) { diff --git a/src/maa.i b/src/maa.i index 79ef841..cfc3941 100644 --- a/src/maa.i +++ b/src/maa.i @@ -24,6 +24,9 @@ %rename(getVersion) maa_get_version(); const char * maa_get_version(); +%rename(setPriority) maa_set_priority; +int maa_set_priority(const unsigned int); + %rename(printError) maa_result_print(maa_result_t error); void maa_result_print(maa_result_t error);