Fixed a deadlocking race condition that might happen when reading APU memory in the hex viewer

This commit is contained in:
Lior Halphon 2016-09-21 01:59:43 +03:00
parent c40b86d4a4
commit 252439c1af
2 changed files with 5 additions and 1 deletions

View File

@ -63,8 +63,9 @@ static int16_t step_lfsr(uint16_t lfsr, bool uses_7_bit)
static void GB_apu_run_internal(GB_gameboy_t *gb)
{
while (!__sync_bool_compare_and_swap(&gb->apu_lock, false, true));
uint32_t steps = gb->apu.apu_cycles / (CPU_FREQUENCY/APU_FREQUENCY);
if (!steps) return;
if (!steps) goto exit;
gb->apu.apu_cycles %= (CPU_FREQUENCY/APU_FREQUENCY);
for (uint8_t i = 0; i < 4; i++) {
@ -123,6 +124,8 @@ static void GB_apu_run_internal(GB_gameboy_t *gb)
gb->apu.wave_channels[0].cur_sweep_steps = gb->apu.wave_channels[0].sweep_steps;
}
}
exit:
gb->apu_lock = false;
}
void GB_apu_get_samples_and_update_pcm_regs(GB_gameboy_t *gb, GB_sample_t *samples)

View File

@ -363,6 +363,7 @@ typedef struct GB_gameboy_s {
unsigned int audio_position;
bool audio_stream_started; // detects first copy request to minimize lag
volatile bool audio_copy_in_progress;
volatile bool apu_lock;
/* Callbacks */
void *user_data;