Fixed a deadlocking race condition that might happen when reading APU memory in the hex viewer
This commit is contained in:
parent
c40b86d4a4
commit
252439c1af
@ -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)
|
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);
|
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);
|
gb->apu.apu_cycles %= (CPU_FREQUENCY/APU_FREQUENCY);
|
||||||
for (uint8_t i = 0; i < 4; i++) {
|
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;
|
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)
|
void GB_apu_get_samples_and_update_pcm_regs(GB_gameboy_t *gb, GB_sample_t *samples)
|
||||||
|
@ -363,6 +363,7 @@ typedef struct GB_gameboy_s {
|
|||||||
unsigned int audio_position;
|
unsigned int audio_position;
|
||||||
bool audio_stream_started; // detects first copy request to minimize lag
|
bool audio_stream_started; // detects first copy request to minimize lag
|
||||||
volatile bool audio_copy_in_progress;
|
volatile bool audio_copy_in_progress;
|
||||||
|
volatile bool apu_lock;
|
||||||
|
|
||||||
/* Callbacks */
|
/* Callbacks */
|
||||||
void *user_data;
|
void *user_data;
|
||||||
|
Loading…
Reference in New Issue
Block a user