Skip to content

Commit

Permalink
Ensure fiber = 0 in *_wait_ensure.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Aug 22, 2023
1 parent 76daf51 commit 1845cf8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
11 changes: 9 additions & 2 deletions ext/io/event/selector/epoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,13 @@ int IO_Event_Selector_EPoll_Waiting_register(struct IO_Event_Selector_EPoll *sel
return result;
}

inline static
void IO_Event_Selector_EPoll_Waiting_cancel(struct IO_Event_Selector_EPoll_Waiting *waiting)
{
IO_Event_List_pop(&waiting->list);
waiting->fiber = 0;
}

void IO_Event_Selector_EPoll_Descriptor_initialize(void *element)
{
struct IO_Event_Selector_EPoll_Descriptor *epoll_descriptor = element;
Expand Down Expand Up @@ -461,7 +468,7 @@ VALUE process_wait_ensure(VALUE _arguments) {

close(arguments->descriptor);

IO_Event_List_pop(&arguments->waiting->list);
IO_Event_Selector_EPoll_Waiting_cancel(arguments->waiting);

return Qnil;
}
Expand Down Expand Up @@ -512,7 +519,7 @@ static
VALUE io_wait_ensure(VALUE _arguments) {
struct io_wait_arguments *arguments = (struct io_wait_arguments *)_arguments;

IO_Event_List_pop(&arguments->waiting->list);
IO_Event_Selector_EPoll_Waiting_cancel(arguments->waiting);

return Qnil;
};
Expand Down
13 changes: 10 additions & 3 deletions ext/io/event/selector/kqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void IO_Event_Selector_KQueue_Waiting_compact(struct IO_Event_List *_waiting)
struct IO_Event_Selector_KQueue_Waiting *waiting = (void*)_waiting;

if (waiting->fiber) {
rb_gc_location(waiting->fiber);
waiting->fiber = rb_gc_location(waiting->fiber);
}
}

Expand Down Expand Up @@ -303,6 +303,13 @@ int IO_Event_Selector_KQueue_Waiting_register(struct IO_Event_Selector_KQueue *s
return result;
}

inline static
void IO_Event_Selector_KQueue_Waiting_cancel(struct IO_Event_Selector_KQueue_Waiting *waiting)
{
IO_Event_List_pop(&waiting->list);
waiting->fiber = 0;
}

void IO_Event_Selector_KQueue_Descriptor_initialize(void *element)
{
struct IO_Event_Selector_KQueue_Descriptor *kqueue_descriptor = element;
Expand Down Expand Up @@ -489,7 +496,7 @@ static
VALUE process_wait_ensure(VALUE _arguments) {
struct process_wait_arguments *arguments = (struct process_wait_arguments *)_arguments;

IO_Event_List_pop(&arguments->waiting->list);
IO_Event_Selector_KQueue_Waiting_cancel(arguments->waiting);

return Qnil;
}
Expand Down Expand Up @@ -533,7 +540,7 @@ static
VALUE io_wait_ensure(VALUE _arguments) {
struct io_wait_arguments *arguments = (struct io_wait_arguments *)_arguments;

IO_Event_List_pop(&arguments->waiting->list);
IO_Event_Selector_KQueue_Waiting_cancel(arguments->waiting);

return Qnil;
}
Expand Down

0 comments on commit 1845cf8

Please sign in to comment.