Ejemplo n.º 1
0
/**
 * Invoke all pending actions prior to specified timestamp
 */
void EventQueue::executeAll(uint64_t now) {
    scheduling_s * current, *tmp;

    scheduling_s * executionList = NULL;

    int counter = 0;

    // we need safe iteration because we are removing elements inside the loop
    LL_FOREACH_SAFE(head, current, tmp)
    {
        if (++counter > QUEUE_LENGTH_LIMIT) {
            firmwareError("Is this list looped?");
            return;
        }
        if (current->momentUs <= now) {
            LL_DELETE(head, current);
            LL_PREPEND(executionList, current);
        }
    }

    /*
     * we need safe iteration here because 'callback' might change change 'current->next'
     * while re-inserting it into the queue from within the callback
     */
    LL_FOREACH_SAFE(executionList, current, tmp)
    current->callback(current->param);
}
Ejemplo n.º 2
0
int main() {
    int i;
    el els[10], *e, *tmp, *tmp2;
    for(i=0;i<10;i++) els[i].id='a'+i;

    /* test LL macros */
    printf("LL macros\n");
    LL_APPEND(head,&els[0]);
    LL_APPEND(head,&els[1]);
    LL_APPEND(head,&els[2]);
    LL_FOREACH(head,e)
        printf("%c ", e->id);
    printf("\n");
    LL_SEARCH_SCALAR(head, e, id, 'b');
    if (e) printf("search scalar found b\n");
    LL_SEARCH(head, e, &els[0], eltcmp);
    if (e) printf("search found %c\n",e->id);
    LL_FOREACH_SAFE(head,e,tmp) LL_DELETE(head,e);

    printf("\n");

    /* test DL macros */
    printf("DL macros\n");
    DL_APPEND(head,&els[0]);
    DL_APPEND(head,&els[1]);
    DL_APPEND(head,&els[2]);
    DL_FOREACH(head,e)
        printf("%c ", e->id);
    printf("\n");
    DL_SEARCH_SCALAR(head, e, id, 'b');
    if (e) printf("search scalar found b\n");
    DL_SEARCH(head, e, &els[0], eltcmp);
    if (e) printf("search found %c\n",e->id);
    DL_FOREACH_SAFE(head,e,tmp) DL_DELETE(head,e);
    printf("\n");

    /* test CDL macros */
    printf("CDL macros\n");
    CDL_PREPEND(head,&els[0]);
    CDL_PREPEND(head,&els[1]);
    CDL_PREPEND(head,&els[2]);
    CDL_FOREACH(head,e)
        printf("%c ", e->id);
    printf("\n");
    CDL_SEARCH_SCALAR(head, e, id, 'b');
    if (e) printf("search scalar found b\n");
    CDL_SEARCH(head, e, &els[0], eltcmp);
    if (e) printf("search found %c\n",e->id);
    CDL_FOREACH_SAFE(head,e,tmp,tmp2) CDL_DELETE(head,e);


    return 0;
}