ve3wwg/teensy3_fibers — pull request #2 by duff2013 (2014-10-01 04:51:18+00:00)
Title: Fix for "Fiber State" not updating and added Keyword for Arduino IDE

I noticed that the fiber state was not being updated while there running, this pull just initializes all fiber's to "Invalid" then in the yield function it updates the fibers, current--> "Created" and previous-->"Executing". Should not add much latency to the context switch.

Run the example below without the update and you will see the fiber states are all 0 unless it becomes returned then it will register 2 (Returned). Then try it with the update and it will show the current state is now being updated. This could be important if your program uses isr's like Interval Timer that wants to interact with fibers or shared resources
```
#include

Fibers<5> fibers(1000);

void yield() {
fibers.yield(); // Yield cpu to next fiber in round-robin sequence
}

void setup() {
pinMode(LED_BUILTIN,OUTPUT);
delay(5000);
fibers.create(fiber1,0,1000);
fibers.create(fiber2,0,1000);
fibers.create(fiber3,0,1000);
}

// main thread
void loop() {
Serial.println("\n-------FIBER0---------");
Serial.print("Fiber current: ");
Serial.println(fibers.current());
Serial.print("Fiber0 State: ");
Serial.println(fibers.state(0));
Serial.print("Fiber1 State: ");
Serial.println(fibers.state(1));
Serial.print("Fiber2 State: ");
Serial.println(fibers.state(2));
Serial.print("Fiber3 State: ");
Serial.println(fibers.state(3));
delay(1000);
}

// First fiber (coroutine)
static void fiber1(void *arg) {
int count = 0;
while ( count++ < 1 ) {
Serial.println("-------FIBER1---------");
Serial.print("Fiber current: ");
Serial.println(fibers.current());
Serial.print("Fiber0 State: ");
Serial.println(fibers.state(0));
Serial.print("Fiber1 State: ");
Serial.println(fibers.state(1));
Serial.print("Fiber2 State: ");
Serial.println(fibers.state(2));
Serial.print("Fiber3 State: ");
Serial.println(fibers.state(3));
//Serial.println();
delay(1000);
}
}

// Second fiber (coroutine)
static void fiber2(void *arg) {
int count = 0;
while ( count++ < 2 ) {
Serial.println("-------FIBER2---------");
Serial.print("Fiber current: ");
Serial.println(fibers.current());
Serial.print("Fiber0 State: ");
Serial.println(fibers.state(0));
Serial.print("Fiber1 State: ");
Serial.println(fibers.state(1));
Serial.print("Fiber2 State: ");
Serial.println(fibers.state(2));
Serial.print("Fiber3 State: ");
Serial.println(fibers.state(3));
delay(1000);
}
}

// Third fiber (coroutine)
static void fiber3(void *arg) {
int count = 0;
while ( count++ < 3 ) {
Serial.println("-------FIBER3---------");
Serial.print("Fiber current: ");
Serial.println(fibers.current());
Serial.print("Fiber0 State: ");
Serial.println(fibers.state(0));
Serial.print("Fiber1 State: ");
Serial.println(fibers.state(1));
Serial.print("Fiber2 State: ");
Serial.println(fibers.state(2));
Serial.print("Fiber3 State: ");
Serial.println(fibers.state(3));
delay(1000);
}
}

```