summaryrefslogtreecommitdiff
path: root/pjlib/src/pj/os_core_unix.c
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2008-03-04 14:45:19 +0000
committerBenny Prijono <bennylp@teluu.com>2008-03-04 14:45:19 +0000
commit5254d7c3a14177dffdf43c3ec7e5235b066d986e (patch)
tree249ea16a1ab2e6d7693c56af6d9af5516590b589 /pjlib/src/pj/os_core_unix.c
parent771571a57c706e924ba3511dbf6c6e3dbda93c68 (diff)
Ticket #500: Added function to set thread priority in PJLIB
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@1841 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib/src/pj/os_core_unix.c')
-rw-r--r--pjlib/src/pj/os_core_unix.c87
1 files changed, 87 insertions, 0 deletions
diff --git a/pjlib/src/pj/os_core_unix.c b/pjlib/src/pj/os_core_unix.c
index 1fe5253b..31cbb2e9 100644
--- a/pjlib/src/pj/os_core_unix.c
+++ b/pjlib/src/pj/os_core_unix.c
@@ -238,6 +238,93 @@ PJ_DEF(pj_bool_t) pj_thread_is_registered(void)
#endif
}
+
+/*
+ * Get thread priority value for the thread.
+ */
+PJ_DEF(int) pj_thread_get_prio(pj_thread_t *thread)
+{
+#if PJ_HAS_THREADS
+ sched_param param;
+ int policy;
+ int rc;
+
+ rc = pthread_getschedparam (thread->thread, &policy, &param);
+ if (rc != 0)
+ return -1;
+
+ return param.sched_priority;
+#else
+ PJ_UNUSED_ARG(thread);
+ return 1;
+#endif
+}
+
+
+/*
+ * Set the thread priority.
+ */
+PJ_DEF(pj_status_t) pj_thread_set_prio(pj_thread_t *thread, int prio)
+{
+#if PJ_HAS_THREADS
+ sched_param param;
+ int policy;
+ int rc;
+
+ rc = pthread_getschedparam (thread->thread, &policy, &param);
+ if (rc != 0)
+ return PJ_RETURN_OS_ERROR(rc);
+
+ param.sched_priority = prio;
+
+ rc = pthread_setschedparam(tid, policy, &param);
+ if (rc != 0)
+ return PJ_RETURN_OS_ERROR(rc);
+
+ return PJ_SUCCESS;
+#else
+ PJ_UNUSED_ARG(thread);
+ PJ_UNUSED_ARG(prio);
+ pj_assert("pj_thread_set_prio() called in non-threading mode!");
+ return 1;
+#endif
+}
+
+
+/*
+ * Get the lowest priority value available on this system.
+ */
+PJ_DEF(int) pj_thread_get_prio_min(pj_thread_t *thread)
+{
+ sched_param param;
+ int policy;
+ int rc;
+
+ rc = pthread_getschedparam(thread->thread, &policy, &param);
+ if (rc != 0)
+ return -1;
+
+ return sched_get_priority_min(policy);
+}
+
+
+/*
+ * Get the highest priority value available on this system.
+ */
+PJ_DEF(int) pj_thread_get_prio_max(pj_thread_t *thread)
+{
+ sched_param param;
+ int policy;
+ int rc;
+
+ rc = pthread_getschedparam(thread->thread, &policy, &param);
+ if (rc != 0)
+ return -1;
+
+ return sched_get_priority_max(policy);
+}
+
+
/*
* Get native thread handle
*/