| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#define UNSUB_TASK_FN_PTR |
| 18 |
#include "preamble.h" |
| 19 |
|
| 20 |
void s_unsubscribe_cleanup_task(struct aws_task *task, void *arg, enum aws_task_status status) |
| 21 |
_(requires \malloc_root((struct epoll_event_data *)arg)) |
| 22 |
_(writes \extent((struct epoll_event_data *)arg)) |
| 23 |
{ |
| 24 |
(void)task; |
| 25 |
(void)status; |
| 26 |
struct epoll_event_data *event_data = (struct epoll_event_data *)arg; |
| 27 |
aws_mem_release(event_data->alloc, (void *)event_data); |
| 28 |
} |
| 29 |
|
| 30 |
static int s_unsubscribe_from_io_events(struct aws_event_loop *event_loop, struct aws_io_handle *handle |
| 31 |
_(ghost \claim(c_event_loop)) |
| 32 |
_(ghost \claim(c_mutex)) |
| 33 |
) { |
| 34 |
AWS_LOGF_TRACE( |
| 35 |
AWS_LS_IO_EVENT_LOOP, "id=%p: un-subscribing from events on fd %d", (void *)event_loop, handle->data.fd); |
| 36 |
struct epoll_loop *epoll_loop = event_loop->impl_data; |
| 37 |
|
| 38 |
AWS_ASSERT(handle->additional_data); |
| 39 |
struct epoll_event_data *additional_handle_data = handle->additional_data; |
| 40 |
_(assert \wrapped(additional_handle_data)) |
| 41 |
_(assert \inv(additional_handle_data)) |
| 42 |
|
| 43 |
struct epoll_event dummy_event; |
| 44 |
|
| 45 |
if (AWS_UNLIKELY(epoll_ctl(epoll_loop->epoll_fd, EPOLL_CTL_DEL, handle->data.fd, &dummy_event ))) { |
| 46 |
AWS_LOGF_ERROR( |
| 47 |
AWS_LS_IO_EVENT_LOOP, |
| 48 |
"id=%p: failed to un-subscribe from events on fd %d", |
| 49 |
(void *)event_loop, |
| 50 |
handle->data.fd); |
| 51 |
return aws_raise_error(AWS_ERROR_SYS_CALL_FAILURE); |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
_(unwrap(additional_handle_data)) |
| 58 |
_(assert handle->\owner != additional_handle_data) |
| 59 |
additional_handle_data->is_subscribed = false; |
| 60 |
|
| 61 |
aws_task_init( |
| 62 |
&additional_handle_data->cleanup_task, |
| 63 |
s_unsubscribe_cleanup_task, |
| 64 |
additional_handle_data, |
| 65 |
"epoll_event_loop_unsubscribe_cleanup"); |
| 66 |
s_schedule_task_now(event_loop, &additional_handle_data->cleanup_task _(ghost c_event_loop) _(ghost c_mutex)); |
| 67 |
|
| 68 |
_(unwrap(handle)) |
| 69 |
handle->additional_data = NULL; |
| 70 |
_(assert handle->\owner == \me) |
| 71 |
|
| 72 |
return AWS_OP_SUCCESS; |
| 73 |
} |
| 74 |
|