Update of /cvsroot/pure-data/pd/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9904
Modified Files: Tag: devel_0_38 m_sched.c s_stuff.h s_audio.c Log Message: - sleepgrain cleanup - improved sys_timedlock
Index: s_audio.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/s_audio.c,v retrieving revision 1.5.4.14 retrieving revision 1.5.4.15 diff -C2 -d -r1.5.4.14 -r1.5.4.15 *** s_audio.c 13 May 2005 16:45:43 -0000 1.5.4.14 --- s_audio.c 15 May 2005 18:51:15 -0000 1.5.4.15 *************** *** 393,405 **** sched_set_using_dacs(enable);
! /* tb { ! * cut'n'paste from m_scheduler to adapt the sleepgrain with the latency */ ! sys_sleepgrain = sys_schedadvance/4; ! if (sys_sleepgrain < 100) ! sys_sleepgrain = 100; ! else ! if (sys_sleepgrain > 5000) ! sys_sleepgrain = 5000; ! /* } tb */ }
--- 393,397 ---- sched_set_using_dacs(enable);
! sys_update_sleepgrain(); }
*************** *** 1204,1206 **** --- 1196,1211 ---- rate, dacblocksize, advance, scheduler, 1); } + + + /* some general helper functions */ + void sys_update_sleepgrain(void) + { + sys_sleepgrain = sys_schedadvance/4; + if (sys_sleepgrain < 100) + sys_sleepgrain = 100; + else + if (sys_sleepgrain > 5000) + sys_sleepgrain = 5000; + } + /* tb } */
Index: m_sched.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/m_sched.c,v retrieving revision 1.5.4.32 retrieving revision 1.5.4.33 diff -C2 -d -r1.5.4.32 -r1.5.4.33 *** m_sched.c 13 May 2005 15:55:30 -0000 1.5.4.32 --- m_sched.c 15 May 2005 18:51:15 -0000 1.5.4.33 *************** *** 8,11 **** --- 8,21 ---- #include "m_imp.h" #include "s_stuff.h" + #include "m_fifo.h" + + /* for timeval */ + #ifdef UNISTD + #include "sys/time.h" + #endif + #ifdef MSW + #include "winsock.h" + #endif +
/* LATER consider making this variable. It's now the LCM of all sample *************** *** 27,31 **** int sys_callbackscheduler = 0; /* if 1: change scheduler to callback based dsp */
- #include "m_fifo.h"
static void run_idle_callbacks(int microsec); --- 37,40 ---- *************** *** 408,412 **** sys_time_per_dsp_tick = (TIMEUNITPERSEC) * ((double)sys_schedblocksize) / sys_dacsr; ! /* T.Grill - lock mutex */ sys_lock(); --- 417,421 ---- sys_time_per_dsp_tick = (TIMEUNITPERSEC) * ((double)sys_schedblocksize) / sys_dacsr; ! /* T.Grill - lock mutex */ sys_lock(); *************** *** 415,424 ****
/* tb: adapt sleepgrain with advance */ ! if (sys_schedadvance < 20000) ! sys_sleepgrain = sys_schedadvance/4; ! if (sys_sleepgrain < 100) ! sys_sleepgrain = 100; ! else if (sys_sleepgrain > 5000) ! sys_sleepgrain = 5000; sys_initmidiqueue();
--- 424,429 ----
/* tb: adapt sleepgrain with advance */ ! sys_update_sleepgrain(); ! sys_initmidiqueue();
*************** *** 558,577 **** /* tb { */ #include <errno.h> int sys_timedlock(int microsec) { - #if 0 /* pthread_mutex_timedlock is broken :-( */ struct timespec timeout; int ret; ! timeout.tv_sec = 0; ! timeout.tv_nsec = microsec * 1000; ret = pthread_mutex_timedlock(&sys_mutex, &timeout); return ret; - #else - /* todo: find a clean solution */ - sys_lock(); - return 0; - #endif } /* tb } */ --- 563,607 ---- /* tb { */ #include <errno.h> + + #ifdef MSW + /* gettimeofday isn't available on windoze ... */ + int gettimeofday (struct timeval *tv, void* tz) + { + __int64 now; /* time since 1 Jan 1601 in 100ns */ + + GetSystemTimeAsFileTime ((LPFILETIME*) &now); + tv->tv_usec = (long) ((now / 10LL) % 1000000LL); + tv->tv_sec = (long) ((now - 116444736000000000LL) / 10000000LL); + return (0); + } + #endif + int sys_timedlock(int microsec) { struct timespec timeout; int ret; ! struct timeval now; ! ! /* timedlock seems to have a resolution of 1ms */ ! 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; ! } ret = pthread_mutex_timedlock(&sys_mutex, &timeout); + + if (ret) + post("timeout"); return ret; } /* tb } */ *************** *** 603,608 **** * { */
- #include "m_fifo.h" - /* linked list of callbacks * callback will be freed after returning 0 */ --- 633,636 ----
Index: s_stuff.h =================================================================== RCS file: /cvsroot/pure-data/pd/src/s_stuff.h,v retrieving revision 1.5.4.8 retrieving revision 1.5.4.9 diff -C2 -d -r1.5.4.8 -r1.5.4.9 *** s_stuff.h 13 May 2005 17:01:48 -0000 1.5.4.8 --- s_stuff.h 15 May 2005 18:51:15 -0000 1.5.4.9 *************** *** 94,97 **** --- 94,101 ---- void sys_setblocksize(int n);
+ /* tb { */ + void sys_update_sleepgrain(void); + /* } */ + /* s_midi.c */ #define MAXMIDIINDEV 16 /* max. number of input ports */