Debian Codegraph @

crt/aws-c-io/source/darwin/dispatch_queue_event_loop_private.h

raw symbols SCIP
1 #ifndef AWS_IO_DARWIN_DISPATCH_QUEUE_H
2 #define AWS_IO_DARWIN_DISPATCH_QUEUE_H
3 /**
4 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
5 * SPDX-License-Identifier: Apache-2.0.
6 */
7
8 #include <Security/Security.h>
9 #include <aws/common/condition_variable.h>
10 #include <aws/common/mutex.h>
11 #include <aws/common/thread.h>
12 #include <aws/io/tls_channel_handler.h>
13 #include <dispatch/dispatch.h>
14
15 struct secure_transport_ctx {
16 struct aws_tls_ctx ctx;
17 CFAllocatorRef wrapped_allocator;
18 CFArrayRef certs;
19 /* The certs field can be set in two different ways, and only one requires releasing individual cert objects. */
20 bool cleanup_cert;
21 sec_identity_t secitem_identity;
22 CFArrayRef ca_cert;
23 enum aws_tls_versions minimum_tls_version;
24 struct aws_string *alpn_list;
25 bool verify_peer;
26 };
27
28 enum aws_dispatch_loop_execution_state {
29 AWS_DLES_SUSPENDED,
30 AWS_DLES_RUNNING,
31 AWS_DLES_SHUTTING_DOWN,
32 AWS_DLES_TERMINATED
33 };
34
35 struct aws_dispatch_loop {
36 struct aws_allocator *allocator;
37 dispatch_queue_t dispatch_queue;
38 struct aws_task_scheduler scheduler;
39 struct aws_event_loop *base_loop;
40
41 struct aws_ref_count ref_count;
42
43 /* Synced data handle cross thread tasks and events, and event loop operations*/
44 struct {
45 /*
46 * This lock is used to protect synced_data across the threads. It should be acquired whenever data in the
47 * synced_data struct is accessed or modified.
48 */
49 struct aws_mutex synced_data_lock;
50
51 /*
52 * Allows blocking waits for changes in synced data state. Currently used by the external destruction process
53 * to wait for the loop to enter the TERMINATED state. It is acceptable to do a blocking wait because
54 * event loop group destruction is done in a dedicated thread spawned only for that purpose.
55 */
56 struct aws_condition_variable signal;
57
58 /*
59 * `is_executing` flag and `current_thread_id` are used together to identify the thread id of the dispatch queue
60 * running the current block. See dispatch queue's `s_is_on_callers_thread()` implementation for details.
61 */
62 bool is_executing;
63 aws_thread_id_t current_thread_id;
64
65 /*
66 * Will be true if dispatch queue is in a suspended state. A dispatch queue in a suspended state will not start
67 * any blocks that are already enqueued but will not prevent additional blocks from being queued.
68 *
69 * Set to true when `stop()` is called on event loop.
70 * `run()` must be called on owning event_loop to resume processing of blocks on a suspended dispatch queue.
71 *
72 * Calling dispatch_sync() on a suspended dispatch queue will deadlock.
73 */
74 enum aws_dispatch_loop_execution_state execution_state;
75
76 struct aws_linked_list cross_thread_tasks;
77
78 /*
79 * priority queue of <scheduled_iteration_entry> in sorted order by timestamp. Each scheduled_iteration_entry
80 * represents a block ALREADY SCHEDULED on Apple dispatch queue.
81 *
82 * When we schedule a new run iteration, scheduled_iterations is checked to see if the scheduling attempt is
83 * redundant.
84 */
85 struct aws_linked_list scheduled_iterations;
86 } synced_data;
87 };
88
89 #endif /* #ifndef AWS_IO_DARWIN_DISPATCH_QUEUE_H */