Update of /cvsroot/pure-data/pd/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28387
Modified Files: Tag: desiredata makefile.in m_sched.c s_loader.c s_inter.c s_main.c Log Message: s_loader.c and m_sched.c go c++
Index: s_inter.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/s_inter.c,v retrieving revision 1.5.4.10.2.25.2.15 retrieving revision 1.5.4.10.2.25.2.16 diff -C2 -d -r1.5.4.10.2.25.2.15 -r1.5.4.10.2.25.2.16 *** s_inter.c 28 Jun 2007 04:43:07 -0000 1.5.4.10.2.25.2.15 --- s_inter.c 28 Jun 2007 05:23:32 -0000 1.5.4.10.2.25.2.16 *************** *** 559,563 ****
#ifdef __linux__ ! extern "C" void glob_watchdog(t_pd *dummy) { #ifndef WATCHDOGTHREAD --- 559,563 ----
#ifdef __linux__ ! void glob_watchdog(t_pd *dummy) { #ifndef WATCHDOGTHREAD
Index: s_loader.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/s_loader.c,v retrieving revision 1.4.4.5.2.10.2.2 retrieving revision 1.4.4.5.2.10.2.3 diff -C2 -d -r1.4.4.5.2.10.2.2 -r1.4.4.5.2.10.2.3 *** s_loader.c 20 Dec 2006 08:29:02 -0000 1.4.4.5.2.10.2.2 --- s_loader.c 28 Jun 2007 05:23:32 -0000 1.4.4.5.2.10.2.3 *************** *** 18,22 **** #endif #include <string.h> ! #include "m_pd.h" #include "s_stuff.h" #include <stdio.h> --- 18,22 ---- #endif #include <string.h> ! #include "desire.h" #include "s_stuff.h" #include <stdio.h> *************** *** 61,76 ****
static t_loadlist *sys_loaded; ! int sys_onloadlist(char *classname) /* return true if already loaded */ ! { t_symbol *s = gensym(classname); t_loadlist *ll; for (ll = sys_loaded; ll; ll = ll->ll_next) if (ll->ll_name == s) ! return (1); ! return (0); }
! void sys_putonloadlist(char *classname) /* add to list of loaded modules */ ! { t_loadlist *ll = (t_loadlist *)getbytes(sizeof(*ll)); ll->ll_name = gensym(classname); --- 61,76 ----
static t_loadlist *sys_loaded; ! /* return true if already loaded */ ! int sys_onloadlist(char *classname) { t_symbol *s = gensym(classname); t_loadlist *ll; for (ll = sys_loaded; ll; ll = ll->ll_next) if (ll->ll_name == s) ! return 1; ! return 0; }
! /* add to list of loaded modules */ ! void sys_putonloadlist(char *classname) { t_loadlist *ll = (t_loadlist *)getbytes(sizeof(*ll)); ll->ll_name = gensym(classname); *************** *** 80,87 **** }
! void class_set_extern_dir(t_symbol *s); ! ! static int sys_do_load_lib(t_canvas *canvas, char *objectname) ! { char symname[MAXPDSTRING], filename[MAXPDSTRING], dirbuf[MAXPDSTRING], *classname, *nameptr; void *dlobj; --- 80,84 ---- }
! static int sys_do_load_lib(t_canvas *canvas, char *objectname) { char symname[MAXPDSTRING], filename[MAXPDSTRING], dirbuf[MAXPDSTRING], *classname, *nameptr; void *dlobj; *************** *** 91,95 **** HINSTANCE ntdll; #endif ! if (classname = strrchr(objectname, '/')) classname++; else classname = objectname; --- 88,92 ---- HINSTANCE ntdll; #endif ! if ((classname = strrchr(objectname, '/'))) classname++; else classname = objectname; *************** *** 97,101 **** { post("%s: already loaded", objectname); ! return (1); } for (i = 0, nameptr = classname; i < MAXPDSTRING-7 && *nameptr; nameptr++) --- 94,98 ---- { post("%s: already loaded", objectname); ! return 1; } for (i = 0, nameptr = classname; i < MAXPDSTRING-7 && *nameptr; nameptr++) *************** *** 152,156 **** dirbuf, &nameptr, MAXPDSTRING, 1)) >= 0) goto gotone; ! return (0); gotone: close(fd); --- 149,153 ---- dirbuf, &nameptr, MAXPDSTRING, 1)) >= 0) goto gotone; ! return 0; gotone: close(fd); *************** *** 170,174 **** post("%s: %s", filename, dlerror()); class_set_extern_dir(&s_); ! return (0); } makeout = (t_xxx)dlsym(dlobj, symname); --- 167,171 ---- post("%s: %s", filename, dlerror()); class_set_extern_dir(&s_); ! return 0; } makeout = (t_xxx)dlsym(dlobj, symname); *************** *** 181,185 **** post("%s: couldn't load", filename); class_set_extern_dir(&s_); ! return (0); } makeout = (t_xxx)GetProcAddress(ntdll, symname); --- 178,182 ---- post("%s: couldn't load", filename); class_set_extern_dir(&s_); ! return 0; } makeout = (t_xxx)GetProcAddress(ntdll, symname); *************** *** 195,199 **** class_set_extern_dir(&s_); sys_putonloadlist(objectname); ! return (1); }
--- 192,196 ---- class_set_extern_dir(&s_); sys_putonloadlist(objectname); ! return 1; }
Index: s_main.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/s_main.c,v retrieving revision 1.7.4.17.2.22.2.17 retrieving revision 1.7.4.17.2.22.2.18 diff -C2 -d -r1.7.4.17.2.22.2.17 -r1.7.4.17.2.22.2.18 *** s_main.c 28 Jun 2007 04:43:07 -0000 1.7.4.17.2.22.2.17 --- s_main.c 28 Jun 2007 05:23:32 -0000 1.7.4.17.2.22.2.18 *************** *** 35,45 **** #endif
! extern "C" void pd_init(void); extern "C" int sys_argparse(int argc, char **argv); void sys_findprogdir(char *progname); ! int sys_startgui(void); ! extern "C" void sys_init_idle_callbacks(void); ! extern "C" int sys_rcfile(void); ! extern "C" int m_scheduler(void); void sys_addhelppath(char *p); extern "C" void alsa_adddev(char *name); --- 35,45 ---- #endif
! extern "C" void pd_init(); extern "C" int sys_argparse(int argc, char **argv); void sys_findprogdir(char *progname); ! int sys_startgui(); ! void sys_init_idle_callbacks(); ! extern "C" int sys_rcfile(); ! extern int m_scheduler(); void sys_addhelppath(char *p); extern "C" void alsa_adddev(char *name); *************** *** 47,51 ****
#ifdef THREADED_SF ! void sys_start_sfthread(void); #endif /* THREDED_SF */
--- 47,51 ----
#ifdef THREADED_SF ! void sys_start_sfthread(); #endif /* THREDED_SF */
*************** *** 115,119 **** /* } jsarlo */
! static void sys_afterargparse(void);
EXTERN t_hash *class_table; --- 115,119 ---- /* } jsarlo */
! static void sys_afterargparse();
EXTERN t_hash *class_table; *************** *** 150,159 ****
if (sys_argparse(argc-1, argv+1)) /* parse cmd line */ ! return (1); sys_afterargparse(); /* post-argparse settings */ if (sys_verbose || sys_version) fprintf(stderr, "%scompiled %s %s\n", pd_version, pd_compiletime, pd_compiledate); if (sys_version) /* if we were just asked our version, exit here. */ ! return (0);
if (sys_startgui()) return 1; /* start the gui */ --- 150,159 ----
if (sys_argparse(argc-1, argv+1)) /* parse cmd line */ ! return 1; sys_afterargparse(); /* post-argparse settings */ if (sys_verbose || sys_version) fprintf(stderr, "%scompiled %s %s\n", pd_version, pd_compiletime, pd_compiledate); if (sys_version) /* if we were just asked our version, exit here. */ ! return 0;
if (sys_startgui()) return 1; /* start the gui */ *************** *** 184,191 **** sys_bashfilename(filename, filename); ntdll = LoadLibrary(filename); ! if (!ntdll) ! { post("%s: couldn't load external scheduler lib ", filename); ! return (0); } externalmainfunc = (t_externalschedlibmain)GetProcAddress(ntdll, --- 184,190 ---- sys_bashfilename(filename, filename); ntdll = LoadLibrary(filename); ! if (!ntdll) { post("%s: couldn't load external scheduler lib ", filename); ! return 0; } externalmainfunc = (t_externalschedlibmain)GetProcAddress(ntdll, *************** *** 193,206 **** return((*externalmainfunc)(sys_extraflagsstring)); #else ! return (0); #endif ! } ! else ! { /* open audio and MIDI */ sys_reopen_midi(); sys_reopen_audio(); /* run scheduler until it quits */ ! return (m_scheduler()); } /* } jsarlo */ --- 192,203 ---- return((*externalmainfunc)(sys_extraflagsstring)); #else ! return 0; #endif ! } else { /* open audio and MIDI */ sys_reopen_midi(); sys_reopen_audio(); /* run scheduler until it quits */ ! return m_scheduler(); } /* } jsarlo */ *************** *** 645,665 **** return 1; } ! for (; argc > 0; argc--, argv++) ! sys_openlist = namelist_append_files(sys_openlist, *argv); ! ! return 0; }
! int sys_getblksize(void) ! { ! return (sys_dacblocksize); ! }
/* stuff to do, once, after calling sys_argparse() -- which may itself be called more than once (first from "settings, second from .pdrc, then from command-line arguments */ ! static void sys_afterargparse(void) ! { char sbuf[MAXPDSTRING]; int i; --- 642,655 ---- return 1; } ! for (; argc > 0; argc--, argv++) sys_openlist = namelist_append_files(sys_openlist, *argv); return 0; }
! int sys_getblksize() {return sys_dacblocksize;}
/* stuff to do, once, after calling sys_argparse() -- which may itself be called more than once (first from "settings, second from .pdrc, then from command-line arguments */ ! static void sys_afterargparse() { char sbuf[MAXPDSTRING]; int i; *************** *** 696,755 **** if (sys_listplease) sys_listdevs(); ! ! /* get the current audio parameters. These are set ! by the preferences mechanism (sys_loadpreferences()) or ! else are the default. Overwrite them with any results ! of argument parsing, and store them again. */ sys_get_audio_params(&naudioindev, audioindev, chindev, &naudiooutdev, audiooutdev, choutdev, &rate, &dacblksize, &advance, &scheduler); ! if (sys_nchin >= 0) ! { nchindev = sys_nchin; ! for (i = 0; i < nchindev; i++) ! chindev[i] = sys_chinlist[i]; ! } ! else nchindev = naudioindev; ! if (sys_nsoundin >= 0) ! { naudioindev = sys_nsoundin; ! for (i = 0; i < naudioindev; i++) ! audioindev[i] = sys_soundindevlist[i]; } ! ! if (sys_nchout >= 0) ! { nchoutdev = sys_nchout; ! for (i = 0; i < nchoutdev; i++) ! choutdev[i] = sys_choutlist[i]; ! } ! else nchoutdev = naudiooutdev; ! if (sys_nsoundout >= 0) ! { naudiooutdev = sys_nsoundout; ! for (i = 0; i < naudiooutdev; i++) ! audiooutdev[i] = sys_soundoutdevlist[i]; } ! if (sys_nmidiin >= 0) ! { nmidiindev = sys_nmidiin; ! for (i = 0; i < nmidiindev; i++) ! midiindev[i] = sys_midiindevlist[i]; } ! if (sys_nmidiout >= 0) ! { nmidioutdev = sys_nmidiout; ! for (i = 0; i < nmidioutdev; i++) ! midioutdev[i] = sys_midioutdevlist[i]; } ! if (sys_main_advance) ! advance = sys_main_advance; ! if (sys_main_srate) ! rate = sys_main_srate; ! if (sys_main_dacblocksize) ! dacblksize = sys_main_dacblocksize; sys_open_audio(naudioindev, audioindev, nchindev, chindev, ! naudiooutdev, audiooutdev, nchoutdev, choutdev, rate, dacblksize, advance, scheduler, 0); ! ! sys_open_midi(nmidiindev, midiindev, nmidioutdev, midioutdev, 0); } --- 686,726 ---- if (sys_listplease) sys_listdevs(); ! ! /* get the current audio parameters. These are set ! by the preferences mechanism (sys_loadpreferences()) or ! else are the default. Overwrite them with any results ! of argument parsing, and store them again. */ sys_get_audio_params(&naudioindev, audioindev, chindev, &naudiooutdev, audiooutdev, choutdev, &rate, &dacblksize, &advance, &scheduler); ! if (sys_nchin >= 0) { nchindev = sys_nchin; ! for (i=0; i<nchindev; i++) chindev[i] = sys_chinlist[i]; ! } else nchindev = naudioindev; ! if (sys_nsoundin >= 0) { naudioindev = sys_nsoundin; ! for (i=0; i<naudioindev; i++) audioindev[i] = sys_soundindevlist[i]; } ! if (sys_nchout >= 0) { nchoutdev = sys_nchout; ! for (i=0; i<nchoutdev; i++) choutdev[i] = sys_choutlist[i]; ! } else nchoutdev = naudiooutdev; ! if (sys_nsoundout >= 0) { naudiooutdev = sys_nsoundout; ! for (i=0; i<naudiooutdev; i++) audiooutdev[i] = sys_soundoutdevlist[i]; } ! if (sys_nmidiin >= 0) { nmidiindev = sys_nmidiin; ! for (i=0; i<nmidiindev; i++) midiindev[i] = sys_midiindevlist[i]; } ! if (sys_nmidiout >= 0) { nmidioutdev = sys_nmidiout; ! for (i=0; i<nmidioutdev; i++) midioutdev[i] = sys_midioutdevlist[i]; } ! if (sys_main_advance) advance = sys_main_advance; ! if (sys_main_srate) rate = sys_main_srate; ! if (sys_main_dacblocksize) dacblksize = sys_main_dacblocksize; sys_open_audio(naudioindev, audioindev, nchindev, chindev, ! naudiooutdev, audiooutdev, nchoutdev, choutdev, ! rate, dacblksize, advance, scheduler, 0); sys_open_midi(nmidiindev, midiindev, nmidioutdev, midioutdev, 0); }
Index: m_sched.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/m_sched.c,v retrieving revision 1.5.4.35.2.21.2.4 retrieving revision 1.5.4.35.2.21.2.5 diff -C2 -d -r1.5.4.35.2.21.2.4 -r1.5.4.35.2.21.2.5 *** m_sched.c 9 Jan 2007 17:14:09 -0000 1.5.4.35.2.21.2.4 --- m_sched.c 28 Jun 2007 05:23:32 -0000 1.5.4.35.2.21.2.5 *************** *** 42,46 **** /* tb: }*/
! int sys_usecsincelastsleep(void); int sys_sleepgrain;
--- 42,46 ---- /* tb: }*/
! int sys_usecsincelastsleep (); int sys_sleepgrain;
*************** *** 113,117 ****
/* OBSOLETE NAME */ ! double clock_getsystime(void) {return sys_time;}
/* elapsed time in milliseconds since the given system time */ --- 113,117 ----
/* OBSOLETE NAME */ ! double clock_getsystime () {return sys_time;}
/* elapsed time in milliseconds since the given system time */ *************** *** 140,144 **** static int sched_diddsp, sched_didpoll, sched_didnothing;
! void sys_clearhist(void) { unsigned i,j; for (i=0; i<NHIST; i++) for (j=0; j<NBIN; j++) sys_histogram[i][j] = 0; --- 140,144 ---- static int sched_diddsp, sched_didpoll, sched_didnothing;
! void sys_clearhist () { unsigned i,j; for (i=0; i<NHIST; i++) for (j=0; j<NBIN; j++) sys_histogram[i][j] = 0; *************** *** 147,151 **** }
! void sys_printhist(void) { unsigned i,j; for (i=0; i<NHIST; i++) { --- 147,151 ---- }
! void sys_printhist () { unsigned i,j; for (i=0; i<NHIST; i++) { *************** *** 167,175 **** int j, phasewas = sys_histphase; double newtime = sys_getrealtime(); ! int msec = (newtime - sys_histtime) * 1000.; ! for (j = NBIN-1; j >= 0; j--) ! { ! if (msec >= sys_bin[j]) ! { sys_histogram[phasewas][j]++; break; --- 167,173 ---- int j, phasewas = sys_histphase; double newtime = sys_getrealtime(); ! int msec = int((newtime-sys_histtime)*1000.); ! for (j = NBIN-1; j >= 0; j--) { ! if (msec >= sys_bin[j]) { sys_histogram[phasewas][j]++; break; *************** *** 178,182 **** sys_histtime = newtime; sys_histphase = phase; ! return (phasewas); }
--- 176,180 ---- sys_histtime = newtime; sys_histphase = phase; ! return phasewas; }
*************** *** 204,209 **** };
! void glob_audiostatus(void) ! { int nresync, nresyncphase, i; nresync = (oss_nresync >= NRESYNC ? NRESYNC : oss_nresync); --- 202,206 ---- };
! void glob_audiostatus (void *dummy) { int nresync, nresyncphase, i; nresync = (oss_nresync >= NRESYNC ? NRESYNC : oss_nresync); *************** *** 248,255 **** }
! static int sched_lastinclip, sched_lastoutclip, ! sched_lastindb, sched_lastoutdb; ! ! void glob_watchdog(t_pd *dummy);
static void sched_pollformeters( void) --- 245,249 ---- }
! static int sched_lastinclip, sched_lastoutclip, sched_lastindb, sched_lastoutdb;
static void sched_pollformeters( void) *************** *** 281,286 **** float inmax, outmax; sys_getmeters(&inmax, &outmax); ! indb = 0.5 + rmstodb(inmax); ! outdb = 0.5 + rmstodb(outmax); inclip = (inmax > 0.999); outclip = (outmax >= 1.0); --- 275,280 ---- float inmax, outmax; sys_getmeters(&inmax, &outmax); ! indb = int(0.5 + rmstodb(inmax)); ! outdb = int(0.5 + rmstodb(outmax)); inclip = (inmax > 0.999); outclip = (outmax >= 1.0); *************** *** 321,325 **** #endif
! void dsp_tick(void);
static int sched_usedacs = 0; --- 315,319 ---- #endif
! extern "C" void dsp_tick ();
static int sched_usedacs = 0; *************** *** 386,415 **** void sys_initmidiqueue( void);
! int m_scheduler(void) ! { int idlecount = 0; ! 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(); ! ! while (!sys_quit) ! { if (!sys_callbackscheduler || !sched_usedacs) ! while (sys_keepsched) ! { int didsomething = 0; int timeforward; - waitfortick: if (sched_usedacs) --- 380,398 ---- void sys_initmidiqueue( void);
! int m_scheduler () { int idlecount = 0; ! 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(); ! while (!sys_quit) { if (!sys_callbackscheduler || !sched_usedacs) ! while (sys_keepsched) { int didsomething = 0; int timeforward; waitfortick: if (sched_usedacs) *************** *** 429,434 **** if (idlecount == 32) idletime = sys_getrealtime(); ! else if (sys_getrealtime() - idletime > 1.) ! { post("audio I/O stuck... closing audio\n"); sys_close_audio(); --- 412,416 ---- if (idlecount == 32) idletime = sys_getrealtime(); ! else if (sys_getrealtime() - idletime > 1.) { post("audio I/O stuck... closing audio\n"); sys_close_audio(); *************** *** 438,444 **** } } ! } ! else ! { if (1000. * (sys_getrealtime() - sched_referencerealtime) > clock_gettimesince(sched_referencelogicaltime)) --- 420,424 ---- } } ! } else { if (1000. * (sys_getrealtime() - sched_referencerealtime) > clock_gettimesince(sched_referencelogicaltime)) *************** *** 447,475 **** } 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); ! } } } --- 427,441 ---- } 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); } } *************** *** 484,491 **** sys_pollmidiqueue(); sys_setmiditimediff(0, 1e-6 * sys_schedadvance); - if (sys_pollgui()) continue; - /* do graphics updates and run idle callbacks */ sched_pollformeters(); --- 450,455 ---- *************** *** 497,501 **** sys_close_audio(); sys_unlock(); ! return (0); }
--- 461,465 ---- sys_close_audio(); sys_unlock(); ! return 0; }
*************** *** 508,524 **** static pthread_cond_t sys_cond = PTHREAD_COND_INITIALIZER;
! void sys_lock(void) ! { pthread_mutex_lock(&sys_mutex); } ! ! void sys_unlock(void) ! { pthread_mutex_unlock(&sys_mutex); pthread_cond_signal(&sys_cond); } ! ! int sys_trylock(void) ! { return pthread_mutex_trylock(&sys_mutex); } --- 472,483 ---- static pthread_cond_t sys_cond = PTHREAD_COND_INITIALIZER;
! void sys_lock () { pthread_mutex_lock(&sys_mutex); } ! void sys_unlock () { pthread_mutex_unlock(&sys_mutex); pthread_cond_signal(&sys_cond); } ! int sys_trylock () { return pthread_mutex_trylock(&sys_mutex); } *************** *** 529,545 **** #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 ((FILETIME*) &now); tv->tv_usec = (long) ((now / 10LL) % 1000000LL); tv->tv_sec = (long) ((now - 116444736000000000LL) / 10000000LL); ! return (0); ! } #endif
! ! #if 0 /* osx doesn't define a pthread_mutex_timedlock ... maybe someday it will ... */ --- 488,501 ---- #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 ((FILETIME*) &now); tv->tv_usec = (long) ((now / 10LL) % 1000000LL); tv->tv_sec = (long) ((now - 116444736000000000LL) / 10000000LL); ! return 0; ! } #endif
! #if 0 /* osx doesn't define a pthread_mutex_timedlock ... maybe someday it will ... */ *************** *** 549,608 **** 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, %d", ret); ! return ret; } #else
! 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; } --- 505,540 ---- int ret; struct timeval now; /* timedlock seems to have a resolution of 1ms */ ! if (microsec < 1000) microsec = 1000; 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, %d", ret); return ret; } #else
! int sys_timedlock(int microsec) { struct timespec timeout; int ret; struct timeval now; ! if (sys_trylock() == 0) return 0; ! if (microsec < 1000) microsec = 1000; ! gettimeofday(&now,0); timeout.tv_sec = now.tv_sec; timeout.tv_nsec = (now.tv_usec + microsec) * 1000; ! while (timeout.tv_nsec > 1000000000) { timeout.tv_sec += 1; ! timeout.tv_nsec -= 1000000000; } ! /* 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; } *************** *** 611,623 ****
#else ! ! void sys_lock(void) {} ! void sys_unlock(void) {} ! int sys_trylock(void) { return 0; } ! int sys_timedlock(int microsec) { return 0; } ! #endif
- /* ------------ soft quit ------------------- */ /* added by Thomas Grill - --- 543,552 ----
#else ! void sys_lock () {} ! void sys_unlock () {} ! int sys_trylock () { return 0; } ! int sys_timedlock (int microsec) { return 0; } #endif
/* ------------ soft quit ------------------- */ /* added by Thomas Grill - *************** *** 626,631 **** */
! void sys_exit(void) ! { sys_keepsched = 0; sys_quit = 1; --- 555,559 ---- */
! void sys_exit () { sys_keepsched = 0; sys_quit = 1; *************** *** 660,664 **** }
! void sys_init_idle_callbacks(void) { callback_fifo = fifo_init(); /* tb: initialize fifo for idle callbacks */ } --- 588,592 ---- }
! void sys_init_idle_callbacks () { callback_fifo = fifo_init(); /* tb: initialize fifo for idle callbacks */ } *************** *** 666,673 **** static t_sched_callback *ringbuffer_head = NULL;
! 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 0 ... it might be set in the fifo */ --- 594,601 ---- static t_sched_callback *ringbuffer_head = NULL;
! extern "C" void run_all_idle_callbacks () { 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 0 ... it might be set in the fifo */ *************** *** 713,717 **** stop = sys_getrealtime()*1.e6 + (double)microsec; /* append idle callback to ringbuffer */ ! while (new_callback = (t_sched_callback*) fifo_get(callback_fifo)) { /* set the next field to NULL ... it might be set in the fifo */ new_callback->next = 0; --- 641,645 ---- stop = sys_getrealtime()*1.e6 + (double)microsec; /* append idle callback to ringbuffer */ ! while ((new_callback = (t_sched_callback*) fifo_get(callback_fifo))) { /* set the next field to NULL ... it might be set in the fifo */ new_callback->next = 0; *************** *** 757,761 **** if(remain > 0) { sys_unlock(); ! sys_microsleep(remain); sys_lock(); } --- 685,689 ---- if(remain > 0) { sys_unlock(); ! sys_microsleep(int(remain)); sys_lock(); } *************** *** 774,778 **** }
! int sys_getscheduler(void) { return sys_callbackscheduler; } --- 702,706 ---- }
! int sys_getscheduler () { return sys_callbackscheduler; } *************** *** 785,789 **** }
! void sys_xrun_notification(void) { sys_callback(sys_xrun_notification_callback, 0, 0); } --- 713,717 ---- }
! extern "C" void sys_xrun_notification () { sys_callback(sys_xrun_notification_callback, 0, 0); } *************** *** 796,800 **** }
! void sys_lock_timeout_notification(void) { sys_callback(sys_lock_timeout_notification_callback, 0, 0); } --- 724,728 ---- }
! extern "C" void sys_lock_timeout_notification () { sys_callback(sys_lock_timeout_notification_callback, 0, 0); }
Index: makefile.in =================================================================== RCS file: /cvsroot/pure-data/pd/src/makefile.in,v retrieving revision 1.4.4.2.2.21.2.25 retrieving revision 1.4.4.2.2.21.2.26 diff -C2 -d -r1.4.4.2.2.21.2.25 -r1.4.4.2.2.21.2.26 *** makefile.in 28 Jun 2007 04:43:07 -0000 1.4.4.2.2.21.2.25 --- makefile.in 28 Jun 2007 05:23:32 -0000 1.4.4.2.2.21.2.26 *************** *** 21,27 **** CFLAGS += -DINSTALL_PREFIX="$(prefix)"
! SRCXX = desire.c kernel.c builtins.c builtins_dsp.c s_path.c s_inter.c s_main.c SRC = m_fifo.c m_simd.c \ ! m_sched.c s_loader.c s_audio.c s_midi.c \ d_ugen.c d_mayer_fft.c d_fftroutine.c d_resample.c d_soundfile.c
--- 21,28 ---- CFLAGS += -DINSTALL_PREFIX="$(prefix)"
! SRCXX = desire.c kernel.c builtins.c builtins_dsp.c s_path.c s_inter.c s_main.c \ ! m_sched.c s_loader.c SRC = m_fifo.c m_simd.c \ ! s_audio.c s_midi.c \ d_ugen.c d_mayer_fft.c d_fftroutine.c d_resample.c d_soundfile.c