Git Product home page Git Product logo

equeue's People

Contributors

bulislaw avatar c1728p9 avatar geky avatar kjbracey avatar mikedk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

equeue's Issues

equeue_unqueue corrupting queue list if done on a sibling.

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)

Delay/period as first argument in event_call_*

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.

Provide pick event function

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, &param, timeout) >= 0)
{
    switch(type)
    {
        case EV_EVENT1:
            //do someting ...
        break;
        case EV_EVENT2:
            //do someting ...
        break;
    }
}

[POSIX] Wrong time diff after NTP syncronization

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 !

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.