Update of /cvsroot/pure-data/pd/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2293
Modified Files: Tag: devel_0_38 s_inter.c Log Message: microsleep
Index: s_inter.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/s_inter.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 *** s_inter.c 11 May 2005 16:41:16 -0000 1.5.4.9 --- s_inter.c 14 May 2005 17:05:27 -0000 1.5.4.10 *************** *** 159,162 **** --- 159,163 ---- t_fdpoll *fp; fd_set readset, writeset, exceptset; + timout.tv_sec = 0; timout.tv_usec = 0; *************** *** 167,171 **** for (fp = sys_fdpoll, i = sys_nfdpoll; i--; fp++) FD_SET(fp->fdp_fd, &readset); - select(sys_maxfd+1, &readset, &writeset, &exceptset, &timout); for (i = 0; i < sys_nfdpoll; i++) --- 168,171 ---- *************** *** 180,192 **** void sys_microsleep(int microsec) { #ifndef MSW struct timespec rec, rem; rec.tv_sec = 0; ! rec.tv_nsec = 100 * microsec; nanosleep(&rec, &rem); #else - /* tb: sleep granularity on windows only 1ms??? */ Sleep(microsec/1000); #endif }
--- 180,224 ---- void sys_microsleep(int microsec) { + /* tb: + sleep granularity on "modern" operating systems is only 1ms??? + + linux: we might be better with the high precision posix timer kernel + patches ... + + windows: win9x doesn't implement a SwitchToThread function, so we can't + sleep for small timeslices + + osx: ??? + */ + + if (microsec < 1000) + microsec = 1000; #ifndef MSW struct timespec rec, rem; rec.tv_sec = 0; ! rec.tv_nsec = 1000 * microsec; nanosleep(&rec, &rem); #else Sleep(microsec/1000); #endif + + /* a solution for lower timeslices might be a busysleep but this might + block a low-prority thread and won't work for win9x + + #define _WIN32_WINNT 0x0400 + + + double end = sys_getrealtime() + (double)microsec * 1e-6; + do + { + #ifdef MSW + SwitchToThread(); + #else + sched_yield() + #endif + } + while(sys_getrealtime() < end); + + */ }
*************** *** 592,596 **** int bytestowrite = sys_guibuftail - sys_guibufhead; int written = 0; ! while (1) { int res = send(sys_guisock, --- 624,628 ---- int bytestowrite = sys_guibuftail - sys_guibufhead; int written = 0; ! while (1) { int res = send(sys_guisock, *************** *** 608,612 **** } } ! sys_guibufhead = sys_guibuftail = 0; } else --- 640,644 ---- } } ! sys_guibufhead = sys_guibuftail = 0; } else