Update of /cvsroot/pure-data/pd/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22138/src
Modified Files: Tag: devel_0_39 m_sched.c Log Message: fix for idle callbacks replacing tabs with spaces
Index: m_sched.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/m_sched.c,v retrieving revision 1.5.4.35.2.16 retrieving revision 1.5.4.35.2.17 diff -C2 -d -r1.5.4.35.2.16 -r1.5.4.35.2.17 *** m_sched.c 27 Jun 2006 16:31:17 -0000 1.5.4.35.2.16 --- m_sched.c 28 Jun 2006 10:51:16 -0000 1.5.4.35.2.17 *************** *** 372,386 **** static void run_clock_callbacks(double next_sys_time) { ! if (clock_setlist && clock_setlist->c_settime <= next_sys_time) ! { ! do ! { ! t_clock *c = clock_setlist; ! sys_time = c->c_settime; ! clock_unset(c); /* the compiler should easily inline this */ ! outlet_setstacklim(); ! (*c->c_fn)(c->c_owner); ! } ! while (clock_setlist && clock_setlist->c_settime <= next_sys_time); } } --- 372,386 ---- static void run_clock_callbacks(double next_sys_time) { ! if (clock_setlist && clock_setlist->c_settime <= next_sys_time) ! { ! do ! { ! t_clock *c = clock_setlist; ! sys_time = c->c_settime; ! clock_unset(c); /* the compiler should easily inline this */ ! outlet_setstacklim(); ! (*c->c_fn)(c->c_owner); ! } ! while (clock_setlist && clock_setlist->c_settime <= next_sys_time); } } *************** *** 390,402 **** void sched_tick(double next_sys_time) { ! run_clock_callbacks(next_sys_time); ! sys_time = next_sys_time; ! sched_diddsp++; /* rethink: how to get rid of this stupid histogram??? */ dsp_tick();
! /* rethink: should we really do all this midi messaging in the realtime thread ? */ ! sys_pollmidiqueue(); ! sys_setmiditimediff(0, 1e-6 * sys_schedadvance); }
--- 390,402 ---- void sched_tick(double next_sys_time) { ! run_clock_callbacks(next_sys_time); ! sys_time = next_sys_time; ! sched_diddsp++; /* rethink: how to get rid of this stupid histogram??? */ dsp_tick();
! /* rethink: should we really do all this midi messaging in the realtime thread ? */ ! sys_pollmidiqueue(); ! sys_setmiditimediff(0, 1e-6 * sys_schedadvance); }
*************** *** 421,434 **** sys_time_per_dsp_tick = (TIMEUNITPERSEC) * ((double)sys_schedblocksize) / sys_dacsr; ! /* T.Grill - lock mutex */ ! sys_lock(); ! sys_clearhist();
! /* tb: adapt sleepgrain with advance */ ! sys_update_sleepgrain();
! sched_set_using_dacs(0); /* tb: dsp is switched off */
sys_initmidiqueue(); --- 421,434 ---- sys_time_per_dsp_tick = (TIMEUNITPERSEC) * ((double)sys_schedblocksize) / sys_dacsr; ! /* T.Grill - lock mutex */ ! sys_lock(); ! sys_clearhist();
! /* tb: adapt sleepgrain with advance */ ! sys_update_sleepgrain();
! sched_set_using_dacs(0); /* tb: dsp is switched off */
sys_initmidiqueue(); *************** *** 436,527 **** while (!sys_quit) { ! if (!sys_callbackscheduler || !sched_usedacs) ! while (sys_keepsched) ! { ! int didsomething = 0; ! int timeforward;
! waitfortick: ! if (sched_usedacs) ! { ! timeforward = sys_send_dacs(); ! /* if dacs remain "idle" for 1 sec, they're hung up. */ ! if (timeforward != 0) ! idlecount = 0; ! else ! { ! idlecount++; ! if (!(idlecount & 31)) ! { ! static double idletime; ! /* on 32nd idle, start a clock watch; every ! 32 ensuing idles, check it */ ! if (idlecount == 32) ! idletime = sys_getrealtime(); ! else if (sys_getrealtime() - idletime > 1.) ! { ! post("audio I/O stuck... closing audio\n"); ! sys_close_audio(); ! sched_set_using_dacs(0); ! goto waitfortick; ! } ! } ! } ! } ! else ! { ! if (1000. * (sys_getrealtime() - sched_referencerealtime) ! > clock_gettimesince(sched_referencelogicaltime)) ! timeforward = SENDDACS_YES; ! else timeforward = SENDDACS_NO; ! } ! sys_setmiditimediff(0, 1e-6 * sys_schedadvance);
! if (timeforward != SENDDACS_NO) ! { ! sched_tick(sys_time + sys_time_per_dsp_tick); ! } ! if (timeforward == SENDDACS_YES) ! didsomething = 1;
! sys_pollmidiqueue(); ! if (sys_pollgui()) ! { ! didsomething = 1; ! }
! /* test for idle; if so, do graphics updates. */ ! if (!didsomething) ! {
! sched_pollformeters();
! /* tb: call idle callbacks */ ! if (timeforward != SENDDACS_SLEPT) ! { ! run_idle_callbacks(sys_sleepgrain); ! } ! } ! } ! else /* tb: scheduler for callback-based dsp scheduling */ ! while(sys_keepsched) ! { /* tb: allow the audio callback to run */ sys_unlock(); ! sys_microsleep(sys_sleepgrain); ! sys_lock();
! sys_pollmidiqueue(); ! sys_setmiditimediff(0, 1e-6 * sys_schedadvance); ! ! if (sys_pollgui()) ! continue; ! ! /* do graphics updates and run idle callbacks */ sched_pollformeters();
! } ! sys_keepsched = 1; ! }
sys_close_audio(); --- 436,527 ---- while (!sys_quit) { ! if (!sys_callbackscheduler || !sched_usedacs) ! while (sys_keepsched) ! { ! int didsomething = 0; ! int timeforward;
! waitfortick: ! if (sched_usedacs) ! { ! timeforward = sys_send_dacs(); ! /* if dacs remain "idle" for 1 sec, they're hung up. */ ! if (timeforward != 0) ! idlecount = 0; ! else ! { ! idlecount++; ! if (!(idlecount & 31)) ! { ! static double idletime; ! /* on 32nd idle, start a clock watch; every ! 32 ensuing idles, check it */ ! if (idlecount == 32) ! idletime = sys_getrealtime(); ! else if (sys_getrealtime() - idletime > 1.) ! { ! post("audio I/O stuck... closing audio\n"); ! sys_close_audio(); ! sched_set_using_dacs(0); ! goto waitfortick; ! } ! } ! } ! } ! else ! { ! if (1000. * (sys_getrealtime() - sched_referencerealtime) ! > clock_gettimesince(sched_referencelogicaltime)) ! timeforward = SENDDACS_YES; ! else timeforward = SENDDACS_NO; ! } ! sys_setmiditimediff(0, 1e-6 * sys_schedadvance);
! if (timeforward != SENDDACS_NO) ! { ! sched_tick(sys_time + sys_time_per_dsp_tick); ! } ! if (timeforward == SENDDACS_YES) ! didsomething = 1;
! sys_pollmidiqueue(); ! if (sys_pollgui()) ! { ! didsomething = 1; ! }
! /* test for idle; if so, do graphics updates. */ ! if (!didsomething) ! {
! sched_pollformeters();
! /* tb: call idle callbacks */ ! if (timeforward != SENDDACS_SLEPT) ! { ! run_idle_callbacks(sys_sleepgrain); ! } ! } ! } ! else /* tb: scheduler for callback-based dsp scheduling */ ! while(sys_keepsched) ! { /* tb: allow the audio callback to run */ sys_unlock(); ! sys_microsleep(sys_sleepgrain); ! sys_lock();
! sys_pollmidiqueue(); ! sys_setmiditimediff(0, 1e-6 * sys_schedadvance); ! ! if (sys_pollgui()) ! continue; ! ! /* do graphics updates and run idle callbacks */ sched_pollformeters();
! } ! sys_keepsched = 1; ! }
sys_close_audio(); *************** *** 540,550 **** void sys_lock(void) { ! pthread_mutex_lock(&sys_mutex); }
void sys_unlock(void) { ! pthread_mutex_unlock(&sys_mutex); ! pthread_cond_signal(&sys_cond); }
--- 540,550 ---- void sys_lock(void) { ! pthread_mutex_lock(&sys_mutex); }
void sys_unlock(void) { ! pthread_mutex_unlock(&sys_mutex); ! pthread_cond_signal(&sys_cond); }
*************** *** 561,570 **** int gettimeofday (struct timeval *tv, void* tz) { ! __int64 now; /* time since 1 Jan 1601 in 100ns */ ! ! GetSystemTimeAsFileTime ((FILETIME*) &now); ! tv->tv_usec = (long) ((now / 10LL) % 1000000LL); ! tv->tv_sec = (long) ((now - 116444736000000000LL) / 10000000LL); ! return (0); } #endif --- 561,570 ---- int gettimeofday (struct timeval *tv, void* tz) { ! __int64 now; /* time since 1 Jan 1601 in 100ns */ ! ! GetSystemTimeAsFileTime ((FILETIME*) &now); ! tv->tv_usec = (long) ((now / 10LL) % 1000000LL); ! tv->tv_sec = (long) ((now - 116444736000000000LL) / 10000000LL); ! return (0); } #endif *************** *** 598,602 ****
if (ret) ! post("timeout, %d", ret);
return ret; --- 598,602 ----
if (ret) ! post("timeout, %d", ret);
return ret; *************** *** 606,639 **** int sys_timedlock(int microsec) { ! struct timespec timeout; ! int ret; ! struct timeval now;
! if (sys_trylock() == 0) ! return 0;
! if (microsec < 1e3) ! microsec = 1e3;
! gettimeofday(&now,0); ! ! timeout.tv_sec = now.tv_sec; ! timeout.tv_nsec = (now.tv_usec + microsec) * 1000; ! ! while (timeout.tv_nsec > 1e9) ! { ! timeout.tv_sec += 1; ! timeout.tv_nsec -= 1e9; ! }
! ! /* in case the lock has been released during the system call, try ! again before waiting for the signal */ ! if (sys_trylock() == 0) ! return 0; ! ! ret = pthread_cond_timedwait(&sys_cond, &sys_mutex, &timeout); ! ! return ret; } #endif --- 606,639 ---- int sys_timedlock(int microsec) { ! struct timespec timeout; ! int ret; ! struct timeval now;
! if (sys_trylock() == 0) ! return 0;
! if (microsec < 1e3) ! microsec = 1e3;
! gettimeofday(&now,0); ! ! timeout.tv_sec = now.tv_sec; ! timeout.tv_nsec = (now.tv_usec + microsec) * 1000; ! ! while (timeout.tv_nsec > 1e9) ! { ! timeout.tv_sec += 1; ! timeout.tv_nsec -= 1e9; ! }
! ! /* in case the lock has been released during the system call, try ! again before waiting for the signal */ ! if (sys_trylock() == 0) ! return 0; ! ! ret = pthread_cond_timedwait(&sys_cond, &sys_mutex, &timeout); ! ! return ret; } #endif *************** *** 658,663 **** void sys_exit(void) { ! sys_keepsched = 0; ! sys_quit = 1; }
--- 658,663 ---- void sys_exit(void) { ! sys_keepsched = 0; ! sys_quit = 1; }
*************** *** 670,677 **** typedef struct _sched_callback { ! struct _sched_callback* next; /* next callback in ringbuffer / in fifo */ ! t_int (*function) (t_int* argv); ! t_int* argv; ! t_int argc; } t_sched_callback;
--- 670,677 ---- typedef struct _sched_callback { ! struct _sched_callback* next; /* next callback in ringbuffer / in fifo */ ! t_int (*function) (t_int* argv); ! t_int* argv; ! t_int argc; } t_sched_callback;
*************** *** 679,694 **** void sys_callback(t_int (*callback) (t_int* argv), t_int* argv, t_int argc) { ! t_sched_callback* noo = (t_sched_callback*) getbytes ! (sizeof(t_sched_callback));
! noo->function = callback; ! noo->argv = (t_int*) copybytes (argv, argc * sizeof (t_int)); ! noo->argc = argc; ! noo->next = NULL;
! if (callback_fifo == NULL) ! callback_fifo = fifo_init(); ! ! fifo_put(callback_fifo, noo); }
--- 679,702 ---- void sys_callback(t_int (*callback) (t_int* argv), t_int* argv, t_int argc) { ! t_sched_callback* noo = (t_sched_callback*) getbytes ! (sizeof(t_sched_callback));
! noo->function = callback; ! if (argv && argc) ! { ! noo->argv = (t_int*) copybytes (argv, argc * sizeof (t_int)); ! noo->argc = argc; ! } ! else ! { ! noo->argc = 0; ! noo->argv = NULL; ! } ! noo->next = NULL;
! if (callback_fifo == NULL) ! callback_fifo = fifo_init(); ! ! fifo_put(callback_fifo, noo); }
*************** *** 696,701 **** void sys_init_idle_callbacks(void) { ! callback_fifo = fifo_init(); /* tb: initialize fifo for idle callbacks */ ! }
static t_sched_callback *ringbuffer_head; --- 704,709 ---- void sys_init_idle_callbacks(void) { ! callback_fifo = fifo_init(); /* tb: initialize fifo for idle callbacks */ ! }
static t_sched_callback *ringbuffer_head; *************** *** 703,765 **** void run_all_idle_callbacks(void) { ! t_sched_callback * new_callback; ! /* append idle callback to ringbuffer */ ! while (new_callback = (t_sched_callback*) fifo_get(callback_fifo)) ! { ! t_sched_callback * next; ! ! /* set the next field to NULL ... it might be set in the fifo */ ! new_callback->next = NULL; ! if (ringbuffer_head == NULL) ! { ! ringbuffer_head = new_callback; ! } ! else ! { ! next = ringbuffer_head; ! while (next->next != 0) ! next = next->next; ! next->next = new_callback; ! } ! }
! if (ringbuffer_head != NULL) ! { ! t_sched_callback * idle_callback = ringbuffer_head; ! t_sched_callback * last = NULL; ! t_sched_callback * next;
! do ! { ! int status; ! status = (idle_callback->function)(idle_callback->argv); ! ! switch (status) ! { ! /* callbacks returning 0 will be deleted */ ! case 0: ! next = idle_callback->next; ! freebytes (idle_callback->argv, idle_callback->argc); ! freebytes ((void*)idle_callback, sizeof(t_sched_callback)); ! ! if (last == NULL) ! ringbuffer_head = next; ! else ! last->next = next; ! ! idle_callback = next; ! ! /* callbacks returning 1 will be run again */ ! case 1: ! break;
! /* callbacks returning 2 will be run during the next idle callback */ ! case 2: ! last = idle_callback; ! idle_callback = idle_callback->next; ! }
} ! while ((idle_callback != NULL)); } } --- 711,774 ---- void run_all_idle_callbacks(void) { ! t_sched_callback * new_callback; ! /* append idle callback to ringbuffer */ ! while (new_callback = (t_sched_callback*) fifo_get(callback_fifo)) ! { ! t_sched_callback * next; ! ! /* set the next field to NULL ... it might be set in the fifo */ ! new_callback->next = NULL; ! if (ringbuffer_head == NULL) ! { ! ringbuffer_head = new_callback; ! } ! else ! { ! next = ringbuffer_head; ! while (next->next != 0) ! next = next->next; ! next->next = new_callback; ! } ! }
! if (ringbuffer_head != NULL) ! { ! t_sched_callback * idle_callback = ringbuffer_head; ! t_sched_callback * last = NULL; ! t_sched_callback * next;
! do ! { ! int status; ! status = (idle_callback->function)(idle_callback->argv); ! ! switch (status) ! { ! /* callbacks returning 0 will be deleted */ ! case 0: ! next = idle_callback->next; ! if (idle_callback->argv) ! freebytes (idle_callback->argv, idle_callback->argc); ! freebytes ((void*)idle_callback, sizeof(t_sched_callback)); ! ! if (last == NULL) ! ringbuffer_head = next; ! else ! last->next = next; ! ! idle_callback = next; ! ! /* callbacks returning 1 will be run again */ ! case 1: ! break;
! /* callbacks returning 2 will be run during the next idle callback */ ! case 2: ! last = idle_callback; ! idle_callback = idle_callback->next; ! }
} ! while ((idle_callback != NULL)); } } *************** *** 767,848 **** static void run_idle_callbacks(int microsec) { ! t_sched_callback * new_callback; ! double stop;
! sys_unlock(); ! ! stop = sys_getrealtime()*1.e6 + (double)microsec;
! /* append idle callback to ringbuffer */ ! while (new_callback = (t_sched_callback*) fifo_get(callback_fifo)) ! { ! t_sched_callback * next; ! ! /* set the next field to NULL ... it might be set in the fifo */ ! new_callback->next = NULL; ! if (ringbuffer_head == NULL) ! { ! ringbuffer_head = new_callback; ! } ! else ! { ! next = ringbuffer_head; ! while (next->next != 0) ! next = next->next; ! next->next = new_callback; ! } ! }
! if (ringbuffer_head != NULL) ! { double remain = stop - sys_getrealtime() * 1.e6; ! t_sched_callback * idle_callback = ringbuffer_head; ! t_sched_callback * last = NULL; ! t_sched_callback * next;
! do ! { ! int status; ! sys_lock(); ! status = (idle_callback->function)(idle_callback->argv); ! sys_unlock(); ! ! switch (status) ! { ! /* callbacks returning 0 will be deleted */ ! case 0: ! next = idle_callback->next; if (idle_callback->argc) freebytes (idle_callback->argv, idle_callback->argc); ! freebytes ((void*)idle_callback, sizeof(t_sched_callback)); ! ! if (last == NULL) ! ringbuffer_head = next; ! else ! last->next = next; ! ! idle_callback = next; ! ! /* callbacks returning 1 will be run again */ ! case 1: ! break;
! /* callbacks returning 2 will be run during the next idle callback */ ! case 2: ! last = idle_callback; ! 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 > 0) ! sys_microsleep(remain); ! } else ! sys_microsleep(microsec); ! sys_lock(); } /* } tb */ --- 776,857 ---- static void run_idle_callbacks(int microsec) { ! t_sched_callback * new_callback; ! double stop;
! sys_unlock(); ! ! stop = sys_getrealtime()*1.e6 + (double)microsec;
! /* append idle callback to ringbuffer */ ! while (new_callback = (t_sched_callback*) fifo_get(callback_fifo)) ! { ! t_sched_callback * next; ! ! /* set the next field to NULL ... it might be set in the fifo */ ! new_callback->next = NULL; ! if (ringbuffer_head == NULL) ! { ! ringbuffer_head = new_callback; ! } ! else ! { ! next = ringbuffer_head; ! while (next->next != 0) ! next = next->next; ! next->next = new_callback; ! } ! }
! if (ringbuffer_head != NULL) ! { double remain = stop - sys_getrealtime() * 1.e6; ! t_sched_callback * idle_callback = ringbuffer_head; ! t_sched_callback * last = NULL; ! t_sched_callback * next;
! do ! { ! int status; ! sys_lock(); ! status = (idle_callback->function)(idle_callback->argv); ! sys_unlock(); ! ! switch (status) ! { ! /* callbacks returning 0 will be deleted */ ! case 0: ! next = idle_callback->next; if (idle_callback->argc) freebytes (idle_callback->argv, idle_callback->argc); ! freebytes ((void*)idle_callback, sizeof(t_sched_callback)); ! ! if (last == NULL) ! ringbuffer_head = next; ! else ! last->next = next; ! ! idle_callback = next; ! ! /* callbacks returning 1 will be run again */ ! case 1: ! break;
! /* callbacks returning 2 will be run during the next idle callback */ ! case 2: ! last = idle_callback; ! 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 > 0) ! sys_microsleep(remain); ! } else ! sys_microsleep(microsec); ! sys_lock(); } /* } tb */ *************** *** 850,864 **** void sys_setscheduler(int scheduler) { ! sys_keepsched = 0; ! sys_callbackscheduler = scheduler; ! return; }
int sys_getscheduler(void) { ! return sys_callbackscheduler; }
! static t_int sys_xrun_notification_callback(t_int * dumy) { t_symbol * pd = gensym("pd"); --- 859,873 ---- void sys_setscheduler(int scheduler) { ! sys_keepsched = 0; ! sys_callbackscheduler = scheduler; ! return; }
int sys_getscheduler(void) { ! return sys_callbackscheduler; }
! static t_int sys_xrun_notification_callback(t_int * dummy) { t_symbol * pd = gensym("pd"); *************** *** 877,881 ****
! static t_int sys_lock_timeout_notification_callback(t_int * dumy) { t_symbol * pd = gensym("pd"); --- 886,890 ----
! static t_int sys_lock_timeout_notification_callback(t_int * dummy) { t_symbol * pd = gensym("pd");