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