Debian Codegraph @

crt/aws-c-io/tests/vcc/unsubscribe.c

raw symbols SCIP
1 /*
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License").
5 * You may not use this file except in compliance with the License.
6 * A copy of the License is located at
7 *
8 * http://aws.amazon.com/apache2.0
9 *
10 * or in the "license" file accompanying this file. This file is distributed
11 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12 * express or implied. See the License for the specific language governing
13 * permissions and limitations under the License.
14 */
15
16 /* clang-format off */
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 /*ignored*/))) {
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 /* We can't clean up yet, because we have schedule tasks and more events to process,
55 * mark it as unsubscribed and schedule a cleanup task. */
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 /* clang-format on */