Skip to content

Commit

Permalink
add abort
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikwidlund authored and Fredrik Widlund committed Oct 5, 2020
1 parent bc50e79 commit b2a6a93
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/dynamic/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ void core_construct(core *core)
core->fd = epoll_create1(EPOLL_CLOEXEC);
if (core->fd == -1)
core->errors ++;
core->active = 1;
}
core->ref ++;
}
Expand All @@ -54,6 +55,12 @@ void core_destruct(core *core)
}
}

void core_abort(core *core)
{
core = core_get(core);
core->active = 0;
}

core_status core_dispatch(core_handler *handler, int type, uintptr_t data)
{
return handler->callback((core_event[]){{.state = handler->state, .type = type, .data = data}});
Expand All @@ -65,7 +72,7 @@ void core_loop(core *core)
int n, i;

core = core_get(core);
while (core->errors == 0 && (core->handlers_active || vector_size(&core->next)))
while (core->active && core->errors == 0 && (core->handlers_active || vector_size(&core->next)))
{
for (i = 0; (size_t) i < vector_size(&core->next); i ++)
(void) core_dispatch(vector_at(&core->next, i), 0, 0);
Expand Down
2 changes: 2 additions & 0 deletions src/dynamic/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ struct core
{
size_t ref;
int fd;
int active;
int errors;
vector handlers;
size_t handlers_active;
Expand All @@ -40,6 +41,7 @@ struct core

void core_construct(core *);
void core_destruct(core *);
void core_abort(core *);
core_status core_dispatch(core_handler *, int, uintptr_t);
void core_loop(core *);
void core_add(core *, core_callback *, void *, int, int);
Expand Down

0 comments on commit b2a6a93

Please sign in to comment.