summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/src/m_sched.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/pdbox/PDa/src/m_sched.c')
-rw-r--r--apps/plugins/pdbox/PDa/src/m_sched.c68
1 files changed, 62 insertions, 6 deletions
diff --git a/apps/plugins/pdbox/PDa/src/m_sched.c b/apps/plugins/pdbox/PDa/src/m_sched.c
index 9d3bed828a..104cc66c70 100644
--- a/apps/plugins/pdbox/PDa/src/m_sched.c
+++ b/apps/plugins/pdbox/PDa/src/m_sched.c
@@ -2,6 +2,11 @@
2* For information on usage and redistribution, and for a DISCLAIMER OF ALL 2* For information on usage and redistribution, and for a DISCLAIMER OF ALL
3* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ 3* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
4 4
5#ifdef ROCKBOX
6#include "plugin.h"
7#include "pdbox.h"
8#endif
9
5/* scheduling stuff */ 10/* scheduling stuff */
6 11
7#include "m_pd.h" 12#include "m_pd.h"
@@ -14,13 +19,21 @@
14 19
15 20
16/* T.Grill - enable PD global thread locking - sys_lock, sys_unlock, sys_trylock functions */ 21/* T.Grill - enable PD global thread locking - sys_lock, sys_unlock, sys_trylock functions */
17#define THREAD_LOCKING 22#ifndef ROCKBOX
23#define THREAD_LOCKING
18#include "pthread.h" 24#include "pthread.h"
25#endif
19 26
20 27
21static int sys_quit; 28static int sys_quit;
22static t_time sys_time; 29#ifndef ROCKBOX
23static t_time sys_time_per_msec = TIMEUNITPERSEC / 1000.; 30static
31#endif
32t_time sys_time;
33#ifndef ROCKBOX
34static
35#endif
36t_time sys_time_per_msec = TIMEUNITPERSEC / 1000.;
24 37
25int sys_schedblocksize = DEFDACBLKSIZE; 38int sys_schedblocksize = DEFDACBLKSIZE;
26int sys_usecsincelastsleep(void); 39int sys_usecsincelastsleep(void);
@@ -133,9 +146,12 @@ static int sys_bin[] = {0, 2, 5, 10, 20, 30, 50, 100, 1000};
133#define NBIN (sizeof(sys_bin)/sizeof(*sys_bin)) 146#define NBIN (sizeof(sys_bin)/sizeof(*sys_bin))
134#define NHIST 10 147#define NHIST 10
135static int sys_histogram[NHIST][NBIN]; 148static int sys_histogram[NHIST][NBIN];
149#ifndef ROCKBOX
136static t_time sys_histtime; 150static t_time sys_histtime;
151#endif
137static int sched_diddsp, sched_didpoll, sched_didnothing; 152static int sched_diddsp, sched_didpoll, sched_didnothing;
138 153
154#ifndef ROCKBOX
139static void sys_clearhist( void) 155static void sys_clearhist( void)
140{ 156{
141 unsigned int i, j; 157 unsigned int i, j;
@@ -144,6 +160,7 @@ static void sys_clearhist( void)
144 sys_histtime = sys_getrealtime(); 160 sys_histtime = sys_getrealtime();
145 sched_diddsp = sched_didpoll = sched_didnothing = 0; 161 sched_diddsp = sched_didpoll = sched_didnothing = 0;
146} 162}
163#endif
147 164
148void sys_printhist( void) 165void sys_printhist( void)
149{ 166{
@@ -169,10 +186,15 @@ void sys_printhist( void)
169 sched_diddsp, sched_didpoll, sched_didnothing); 186 sched_diddsp, sched_didpoll, sched_didnothing);
170} 187}
171 188
189#ifndef ROCKBOX
172static int sys_histphase; 190static int sys_histphase;
191#endif
173 192
174int sys_addhist(int phase) 193int sys_addhist(int phase)
175{ 194{
195#ifdef ROCKBOX
196 (void) phase;
197#endif
176#ifndef FIXEDPOINT 198#ifndef FIXEDPOINT
177 int i, j, phasewas = sys_histphase; 199 int i, j, phasewas = sys_histphase;
178 t_time newtime = sys_getrealtime(); 200 t_time newtime = sys_getrealtime();
@@ -216,7 +238,11 @@ static char *(oss_errornames[]) = {
216 238
217void glob_audiostatus(void) 239void glob_audiostatus(void)
218{ 240{
241#ifdef ROCKBOX
242 int nresync, nresyncphase, i;
243#else
219 int dev, nresync, nresyncphase, i; 244 int dev, nresync, nresyncphase, i;
245#endif
220 nresync = (oss_nresync >= NRESYNC ? NRESYNC : oss_nresync); 246 nresync = (oss_nresync >= NRESYNC ? NRESYNC : oss_nresync);
221 nresyncphase = oss_resyncphase - 1; 247 nresyncphase = oss_resyncphase - 1;
222 post("audio I/O error history:"); 248 post("audio I/O error history:");
@@ -251,7 +277,9 @@ void sys_log_error(int type)
251 if (type != ERR_NOTHING && !sched_diored && 277 if (type != ERR_NOTHING && !sched_diored &&
252 (sched_diddsp >= sched_dioredtime)) 278 (sched_diddsp >= sched_dioredtime))
253 { 279 {
280#ifndef ROCKBOX
254 sys_vgui("pdtk_pd_dio 1\n"); 281 sys_vgui("pdtk_pd_dio 1\n");
282#endif
255 sched_diored = 1; 283 sched_diored = 1;
256 } 284 }
257 sched_dioredtime = 285 sched_dioredtime =
@@ -263,6 +291,7 @@ static int sched_lastinclip, sched_lastoutclip,
263 291
264void glob_ping(t_pd *dummy); 292void glob_ping(t_pd *dummy);
265 293
294#ifndef ROCKBOX
266static void sched_pollformeters( void) 295static void sched_pollformeters( void)
267{ 296{
268 int inclip, outclip, indb, outdb; 297 int inclip, outclip, indb, outdb;
@@ -313,9 +342,13 @@ static void sched_pollformeters( void)
313 sched_nextmeterpolltime = 342 sched_nextmeterpolltime =
314 sched_diddsp + (int)(sys_dacsr /(double)sys_schedblocksize); 343 sched_diddsp + (int)(sys_dacsr /(double)sys_schedblocksize);
315} 344}
345#endif /* ROCKBOX */
316 346
317void glob_meters(void *dummy, float f) 347void glob_meters(void *dummy, float f)
318{ 348{
349#ifdef ROCKBOX
350 (void) dummy;
351#endif
319 if (f == 0) 352 if (f == 0)
320 sys_getmeters(0, 0); 353 sys_getmeters(0, 0);
321 sched_meterson = (f != 0); 354 sched_meterson = (f != 0);
@@ -335,7 +368,10 @@ void dsp_tick(void);
335 368
336static int sched_usedacs = 1; 369static int sched_usedacs = 1;
337static t_time sched_referencerealtime, sched_referencelogicaltime; 370static t_time sched_referencerealtime, sched_referencelogicaltime;
338static t_time sys_time_per_dsp_tick; 371#ifndef ROCKBOX
372static
373#endif
374t_time sys_time_per_dsp_tick;
339 375
340void sched_set_using_dacs(int flag) 376void sched_set_using_dacs(int flag)
341{ 377{
@@ -344,14 +380,24 @@ void sched_set_using_dacs(int flag)
344 { 380 {
345 sched_referencerealtime = sys_getrealtime(); 381 sched_referencerealtime = sys_getrealtime();
346 sched_referencelogicaltime = clock_getlogicaltime(); 382 sched_referencelogicaltime = clock_getlogicaltime();
383#ifndef ROCKBOX
347 post("schedsetuding"); 384 post("schedsetuding");
385#endif
348 } 386 }
349 sys_time_per_dsp_tick = (TIMEUNITPERSEC) * 387 sys_time_per_dsp_tick = (TIMEUNITPERSEC) *
350 ((double)sys_schedblocksize) / sys_dacsr; 388 ((double)sys_schedblocksize) / sys_dacsr;
389/*
390#ifdef SIMULATOR
391printf("%f\n%f\n%f\n%f\n", (double)sys_time_per_dsp_tick, (double)TIMEUNITPERSEC, (double) sys_schedblocksize, (double)sys_dacsr);
392#endif
393*/
351} 394}
352 395
353 /* take the scheduler forward one DSP tick, also handling clock timeouts */ 396 /* take the scheduler forward one DSP tick, also handling clock timeouts */
354static void sched_tick(t_time next_sys_time) 397#ifndef ROCKBOX
398static
399#endif
400void sched_tick(t_time next_sys_time)
355{ 401{
356 int countdown = 5000; 402 int countdown = 5000;
357 while (clock_setlist && clock_setlist->c_settime < next_sys_time) 403 while (clock_setlist && clock_setlist->c_settime < next_sys_time)
@@ -364,7 +410,9 @@ static void sched_tick(t_time next_sys_time)
364 if (!countdown--) 410 if (!countdown--)
365 { 411 {
366 countdown = 5000; 412 countdown = 5000;
413#ifndef ROCKBOX
367 sys_pollgui(); 414 sys_pollgui();
415#endif
368 } 416 }
369 if (sys_quit) 417 if (sys_quit)
370 return; 418 return;
@@ -388,9 +436,11 @@ the audio I/O system is still busy with previous transfers.
388void sys_pollmidiqueue( void); 436void sys_pollmidiqueue( void);
389void sys_initmidiqueue( void); 437void sys_initmidiqueue( void);
390 438
439#ifndef ROCKBOX
391int m_scheduler_pda( void) 440int m_scheduler_pda( void)
392{ 441{
393 int idlecount = 0; 442 int idlecount = 0;
443
394 sys_time_per_dsp_tick = (TIMEUNITPERSEC) * 444 sys_time_per_dsp_tick = (TIMEUNITPERSEC) *
395 ((double)sys_schedblocksize) / sys_dacsr; 445 ((double)sys_schedblocksize) / sys_dacsr;
396 446
@@ -402,13 +452,18 @@ int m_scheduler_pda( void)
402 sys_sleepgrain = 100; 452 sys_sleepgrain = 100;
403 else if (sys_sleepgrain > 5000) 453 else if (sys_sleepgrain > 5000)
404 sys_sleepgrain = 5000; 454 sys_sleepgrain = 5000;
455
405 sys_initmidiqueue(); 456 sys_initmidiqueue();
457
406 while (!sys_quit) 458 while (!sys_quit)
407 { 459 {
460
408 int didsomething = 0; 461 int didsomething = 0;
462
409 int timeforward; 463 int timeforward;
410 464
411 sys_addhist(0); 465 sys_addhist(0);
466
412 waitfortick: 467 waitfortick:
413 if (sched_usedacs) 468 if (sched_usedacs)
414 { 469 {
@@ -564,7 +619,7 @@ int sys_trylock(void)
564 619
565void sys_lock(void) {} 620void sys_lock(void) {}
566void sys_unlock(void) {} 621void sys_unlock(void) {}
567int sys_trylock(void) {} 622int sys_trylock(void) { return 0; }
568 623
569#endif 624#endif
570 625
@@ -580,3 +635,4 @@ void sys_exit(void)
580 sys_quit = 1; 635 sys_quit = 1;
581} 636}
582 637
638#endif /* ROCKBOX */