[pjsip] pj_thread_sleep(0) problem in linux platform issue

Simon Chen simonmychen at seed.net.tw
Tue May 20 22:41:41 EDT 2008


Hello!

    pj_thread_sleep(0) is used for forced task switch sometimes. It can work 
find in windows platform. But in  linux platform, pj_thread_sleep(0) will 
sleep 1 tick. This will effect the performance of the thread.  I modify the 
pj_thread_sleep in os_core_uinx.c. When msec equals 0, call sched_yield(). 
It can work find in my test. How about this modification for the pjlib? any 
suggestion? Thanks!

PJ_DEF(pj_status_t) pj_thread_sleep(unsigned msec)
{
/* TODO: should change this to something like PJ_OS_HAS_NANOSLEEP */
#if defined(PJ_RTEMS) && PJ_RTEMS!=0
    enum { NANOSEC_PER_MSEC = 1000000 };
    struct timespec req;

    PJ_CHECK_STACK();

// modification start -----------
if( msec == 0 )
 {
  sched_yield();
  return PJ_SUCCESS;
 }
// modification  end ----------- 
    req.tv_sec = msec / 1000;
    req.tv_nsec = (msec % 1000) * NANOSEC_PER_MSEC;

    if (nanosleep(&req, NULL) == 0)
 return PJ_SUCCESS;

    return PJ_RETURN_OS_ERROR(pj_get_native_os_error());
#else
    PJ_CHECK_STACK();

// modification  start -----------
if( msec == 0 )
 {
  sched_yield();
  return PJ_SUCCESS;
 }
// modification  end ----------- 
    pj_set_os_error(0);

    usleep(msec * 1000);

    return pj_get_os_error();
;
#endif /* PJ_RTEMS */
}


Simonmy 






More information about the pjsip mailing list