Skip to content

Commit

Permalink
cleanup event loop
Browse files Browse the repository at this point in the history
  • Loading branch information
koekeishiya committed Dec 3, 2020
1 parent f775ad5 commit 6f781a1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
8 changes: 3 additions & 5 deletions src/event_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ static void *event_loop_run(void *context)
if (!head->next) break;
} while (!__sync_bool_compare_and_swap(&event_loop->head, head, head->next));

if (head->next && head->next->data) {
struct event *event = head->next->data;
if (head->next) {
struct event *event = (void *)head->next + sizeof(struct queue_item);

uint32_t result = event_handler[event->type](event->context, event->param1);

Expand Down Expand Up @@ -61,9 +61,8 @@ void event_loop_post(struct event_loop *event_loop, enum event_type type, void *

new_tail = memory_pool_push(&event_loop->pool, sizeof(struct queue_item) + sizeof(struct event));
new_tail->next = NULL;
new_tail->data = (void *)new_tail + sizeof(struct queue_item);

event = new_tail->data;
event = (void *)new_tail + sizeof(struct queue_item);
event->type = type;
event->context = context;
event->param1 = param1;
Expand All @@ -85,7 +84,6 @@ bool event_loop_init(struct event_loop *event_loop)
if (!memory_pool_init(&event_loop->pool, EVENT_POOL_SIZE)) return false;

event_loop->head = memory_pool_push(&event_loop->pool, sizeof(struct queue_item) + sizeof(struct event));
event_loop->head->data = NULL;
event_loop->head->next = NULL;
event_loop->tail = event_loop->head;

Expand Down
1 change: 0 additions & 1 deletion src/event_loop.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

struct queue_item
{
struct event *data;
struct queue_item *next;
};

Expand Down

0 comments on commit 6f781a1

Please sign in to comment.