Update of /cvsroot/pure-data/pd/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10680
Modified Files: Tag: devel_0_38 m_sched.c Log Message: updating idle callback system
Index: m_sched.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/m_sched.c,v retrieving revision 1.5.4.10 retrieving revision 1.5.4.11 diff -C2 -d -r1.5.4.10 -r1.5.4.11 *** m_sched.c 29 Nov 2004 21:31:23 -0000 1.5.4.10 --- m_sched.c 2 Dec 2004 15:19:15 -0000 1.5.4.11 *************** *** 27,31 **** --- 27,34 ---- int sys_callbackscheduler = 0; /* if 1: change scheduler to callback based dsp */
+ #include "m_fifo.h" static t_int run_idle_callbacks(void); + static t_sched_callback * idle_callback = NULL; + /* tb: }*/
*************** *** 413,416 **** --- 416,422 ---- sys_sleepgrain = 5000; sys_initmidiqueue(); + + callback_fifo = fifo_init(); /* tb: initialize fifo for idle callbacks */ + while (!sys_quit) { *************** *** 612,684 **** * { */
! #if 1 ! /* linked list of callbacks ! * callback will be freed after returning 0 */ ! typedef struct _sched_callback ! { ! t_int (*function) (t_int* argv); ! t_int* argv; ! t_int argc; ! struct _sched_callback* next; ! } t_sched_callback; ! ! /* this is not save ... possibly not atomic */ ! static volatile t_sched_callback * cb_fifo_begin = NULL; ! static volatile t_sched_callback * cb_fifo_end = NULL; ! ! void set_callback(t_int (*callback) (t_int* argv), t_int* argv, t_int argc) ! { ! t_sched_callback* new = (t_sched_callback*) getbytes ! (sizeof(t_sched_callback)); ! ! new->function = callback; ! new->argv = (t_int*) copybytes (argv, argc * sizeof (t_int)); ! new->argc = argc; ! new->next = NULL; ! ! if (cb_fifo_begin != NULL) ! { ! cb_fifo_end->next = new; ! cb_fifo_end = new; ! } ! else ! { ! cb_fifo_begin = new; ! cb_fifo_end = new; ! } ! ! } ! ! ! static t_int run_idle_callbacks(void) ! { ! if (cb_fifo_begin) ! { ! double stop = sys_getrealtime() + sys_sleepgrain; ! ! do ! { ! int resume = cb_fifo_begin->function(cb_fifo_begin->argv); ! ! if (resume == 0) ! { ! t_sched_callback* next = cb_fifo_begin->next; ! ! freebytes (cb_fifo_begin->argv, cb_fifo_begin->argc); ! freebytes ((void*)cb_fifo_begin, sizeof(t_sched_callback)); ! ! cb_fifo_begin = next; ! } ! } ! while ( sys_getrealtime() > stop && cb_fifo_begin); ! ! return 0; /* don't sleep */ ! } ! return 1; /* sleep now */ ! } ! ! ! #else ! #include "m_lockfree_fifo.h"
--- 618,622 ---- * { */
! #include "m_fifo.h"
*************** *** 709,719 **** }
- static t_sched_callback * idle_callback = NULL; - static t_int run_idle_callbacks(void) { - if (callback_fifo == NULL) - callback_fifo = fifo_init(); - if (idle_callback == NULL) idle_callback = (t_sched_callback*) fifo_get(callback_fifo); --- 647,652 ----