summaryrefslogtreecommitdiffstats
path: root/polyp/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'polyp/util.c')
-rw-r--r--polyp/util.c40
1 files changed, 38 insertions, 2 deletions
diff --git a/polyp/util.c b/polyp/util.c
index 6c8febb6..0d930118 100644
--- a/polyp/util.c
+++ b/polyp/util.c
@@ -37,6 +37,8 @@
#include <signal.h>
#include <pthread.h>
#include <sys/time.h>
+#include <sched.h>
+#include <sys/resource.h>
#include "util.h"
#include "xmalloc.h"
@@ -83,7 +85,7 @@ ssize_t pa_loop_read(int fd, void*data, size_t size) {
break;
ret += r;
- data += r;
+ data = (uint8_t*) data + r;
size -= r;
}
@@ -104,7 +106,7 @@ ssize_t pa_loop_write(int fd, const void*data, size_t size) {
break;
ret += r;
- data += r;
+ data = (uint8_t*) data + r;
size -= r;
}
@@ -213,3 +215,37 @@ uint32_t pa_age(struct timeval *tv) {
return r;
}
+
+#define NICE_LEVEL (-15)
+
+void pa_raise_priority(void) {
+ if (setpriority(PRIO_PROCESS, 0, NICE_LEVEL) < 0)
+ fprintf(stderr, __FILE__": setpriority() failed: %s\n", strerror(errno));
+ else
+ fprintf(stderr, __FILE__": Successfully gained nice level %i.\n", NICE_LEVEL);
+
+#ifdef _POSIX_PRIORITY_SCHEDULING
+ {
+ struct sched_param sp;
+ sched_getparam(0, &sp);
+ sp.sched_priority = 1;
+ if (sched_setscheduler(0, SCHED_FIFO, &sp) < 0)
+ fprintf(stderr, __FILE__": sched_setscheduler() failed: %s\n", strerror(errno));
+ else
+ fprintf(stderr, __FILE__": Successfully gained SCHED_FIFO scheduling.\n");
+ }
+#endif
+}
+
+void pa_reset_priority(void) {
+#ifdef _POSIX_PRIORITY_SCHEDULING
+ {
+ struct sched_param sp;
+ sched_getparam(0, &sp);
+ sp.sched_priority = 0;
+ sched_setscheduler(0, SCHED_OTHER, &sp);
+ }
+#endif
+
+ setpriority(PRIO_PROCESS, 0, 0);
+}