summaryrefslogtreecommitdiff
path: root/pjsip-apps/src/samples/siprtp.c
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2006-07-31 18:54:06 +0000
committerBenny Prijono <bennylp@teluu.com>2006-07-31 18:54:06 +0000
commit7f63047582f9d4e1f3997ce862d0ce1aa1ffd40f (patch)
treebe8058bf39a9a5fff8dedbfd3a51987ca05c833e /pjsip-apps/src/samples/siprtp.c
parent2d507021e3078779c8b48c44c8881558f0ee6242 (diff)
Changed siprtp on Linux to raise the thread priority
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@639 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjsip-apps/src/samples/siprtp.c')
-rw-r--r--pjsip-apps/src/samples/siprtp.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/pjsip-apps/src/samples/siprtp.c b/pjsip-apps/src/samples/siprtp.c
index 001fd2e3..0da627b3 100644
--- a/pjsip-apps/src/samples/siprtp.c
+++ b/pjsip-apps/src/samples/siprtp.c
@@ -1056,6 +1056,69 @@ static void boost_priority(void)
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST);
}
+#elif defined(PJ_LINUX) && PJ_LINUX != 0
+#include <pthread.h>
+static void boost_priority(void)
+{
+#define POLICY SCHED_FIFO
+ pthread_t thread;
+ struct sched_param tp;
+ int max_prio;
+ int policy;
+ int rc;
+
+ if (sched_get_priority_min(POLICY) < sched_get_priority_max(POLICY))
+ max_prio = sched_get_priority_max(POLICY)-1;
+ else
+ max_prio = sched_get_priority_max(POLICY)+1;
+
+ /*
+ * Adjust process scheduling algorithm and priority
+ */
+ rc = sched_getparam(0, &tp);
+ if (rc != 0) {
+ app_perror( THIS_FILE, "sched_getparam error",
+ PJ_RETURN_OS_ERROR(rc));
+ return;
+ }
+ tp.__sched_priority = max_prio;
+
+ rc = sched_setscheduler(0, POLICY, &tp);
+ if (rc != 0) {
+ app_perror( THIS_FILE, "sched_setscheduler error",
+ PJ_RETURN_OS_ERROR(rc));
+ }
+
+ PJ_LOG(4, (THIS_FILE, "New process policy=%d, priority=%d",
+ policy, tp.__sched_priority));
+
+ /*
+ * Adjust thread scheduling algorithm and priority
+ */
+ rc = pthread_getschedparam(pthread_self(), &policy, &tp);
+ if (rc != 0) {
+ app_perror( THIS_FILE, "pthread_getschedparam error",
+ PJ_RETURN_OS_ERROR(rc));
+ return;
+ }
+
+ PJ_LOG(4, (THIS_FILE, "Old thread policy=%d, priority=%d",
+ policy, tp.__sched_priority));
+
+ policy = POLICY;
+ tp.__sched_priority = max_prio;
+
+ rc = pthread_setschedparam(pthread_self(), policy, &tp);
+ if (rc != 0) {
+ app_perror( THIS_FILE, "pthread_setschedparam error",
+ PJ_RETURN_OS_ERROR(rc));
+ return;
+ }
+
+ PJ_LOG(4, (THIS_FILE, "New thread policy=%d, priority=%d",
+ policy, tp.__sched_priority));
+}
+
#else
# define boost_priority()
#endif