Rewrote timer code.
The new code is based on timestamps, rather than delays. This eliminates the need to update every timer in timer_process(), which cost a non-trivial amount of CPU time on low-end machines. This involved changes to every user of the timer code, so this change almost certainly introduces bugs.
This commit is contained in:
parent
ab359ca9c5
commit
a7d006b637
79 changed files with 1050 additions and 1033 deletions
|
|
@ -71,9 +71,19 @@ void ad1848_write(uint16_t addr, uint8_t val, void *p)
|
|||
break;
|
||||
|
||||
case 9:
|
||||
if (!ad1848->enable && (val & 0x41) == 0x01)
|
||||
{
|
||||
if (ad1848->timer_latch)
|
||||
timer_advance_u64(&ad1848->timer, ad1848->timer_latch);
|
||||
else
|
||||
timer_advance_u64(&ad1848->timer, TIMER_USEC);
|
||||
}
|
||||
ad1848->enable = ((val & 0x41) == 0x01);
|
||||
if (!ad1848->enable)
|
||||
{
|
||||
timer_disable(&ad1848->timer);
|
||||
ad1848->out_l = ad1848->out_r = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case 12:
|
||||
|
|
@ -93,7 +103,7 @@ void ad1848_write(uint16_t addr, uint8_t val, void *p)
|
|||
|
||||
void ad1848_speed_changed(ad1848_t *ad1848)
|
||||
{
|
||||
ad1848->timer_latch = (int)((double)TIMER_USEC * (1000000.0 / (double)ad1848->freq));
|
||||
ad1848->timer_latch = (uint64_t)((double)TIMER_USEC * (1000000.0 / (double)ad1848->freq));
|
||||
}
|
||||
|
||||
void ad1848_update(ad1848_t *ad1848)
|
||||
|
|
@ -110,9 +120,9 @@ static void ad1848_poll(void *p)
|
|||
ad1848_t *ad1848 = (ad1848_t *)p;
|
||||
|
||||
if (ad1848->timer_latch)
|
||||
ad1848->timer_count += ad1848->timer_latch;
|
||||
timer_advance_u64(&ad1848->timer, ad1848->timer_latch);
|
||||
else
|
||||
ad1848->timer_count = TIMER_USEC;
|
||||
timer_advance_u64(&ad1848->timer, TIMER_USEC);
|
||||
|
||||
ad1848_update(ad1848);
|
||||
|
||||
|
|
@ -214,5 +224,5 @@ void ad1848_init(ad1848_t *ad1848)
|
|||
// pclog("ad1848_vols %i = %f %i\n", c, attenuation, ad1848_vols[c]);
|
||||
}
|
||||
|
||||
timer_add(ad1848_poll, &ad1848->timer_count, &ad1848->enable, ad1848);
|
||||
timer_add(&ad1848->timer, ad1848_poll, ad1848, 0);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue