summaryrefslogtreecommitdiffstats
path: root/polyp/util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2004-09-01 00:23:51 +0000
committerLennart Poettering <lennart@poettering.net>2004-09-01 00:23:51 +0000
commit34fe8bd893ed9c7531bc4898b934ef9d4cdf3e68 (patch)
tree816a8543d3521eb43fb49c67af33afc44769bd91 /polyp/util.c
parent9618aea5df5bf2c5069575f28a935c2039fc55e0 (diff)
add support for SCHED_FIFO
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@163 fefdeb5f-60dc-0310-8127-8f9354f1896f
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);
+}