altos: shut down packet mode cleanly
authorKeith Packard <keithp@keithp.com>
Mon, 30 Aug 2010 06:22:27 +0000 (23:22 -0700)
committerKeith Packard <keithp@keithp.com>
Mon, 30 Aug 2010 06:22:27 +0000 (23:22 -0700)
Instead of constantly bashing the packet master thread, let it shut
itself down in an orderly fashion. It will shut down fairly quickly as
all of the activities in that thread are bounded. Otherwise, the
master packet thread might leave mutexes locked and all sorts of other
horrors.

Tested on Linux and Mac OS X and shown to be reliable.

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

index 50f5aeffc79101725df181261fe3408c801f6a4e..641b49f411a48a5c5821e376f055a9872d754363 100644 (file)
@@ -29,6 +29,8 @@ ao_packet_getchar(void) __critical
                        ao_wake_task(&ao_packet_task);
                ao_usb_flush();
                ao_sleep(&ao_stdin_ready);
+               if (!ao_packet_enable)
+                       break;
        }
        return c;
 }
@@ -127,10 +129,9 @@ ao_packet_forward(void) __reentrant
                ao_delay(AO_MS_TO_TICKS(100));
        ao_packet_enable = 0;
        while (ao_packet_echo_task.wchan || ao_packet_task.wchan) {
-               ao_radio_abort();
-               ao_wake_task(&ao_packet_echo_task);
-               ao_wake_task(&ao_packet_task);
-               ao_yield();
+               if (ao_packet_echo_task.wchan)
+                       ao_wake_task(&ao_packet_echo_task);
+               ao_delay(AO_MS_TO_TICKS(10));
        }
 }