Ignore:
Timestamp:
Mar 4, 2008 2:45:19 PM (16 years ago)
Author:
bennylp
Message:

Ticket #500: Added function to set thread priority in PJLIB

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib/src/pj/os_core_unix.c

    r1783 r1841  
    239239} 
    240240 
     241 
     242/* 
     243 * Get thread priority value for the thread. 
     244 */ 
     245PJ_DEF(int) pj_thread_get_prio(pj_thread_t *thread) 
     246{ 
     247#if PJ_HAS_THREADS 
     248    sched_param param; 
     249    int policy; 
     250    int rc; 
     251 
     252    rc = pthread_getschedparam (thread->thread, &policy, &param); 
     253    if (rc != 0) 
     254        return -1; 
     255 
     256    return param.sched_priority; 
     257#else 
     258    PJ_UNUSED_ARG(thread); 
     259    return 1; 
     260#endif 
     261} 
     262 
     263 
     264/* 
     265 * Set the thread priority. 
     266 */ 
     267PJ_DEF(pj_status_t) pj_thread_set_prio(pj_thread_t *thread,  int prio) 
     268{ 
     269#if PJ_HAS_THREADS 
     270    sched_param param; 
     271    int policy; 
     272    int rc; 
     273 
     274    rc = pthread_getschedparam (thread->thread, &policy, &param); 
     275    if (rc != 0) 
     276        return PJ_RETURN_OS_ERROR(rc); 
     277 
     278    param.sched_priority = prio; 
     279 
     280    rc = pthread_setschedparam(tid, policy, &param); 
     281    if (rc != 0) 
     282        return PJ_RETURN_OS_ERROR(rc); 
     283 
     284    return PJ_SUCCESS; 
     285#else 
     286    PJ_UNUSED_ARG(thread); 
     287    PJ_UNUSED_ARG(prio); 
     288    pj_assert("pj_thread_set_prio() called in non-threading mode!"); 
     289    return 1; 
     290#endif 
     291} 
     292 
     293 
     294/* 
     295 * Get the lowest priority value available on this system. 
     296 */ 
     297PJ_DEF(int) pj_thread_get_prio_min(pj_thread_t *thread) 
     298{ 
     299    sched_param param; 
     300    int policy; 
     301    int rc; 
     302 
     303    rc = pthread_getschedparam(thread->thread, &policy, &param); 
     304    if (rc != 0) 
     305        return -1; 
     306 
     307    return sched_get_priority_min(policy); 
     308} 
     309 
     310 
     311/* 
     312 * Get the highest priority value available on this system. 
     313 */ 
     314PJ_DEF(int) pj_thread_get_prio_max(pj_thread_t *thread) 
     315{ 
     316    sched_param param; 
     317    int policy; 
     318    int rc; 
     319 
     320    rc = pthread_getschedparam(thread->thread, &policy, &param); 
     321    if (rc != 0) 
     322        return -1; 
     323 
     324    return sched_get_priority_max(policy); 
     325} 
     326 
     327 
    241328/* 
    242329 * Get native thread handle 
Note: See TracChangeset for help on using the changeset viewer.