Update of /cvsroot/pure-data/pd/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30377
Modified Files: Tag: devel_0_38 m_sched.c Log Message: updated callback fifo
Index: m_sched.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/m_sched.c,v retrieving revision 1.5.4.9 retrieving revision 1.5.4.10 diff -C2 -d -r1.5.4.9 -r1.5.4.10 *** m_sched.c 26 Nov 2004 10:11:04 -0000 1.5.4.9 --- m_sched.c 29 Nov 2004 21:31:23 -0000 1.5.4.10 *************** *** 394,400 **** int (*sys_idlehook)(void);
- - - int m_scheduler( void) { --- 394,397 ---- *************** *** 548,559 **** sys_unlock(); #endif ! ! /* sleep: the callback might run sched_tick during this time */ ! sys_microsleep(sys_sleepgrain / 10); ! ! /* call externally installed idle function if any. */ ! /* tb: is there a more elegant way to do this? */ ! // sys_idlehook(); ! #ifdef THREAD_LOCKING sys_lock(); --- 545,551 ---- sys_unlock(); #endif ! if (run_idle_callbacks()) ! sys_microsleep(sys_sleepgrain); ! #ifdef THREAD_LOCKING sys_lock(); *************** *** 688,693 ****
#else
! #error to be implemented
#endif --- 680,737 ----
#else + #include "m_lockfree_fifo.h"
! ! /* 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; ! } t_sched_callback; ! ! t_fifo * callback_fifo = 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; ! ! if (callback_fifo == NULL) ! callback_fifo = fifo_init(); ! ! fifo_put(callback_fifo, new); ! } ! ! 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); ! ! if (idle_callback != NULL) ! { ! double stop = sys_getrealtime() + sys_sleepgrain; ! do ! { ! if ( ((idle_callback->function)(idle_callback->argv)) == 0) ! { ! freebytes (idle_callback->argv, idle_callback->argc); ! freebytes ((void*)idle_callback, sizeof(t_sched_callback)); ! idle_callback = fifo_get(callback_fifo); ! } ! } ! while ( (sys_getrealtime() > stop) && (idle_callback != NULL)); ! } ! }
#endif