geky / equeue Goto Github PK
View Code? Open in Web Editor NEWA Swiss Army knife scheduler for embedded systems
License: MIT License
A Swiss Army knife scheduler for embedded systems
License: MIT License
I'm still investigating this fully, but I think the equeue_unqueue function corrupts the linked list administration of the event queue if cancel is called on a event that is a sibling of the main linked list.
equeue_unqueue seems to assume &e->next == e->next->ref
, which is no longer true on a sibling, as I think e->next is basicly invalid on a sibling (as e->next is also not updated if an entry is inserted after the parent of the sibling)
Not sure what a proper fix is yet. (Note, found this issue as part of mbed-os)
event_call_in and event_call_every take as their last argument the delay or the period, in milliseconds. I believe it would be better if they took the delay/period as their first argument because it would make the call marginally clearer, but more importantly because it would simplify the implementation. Aside from being useful, this library seems educational, and a simpler implementation should help both goals.
This lib is very good , but can you provide pick event functions that I can handle the event by myself.
some thing like following:
// post a event somewhere
equeue_post_event(queue, type, param);
// pick event by wait function
if(equeue_wait_event(queue, &type, ¶m, timeout) >= 0)
{
switch(type)
{
case EV_EVENT1:
//do someting ...
break;
case EV_EVENT2:
//do someting ...
break;
}
}
How would I go about implementing the platform functions for a bare metal application?
Doing some tests I realized that if the tick
is initialized before the first NTP synchronization, then the next diff is off, and the dispatch loop just hangs "forever" (in the case where events are already in the queue at least).
This is because the posix implementation uses gettimeofday
, which is affected by NTP.
For me the solution was to use create a equeue_posix_monotonic.c
and use clock_gettime
, as in this patch:
diff --git a/equeue_posix.c b/equeue_posix.c
index 28bf5ae..b69f6d5 100644
--- a/equeue_posix.c
+++ b/equeue_posix.c
@@ -15,9 +15,9 @@
// Tick operations
unsigned equeue_tick(void) {
- struct timeval tv;
- gettimeofday(&tv, 0);
- return (unsigned)(tv.tv_sec*1000 + tv.tv_usec/1000);
+ struct timespec tp;
+ (void) clock_gettime(CLOCK_MONOTONIC, &tp);
+ return (unsigned)(tp.tv_sec*1000 + tp.tv_nsec/1000000);
}
Maybe something like this should be better:
diff --git a/equeue_posix.c b/equeue_posix.c
index 28bf5ae..6e2c787 100644
--- a/equeue_posix.c
+++ b/equeue_posix.c
@@ -15,9 +15,15 @@
// Tick operations
unsigned equeue_tick(void) {
+#ifdef _POSIX_MONOTONIC_CLOCK
+ struct timespec tp;
+ (void) clock_gettime(CLOCK_MONOTONIC, &tp);
+ return (unsigned)(tp.tv_sec*1000 + tp.tv_nsec/1000000);
+#else
struct timeval tv;
gettimeofday(&tv, 0);
return (unsigned)(tv.tv_sec*1000 + tv.tv_usec/1000);
+#endif
}
Let me know if this patch is something you'd be willing to include in the lib.
Thanks for equeue
by the way !
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.