Changeset 1841


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

Location:
pjproject/trunk/pjlib
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib/include/pj/os.h

    r1601 r1841  
    136136 */ 
    137137PJ_DECL(pj_bool_t) pj_thread_is_registered(void); 
     138 
     139 
     140/** 
     141 * Get thread priority value for the thread. 
     142 * 
     143 * @param thread        Thread handle. 
     144 * 
     145 * @return              Thread priority value, or -1 on error. 
     146 */ 
     147PJ_DECL(int) pj_thread_get_prio(pj_thread_t *thread); 
     148 
     149 
     150/** 
     151 * Set the thread priority. The priority value must be in the priority 
     152 * value range, which can be retrieved with #pj_thread_get_prio_min() and 
     153 * #pj_thread_get_prio_max() functions. 
     154 * 
     155 * @param thread        Thread handle. 
     156 * @param prio          New priority to be set to the thread. 
     157 * 
     158 * @return              PJ_SUCCESS on success or the error code. 
     159 */ 
     160PJ_DECL(pj_status_t) pj_thread_set_prio(pj_thread_t *thread,  int prio); 
     161 
     162/** 
     163 * Get the lowest priority value available for this thread. 
     164 * 
     165 * @param thread        Thread handle. 
     166 * @return              Minimum thread priority value, or -1 on error. 
     167 */ 
     168PJ_DECL(int) pj_thread_get_prio_min(pj_thread_t *thread); 
     169 
     170 
     171/** 
     172 * Get the highest priority value available for this thread. 
     173 * 
     174 * @param thread        Thread handle. 
     175 * @return              Minimum thread priority value, or -1 on error. 
     176 */ 
     177PJ_DECL(int) pj_thread_get_prio_max(pj_thread_t *thread); 
    138178 
    139179 
  • pjproject/trunk/pjlib/src/pj/os_core_symbian.cpp

    r1651 r1841  
    485485} 
    486486 
     487 
     488/* 
     489 * Get thread priority value for the thread. 
     490 */ 
     491PJ_DEF(int) pj_thread_get_prio(pj_thread_t *thread) 
     492{ 
     493    PJ_UNUSED_ARG(thread); 
     494    return 1; 
     495} 
     496 
     497 
     498/* 
     499 * Set the thread priority. 
     500 */ 
     501PJ_DEF(pj_status_t) pj_thread_set_prio(pj_thread_t *thread,  int prio) 
     502{ 
     503    PJ_UNUSED_ARG(thread); 
     504    PJ_UNUSED_ARG(prio); 
     505    return PJ_SUCCESS; 
     506} 
     507 
     508 
     509/* 
     510 * Get the lowest priority value available on this system. 
     511 */ 
     512PJ_DEF(int) pj_thread_get_prio_min(pj_thread_t *thread) 
     513{ 
     514    PJ_UNUSED_ARG(thread); 
     515    return 1; 
     516} 
     517 
     518 
     519/* 
     520 * Get the highest priority value available on this system. 
     521 */ 
     522PJ_DEF(int) pj_thread_get_prio_max(pj_thread_t *thread) 
     523{ 
     524    PJ_UNUSED_ARG(thread); 
     525    return 1; 
     526} 
     527 
     528 
    487529/* 
    488530 * pj_thread_get_os_handle() 
  • 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 
  • pjproject/trunk/pjlib/src/pj/os_core_win32.c

    r1659 r1841  
    254254} 
    255255 
     256 
     257/* 
     258 * Get thread priority value for the thread. 
     259 */ 
     260PJ_DEF(int) pj_thread_get_prio(pj_thread_t *thread) 
     261{ 
     262    return GetThreadPriority(thread->hthread); 
     263} 
     264 
     265 
     266/* 
     267 * Set the thread priority. 
     268 */ 
     269PJ_DEF(pj_status_t) pj_thread_set_prio(pj_thread_t *thread,  int prio) 
     270{ 
     271#if PJ_HAS_THREADS 
     272    PJ_ASSERT_RETURN(thread, PJ_EINVAL); 
     273    PJ_ASSERT_RETURN(prio>=THREAD_PRIORITY_IDLE &&  
     274                        prio<=THREAD_PRIORITY_TIME_CRITICAL, 
     275                     PJ_EINVAL); 
     276 
     277    if (SetThreadPriority(thread->hthread, prio) == FALSE) 
     278        return PJ_RETURN_OS_ERROR(GetLastError()); 
     279 
     280    return PJ_SUCCESS; 
     281 
     282#else 
     283    PJ_UNUSED_ARG(thread); 
     284    PJ_UNUSED_ARG(prio); 
     285    pj_assert("pj_thread_set_prio() called in non-threading mode!"); 
     286    return PJ_EINVALIDOP; 
     287#endif 
     288} 
     289 
     290 
     291/* 
     292 * Get the lowest priority value available on this system. 
     293 */ 
     294PJ_DEF(int) pj_thread_get_prio_min(pj_thread_t *thread) 
     295{ 
     296    PJ_UNUSED_ARG(thread); 
     297    return THREAD_PRIORITY_IDLE; 
     298} 
     299 
     300 
     301/* 
     302 * Get the highest priority value available on this system. 
     303 */ 
     304PJ_DEF(int) pj_thread_get_prio_max(pj_thread_t *thread) 
     305{ 
     306    PJ_UNUSED_ARG(thread); 
     307    return THREAD_PRIORITY_TIME_CRITICAL; 
     308} 
     309 
     310 
    256311/* 
    257312 * Get native thread handle 
Note: See TracChangeset for help on using the changeset viewer.