pj_thread_sleep(0) problem in linux platform issue

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 





[Index of Archives]     [Asterisk Users]     [Asterisk App Development]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [Linux API]
  Powered by Linux