Eliminate deadlock when writing config from radio link
authorKeith Packard <keithp@keithp.com>
Sat, 27 Feb 2010 23:11:44 +0000 (15:11 -0800)
committerKeith Packard <keithp@keithp.com>
Sat, 27 Feb 2010 23:11:44 +0000 (15:11 -0800)
Writing the 'Saved\r\n' string would fill the packet buffer and cause
a flush to occur, which would need to wait for the radio link to
receive and transmit a packet. The radio link always re-fetches the
radio channel number when lighting up the radio, so it need to look in
the config space. If the config mutex was held by the config writing
process while the radio was trying to get the channel number, then
we'd get a deadlock.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/ao_config.c

index f8ea27feb54e6c9124efe526317fab397ac222ce..8df994a643d79e376814a10ed9ebddcdbb99b516 100644 (file)
@@ -377,13 +377,18 @@ ao_config_show(void) __reentrant
 void
 ao_config_write(void) __reentrant
 {
 void
 ao_config_write(void) __reentrant
 {
+       uint8_t saved = 0;
        ao_mutex_get(&ao_config_mutex);
        if (ao_config_dirty) {
                _ao_config_put();
                ao_config_dirty = 0;
        ao_mutex_get(&ao_config_mutex);
        if (ao_config_dirty) {
                _ao_config_put();
                ao_config_dirty = 0;
-               printf("Saved\n");
+               saved = 1;
        }
        ao_mutex_put(&ao_config_mutex);
        }
        ao_mutex_put(&ao_config_mutex);
+       if (saved)
+               puts("Saved");
+       else
+               puts("Nothing to save");
 }
 #endif
 
 }
 #endif