Update of /cvsroot/pure-data/pd/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1652/src
Modified Files: Tag: devel_0_38 m_sched.c Log Message: enhanced sleeping behavior
Index: m_sched.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/m_sched.c,v retrieving revision 1.5.4.16 retrieving revision 1.5.4.17 diff -C2 -d -r1.5.4.16 -r1.5.4.17 *** m_sched.c 16 Jan 2005 21:51:20 -0000 1.5.4.16 --- m_sched.c 2 Feb 2005 13:51:54 -0000 1.5.4.17 *************** *** 29,33 **** #include "m_fifo.h"
! static t_int run_idle_callbacks(void); t_fifo * callback_fifo = NULL;
--- 29,33 ---- #include "m_fifo.h"
! static void run_idle_callbacks(int microsec); t_fifo * callback_fifo = NULL;
*************** *** 502,513 **** #endif /* tb: call idle callbacks */ ! if (run_idle_callbacks()) ! { ! /* if even that had nothing to do, sleep. */ ! if (timeforward != SENDDACS_SLEPT) ! { ! sys_microsleep(sys_sleepgrain); ! } ! } #ifdef THREAD_LOCKING /* T.Grill - leave idle phase -> lock thread lock */ --- 502,507 ---- #endif /* tb: call idle callbacks */ ! run_idle_callbacks(timeforward != SENDDACS_SLEPT?sys_sleepgrain:0); ! #ifdef THREAD_LOCKING /* T.Grill - leave idle phase -> lock thread lock */ *************** *** 553,558 **** sys_unlock(); #endif ! if (run_idle_callbacks()) ! sys_microsleep(sys_sleepgrain); #ifdef THREAD_LOCKING --- 547,551 ---- sys_unlock(); #endif ! run_idle_callbacks(sys_sleepgrain); #ifdef THREAD_LOCKING *************** *** 652,656 **** static t_sched_callback * idle_callback = NULL;
! static t_int run_idle_callbacks(void) { if (idle_callback == NULL) --- 645,649 ---- static t_sched_callback * idle_callback = NULL;
! static void run_idle_callbacks(int sleep) { if (idle_callback == NULL) *************** *** 660,668 **** { double remain; ! double stop = sys_getrealtime() + sys_sleepgrain; do { int status = (idle_callback->function)(idle_callback->argv); ! remain = stop-sys_getrealtime();
switch (status) --- 653,661 ---- { double remain; ! double stop = sys_getrealtime()*1.e6 + microsec; do { int status = (idle_callback->function)(idle_callback->argv); ! remain = stop-sys_getrealtime()*1.e6;
switch (status) *************** *** 690,697 **** /* sleep for the rest of the time */ if(remain > 100) sys_microsleep(remain); - return 0; } ! else ! return 1; /* sleep */ }
--- 683,689 ---- /* sleep for the rest of the time */ if(remain > 100) sys_microsleep(remain); } ! else ! sys_microsleep(microsec); }
*************** *** 700,704 **** static t_sched_callback *ringbuffer_head;
! static t_int run_idle_callbacks(void) { t_sched_callback * new_callback; --- 692,696 ---- static t_sched_callback *ringbuffer_head;
! static void run_idle_callbacks(int microsec) { t_sched_callback * new_callback; *************** *** 726,730 **** { double remain; ! double stop = sys_getrealtime() + sys_sleepgrain; t_sched_callback * idle_callback = ringbuffer_head; t_sched_callback * last = NULL; --- 718,722 ---- { double remain; ! double stop = sys_getrealtime()*1.e6 + microsec; t_sched_callback * idle_callback = ringbuffer_head; t_sched_callback * last = NULL; *************** *** 734,738 **** { int status = (idle_callback->function)(idle_callback->argv); - remain = stop-sys_getrealtime();
switch (status) --- 726,729 ---- *************** *** 760,773 **** idle_callback = idle_callback->next; } ! } while ((idle_callback != NULL) && (remain > 0));
- sleep: /* sleep for the rest of the time */ ! if(remain > 100) sys_microsleep(remain); ! return 0; } ! else ! return 1; /* sleep */ } #endif --- 751,765 ---- idle_callback = idle_callback->next; } ! ! remain = stop-sys_getrealtime()*1.e6; ! } while ((idle_callback != NULL) && (remain > 0));
/* sleep for the rest of the time */ ! if(remain > 100) ! sys_microsleep(remain); } ! else ! sys_microsleep(microsec); } #endif