Arduino-Scheduler
Portable Collaborative Multi-Tasking Scheduler for Arduino
SchedulerBenchmarkSemaphore.ino
Go to the documentation of this file.
1 
28 #include <Scheduler.h>
29 #include <Scheduler/Semaphore.h>
30 
31 // Check for SparkFun SAMD21 Breakout
32 #if defined(ARDUINO_ARCH_SAMD) && (USB_PID == 0x8D21)
33 #define Serial SerialUSB
34 #endif
35 
37 unsigned long count = 0;
38 
39 void setup()
40 {
41  Serial.begin(57600);
42  while (!Serial);
43  Serial.println(F("SchedulerBenchmarkSemaphore: started"));
44  Serial.flush();
45 
48 }
49 
50 void loop()
51 {
52  unsigned long start = millis();
53  await(millis() - start >= 1000);
54  Serial.print(count);
55  Serial.print(F(" ("));
56  Serial.print(1000000.0 / count);
57  Serial.println(F(" us)"));
58  Serial.flush();
59  count = 0;
60 }
61 
62 void producer()
63 {
64  while (1) semaphore.signal();
65 }
66 
67 void consumer()
68 {
69  while (1) {
70  semaphore.wait();
71  count += 1;
72  }
73 }
unsigned long count
void wait(unsigned int count=1)
Definition: Semaphore.h:36
static bool startLoop(func_t taskLoop, size_t stackSize=DEFAULT_STACK_SIZE)
Definition: Scheduler.h:65
#define await(cond)
Definition: Scheduler.h:162
Semaphore semaphore(0)
SchedulerClass Scheduler
Definition: Scheduler.cpp:53
void signal(unsigned int count=1)
Definition: Semaphore.h:46