Skip to content

Commit

Permalink
Fix a potential race acessing gflags
Browse files Browse the repository at this point in the history
  • Loading branch information
alvieboy committed Nov 12, 2009
1 parent f12feb0 commit d0e216e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion oscope.pde
Expand Up @@ -104,9 +104,10 @@ static void setup_adc()

static void start_sampling()
{
sei();
cli();
gflags &= ~BYTE_FLAG_CONVERSIONDONE;
gflags |= BYTE_FLAG_STARTCONVERSION;
sei();
}

static void adc_set_frequency(unsigned char divider)
Expand Down Expand Up @@ -232,9 +233,11 @@ static void process_packet(unsigned char command, unsigned char *buf, unsigned s
send_parameters(buf);
break;
case COMMAND_SET_FLAGS:
cli();
gflags &= ~(BYTE_FLAG_INVERTTRIGGER|BYTE_FLAG_DUALCHANNEL);
buf[0] &= BYTE_FLAG_INVERTTRIGGER|BYTE_FLAG_DUALCHANNEL;
gflags |= buf[0];
sei();
send_parameters(buf);
break;
default:
Expand Down Expand Up @@ -306,7 +309,9 @@ void loop() {
bIn = Serial.read();
process(bIn & 0xff);
} else if (gflags & BYTE_FLAG_CONVERSIONDONE) {
cli();
gflags &= ~ BYTE_FLAG_CONVERSIONDONE;
sei();
send_packet(COMMAND_BUFFER_SEG, dataBuffer, numSamples);
} else {
}
Expand Down

0 comments on commit d0e216e

Please sign in to comment.