Created
November 7, 2018 08:23
-
-
Save daid/3c9f20fb0abbf2d71043287f626ca2e9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "equeue/equeue.h" | |
#include <assert.h> | |
#include <stdio.h> | |
static unsigned int tick_counter; | |
void test_func(void* data) | |
{ | |
printf("test_func: %p\n", data); | |
} | |
struct ecallback { | |
void (*cb)(void*); | |
void *data; | |
}; | |
void dump(struct equeue_event** ref, bool is_sib) | |
{ | |
struct equeue_event* e = *ref; | |
int data = (int)((struct ecallback*)(e + 1))->data; | |
if (is_sib) printf(" "); else printf("--"); | |
printf("E:%p NEXT:%p SIB:%p REF:%p%c= %p CB:%p %d\n", e, e->next, e->sibling, e->ref, (e->ref == ref) ? ' ' : '!', ref, e->cb, data); | |
if (e->sibling) | |
dump(&e->sibling, true); | |
if (e->next && !is_sib) | |
dump(&e->next, false); | |
} | |
int main(int argc, char** argv) | |
{ | |
equeue_t q; | |
assert(equeue_create(&q, 1024) == 0); | |
int e0 = equeue_call_in(&q, 1, test_func, (void*)0); | |
int e1 = equeue_call_in(&q, 3, test_func, (void*)1); | |
int e2 = equeue_call_in(&q, 1, test_func, (void*)2); | |
int e3 = equeue_call_in(&q, 1, test_func, (void*)3); | |
int e4 = equeue_call_in(&q, 2, test_func, (void*)4); | |
printf("Before:\n"); | |
dump(&q.queue, false); | |
equeue_cancel(&q, e2); | |
equeue_cancel(&q, e1); | |
//equeue_cancel(&q, c); | |
printf("After:\n"); | |
dump(&q.queue, false); | |
tick_counter = 10; | |
equeue_dispatch(&q, 0); | |
equeue_destroy(&q); | |
return 0; | |
} | |
int equeue_mutex_create(equeue_mutex_t *mutex) | |
{ | |
return 0; | |
} | |
void equeue_mutex_destroy(equeue_mutex_t *mutex) | |
{ | |
} | |
void equeue_mutex_lock(equeue_mutex_t *mutex) | |
{ | |
} | |
void equeue_mutex_unlock(equeue_mutex_t *mutex) | |
{ | |
} | |
int equeue_sema_create(equeue_sema_t *sema) | |
{ | |
*sema = 0; | |
return 0; | |
} | |
void equeue_sema_destroy(equeue_sema_t *sema) | |
{ | |
} | |
void equeue_sema_signal(equeue_sema_t *sema) | |
{ | |
} | |
bool equeue_sema_wait(equeue_sema_t *sema, int ms) | |
{ | |
return false; | |
} | |
unsigned equeue_tick(void) | |
{ | |
return tick_counter; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment