summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2009-06-04 01:53:51 +0200
committerLennart Poettering <lennart@poettering.net>2009-06-04 01:53:51 +0200
commit065fe7baaa263b8140acd6f1ff1c816af9e02d0d (patch)
treea6aad3e1b929903a2e8f1b41365a633ccf99fcc3
parentf4dd55fa9fcf2b4a018793a2bfe3fe42e9dbc663 (diff)
when thread == 0 is passed, fill in gettid()
-rw-r--r--rtkit.c15
-rw-r--r--rtkit.h14
2 files changed, 23 insertions, 6 deletions
diff --git a/rtkit.c b/rtkit.c
index 67a44f7..893edde 100644
--- a/rtkit.c
+++ b/rtkit.c
@@ -24,11 +24,20 @@
SOFTWARE.
***/
+#define _GNU_SOURCE
+
#include <string.h>
#include <errno.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/syscall.h>
#include "rtkit.h"
+static pid_t _gettid(void) {
+ return syscall(SYS_gettid);
+}
+
static int translate_error(const char *name) {
if (strcmp(name, DBUS_ERROR_NO_MEMORY) == 0)
return -ENOMEM;
@@ -51,6 +60,9 @@ int rtkit_make_realtime(DBusConnection *connection, pid_t thread, int priority)
dbus_error_init(&error);
+ if (thread == 0)
+ thread = _gettid();
+
if (!(m = dbus_message_new_method_call(
RTKIT_SERVICE_NAME,
RTKIT_OBJECT_PATH,
@@ -105,6 +117,9 @@ int rtkit_make_high_priority(DBusConnection *connection, pid_t thread, int nice_
dbus_error_init(&error);
+ if (thread == 0)
+ thread = _gettid();
+
if (!(m = dbus_message_new_method_call(
RTKIT_SERVICE_NAME,
RTKIT_OBJECT_PATH,
diff --git a/rtkit.h b/rtkit.h
index 5796ad8..45bc438 100644
--- a/rtkit.h
+++ b/rtkit.h
@@ -38,15 +38,17 @@
#define RTKIT_OBJECT_PATH "/org/freedesktop/RealtimeKit1"
/* This is mostly equivalent to sched_setparam(thread, SCHED_RR, {
- * .sched_priority = priority }). If thread is 0 the calling
- * processe's main thread is used. The returned value is a negative
- * errno error code, or 0 on success. */
+ * .sched_priority = priority }). 'thread' needs to be a kernel thread
+ * id as returned by gettid(), not a pthread_t! If 'thread' is 0 the
+ * current thread is used. The returned value is a negative errno
+ * style error code, or 0 on success. */
int rtkit_make_realtime(DBusConnection *connection, pid_t thread, int priority);
/* This is mostly equivalent to setpriority(PRIO_PROCESS, thread,
- * nice_level). If thread is 0 the calling processe's main thread is
- * used. The returned value is a negative errno error code, or 0 on
- * success.*/
+ * nice_level). 'thread' needs to be a kernel thread id as returned by
+ * gettid(), not a pthread_t! If 'thread' is 0 the current thread is
+ * used. The returned value is a negative errno style error code, or 0
+ * on success.*/
int rtkit_make_high_priority(DBusConnection *connection, pid_t thread, int nice_level);
#endif