@@ -10,35 +10,30 @@ void handler(int count);
10
10
Event<void (int )> event1 (&queue, handler);
11
11
Event<void (int )> event2 (&queue, handler);
12
12
13
-
14
- void handler (int count)
15
- {
13
+ void handler (int count) {
16
14
unsigned time_ms = equeue_tick ();
17
15
printf (" Timestamp = %d Event = %d \n " , time_ms, count);
18
16
return ;
19
17
}
20
18
21
- void post_events (void )
22
- {
19
+ void post_events (void ) {
23
20
// Events can be posted multiple times and enqueue gracefully until
24
21
// the dispatch function is called. Each event will be processed
25
22
// subject to any delay and period specified. Each time an event has
26
23
// been dispatched it will be re-queued ready for the next dispatch
27
24
// period.
28
- event1.post (1 ); // Event1 with a value of 1
29
- event1.post (2 ); // Event1 with a value of 2
30
- event1.post (3 ); // Event1 with a value of 3
25
+ event1.post (1 ); // Event1 with a value of 1
26
+ event1.post (2 ); // Event1 with a value of 2
27
+ event1.post (3 ); // Event1 with a value of 3
31
28
32
29
// Cancel the last event posted ie Event1 with a value of 3
33
30
event1.cancel ();
34
31
35
- event1.post (4 ); // Event1 with a value of 4
36
-
37
- event2.post (5 ); // Event2 with a value of 5
32
+ event1.post (4 ); // Event1 with a value of 4
38
33
34
+ event2.post (5 ); // Event2 with a value of 5
39
35
}
40
36
41
-
42
37
// Example demonstrates the following:
43
38
// 1. Post 5 different events to a queue
44
39
// 2. Configure the event delay and period for each
@@ -76,18 +71,17 @@ void post_events(void)
76
71
// Timestamp = 727 Event = 2
77
72
// Timestamp = 756 Event = 4
78
73
79
- int main ()
80
- {
74
+ int main () {
81
75
// Example 1 Dispatch posted events for a specified period
82
76
Thread event_thread;
83
77
84
78
// The event can be manually configured for special timing requirements
85
79
// specified in milliseconds (using Chrono durations)
86
- event1.delay (100ms); // Starting delay - 100 msec
87
- event1.period (200ms); // Delay between each event - 200msec
80
+ event1.delay (100ms); // Starting delay - 100 msec
81
+ event1.period (200ms); // Delay between each event - 200msec
88
82
89
- event2.delay (400ms); // Starting delay - 400 msec
90
- event2.period (non_periodic); // Single non periodic event
83
+ event2.delay (400ms); // Starting delay - 400 msec
84
+ event2.period (non_periodic); // Single non periodic event
91
85
92
86
event_thread.start (callback (post_events));
93
87
@@ -99,5 +93,4 @@ int main()
99
93
queue.dispatch_for (800ms);
100
94
101
95
event_thread.join ();
102
-
103
96
}
0 commit comments