1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
;
/**
* Specifies the join strategy used on an aws_thread, which in turn controls whether or not a thread participates
* in the managed thread system. The managed thread system provides logic to guarantee a join on all participating
* threads at the cost of laziness (the user cannot control when joins happen).
*
* Manual - thread does not particpate in the managed thread system; any joins must be done by the user. This
* is the default. The user must call aws_thread_clean_up(), but only after any desired join operation has completed.
* Not doing so will cause the windows handle to leak.
*
* Managed - the managed thread system will automatically perform a join some time after the thread's run function
* has completed. It is an error to call aws_thread_join on a thread configured with the managed join strategy. The
* managed thread system will call aws_thread_clean_up() on the thread after the background join has completed.
*
* Additionally, an API exists, aws_thread_join_all_managed(), which blocks and returns when all outstanding threads
* with the managed strategy have fully joined. This API is useful for tests (rather than waiting for many individual
* signals) and program shutdown or DLL unload. This API is automatically invoked by the common library clean up
* function. If the common library clean up is called from a managed thread, this will cause deadlock.
*
* Lazy thread joining is done only when threads finish their run function or when the user calls
* aws_thread_join_all_managed(). This means it may be a long time between thread function completion and the join
* being applied, but the queue of unjoined threads is always one or fewer so there is no critical resource
* backlog.
*
* Currently, only event loop group async cleanup and host resolver threads participate in the managed thread system.
* Additionally, event loop threads will increment and decrement the pending join count (they are manually joined
* internally) in order to have an accurate view of internal thread usage and also to prevent failure to release
* an event loop group fully from allowing aws_thread_join_all_managed() from running to completion when its
* intent is such that it should block instead.
*/
;
/**
* Thread names should be 15 characters or less.
* Longer names will not display on Linux.
* This length does not include a null terminator.
*/
;
typedef union aws_thread_once;
typedef unsigned long aws_thread_id_t;
typedef pthread_once_t aws_thread_once;
typedef pthread_t aws_thread_id_t;
/*
* Buffer size needed to represent aws_thread_id_t as a string (2 hex chars per byte
* plus '\0' terminator). Needed for portable printing because pthread_t is
* opaque.
*/
;
/**
* Returns an instance of system default thread options.
*/
const struct aws_thread_options *;
AWS_COMMON_API void ;
/**
* Initializes a new platform specific thread object struct (not the os-level
* thread itself).
*/
int ;
/**
* Creates an OS level thread and associates it with func. context will be passed to func when it is executed.
* options will be applied to the thread if they are applicable for the platform.
*
* After launch, you may join on the thread. A successfully launched thread must have clean_up called on it in order
* to avoid a handle leak. If you do not join before calling clean_up, the thread will become detached.
*
* Managed threads must not have join or clean_up called on them by external code.
*/
int ;
/**
* Gets the id of thread
*/
aws_thread_id_t ;
/**
* Gets the detach state of the thread. For example, is it safe to call join on
* this thread? Has it been detached()?
*/
enum aws_thread_detach_state ;
/**
* Joins the calling thread to a thread instance. Returns when thread is
* finished. Calling this from the associated OS thread will cause a deadlock.
*/
int ;
/**
* Blocking call that waits for all managed threads to complete their join call. This can only be called
* from the main thread or a non-managed thread.
*
* This gets called automatically from library cleanup.
*
* By default the wait is unbounded, but that default can be overridden via aws_thread_set_managed_join_timeout_ns()
*/
int ;
/**
* Overrides how long, in nanoseconds, that aws_thread_join_all_managed will wait for threads to complete.
* A value of zero will result in an unbounded wait.
*/
void ;
/**
* Cleans up the thread handle. Don't call this on a managed thread. If you wish to join the thread, you must join
* before calling this function.
*/
void ;
/**
* Returns the thread id of the calling thread.
*/
aws_thread_id_t ;
/**
* Compare thread ids.
*/
bool ;
/**
* Sleeps the current thread by nanos.
*/
void ;
typedef void;
/**
* Adds a callback to the chain to be called when the current thread joins.
* Callbacks are called from the current thread, in the reverse order they
* were added, after the thread function returns.
* If not called from within an aws_thread, has no effect.
*/
int ;
/**
* Increments the count of unjoined threads in the managed thread system. Used by managed threads and
* event loop threads. Additional usage requires the user to join corresponding threads themselves and
* correctly increment/decrement even in the face of launch/join errors.
*
* aws_thread_join_all_managed() will not return until this count has gone to zero.
*/
AWS_COMMON_API void ;
/**
* Decrements the count of unjoined threads in the managed thread system. Used by managed threads and
* event loop threads. Additional usage requires the user to join corresponding threads themselves and
* correctly increment/decrement even in the face of launch/join errors.
*
* aws_thread_join_all_managed() will not return until this count has gone to zero.
*/
AWS_COMMON_API void ;
/* AWS_COMMON_THREAD_H */