libwebsockets
Lightweight C library for HTML5 websockets
lws-threadpool.h
1/*
2 * libwebsockets - small server side websockets and web server implementation
3 *
4 * Copyright (C) 2010 - 2020 Andy Green <andy@warmcat.com>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 * IN THE SOFTWARE.
23 */
24
37
38struct lws_threadpool;
39struct lws_threadpool_task;
40
41enum lws_threadpool_task_status {
42 LWS_TP_STATUS_QUEUED,
43 LWS_TP_STATUS_RUNNING,
44 LWS_TP_STATUS_SYNCING,
45 LWS_TP_STATUS_STOPPING,
46 LWS_TP_STATUS_FINISHED, /* lws_threadpool_task_status() frees task */
47 LWS_TP_STATUS_STOPPED, /* lws_threadpool_task_status() frees task */
48};
49
50enum lws_threadpool_task_return {
52 LWS_TP_RETURN_CHECKING_IN,
58 LWS_TP_RETURN_SYNC,
60 LWS_TP_RETURN_FINISHED,
62 LWS_TP_RETURN_STOPPED,
63
64 /* OR on to indicate this task wishes to outlive its wsi */
65 LWS_TP_RETURN_FLAG_OUTLIVE = 64
66};
67
69 int threads;
70 int max_queue_depth;
71};
72
74#if defined(LWS_WITH_SECURE_STREAMS)
75 struct lws_ss_handle *ss;
76#endif
77 struct lws *wsi;
78
79 void *user;
80 const char *name;
84 enum lws_threadpool_task_return (*task)(void *user,
85 enum lws_threadpool_task_status s);
87 void (*cleanup)(struct lws *wsi, void *user);
96};
97
112LWS_VISIBLE LWS_EXTERN struct lws_threadpool *
113lws_threadpool_create(struct lws_context *context,
114 const struct lws_threadpool_create_args *args,
115 const char *format, ...) LWS_FORMAT(3);
116
131LWS_VISIBLE LWS_EXTERN void
132lws_threadpool_finish(struct lws_threadpool *tp);
133
141LWS_VISIBLE LWS_EXTERN void
142lws_threadpool_destroy(struct lws_threadpool *tp);
143
164LWS_VISIBLE LWS_EXTERN struct lws_threadpool_task *
165lws_threadpool_enqueue(struct lws_threadpool *tp,
166 const struct lws_threadpool_task_args *args,
167 const char *format, ...) LWS_FORMAT(3);
168
186LWS_VISIBLE LWS_EXTERN int
187lws_threadpool_dequeue(struct lws *wsi) LWS_WARN_DEPRECATED;
188
189LWS_VISIBLE LWS_EXTERN int
190lws_threadpool_dequeue_task(struct lws_threadpool_task *task);
191
192
214LWS_VISIBLE LWS_EXTERN enum lws_threadpool_task_status
215lws_threadpool_task_status_wsi(struct lws *wsi,
216 struct lws_threadpool_task **task, void **user)
217 LWS_WARN_DEPRECATED;
218
219LWS_VISIBLE LWS_EXTERN enum lws_threadpool_task_status
220lws_threadpool_task_status(struct lws_threadpool_task *task, void **user);
221
222LWS_VISIBLE LWS_EXTERN enum lws_threadpool_task_status
223lws_threadpool_task_status_noreap(struct lws_threadpool_task *task);
224
237LWS_VISIBLE LWS_EXTERN void
238lws_threadpool_task_sync(struct lws_threadpool_task *task, int stop);
239
253
254LWS_VISIBLE LWS_EXTERN void
255lws_threadpool_dump(struct lws_threadpool *tp);
256
257
258
259LWS_VISIBLE LWS_EXTERN struct lws_threadpool_task *
260lws_threadpool_get_task_wsi(struct lws *wsi);
261
262#if defined(LWS_WITH_SECURE_STREAMS)
263LWS_VISIBLE LWS_EXTERN struct lws_threadpool_task *
264lws_threadpool_get_task_ss(struct lws_ss_handle *ss);
265#endif
266
267
268LWS_VISIBLE LWS_EXTERN int
269lws_threadpool_foreach_task_wsi(struct lws *wsi, void *user,
270 int (*cb)(struct lws_threadpool_task *task,
271 void *user));
272
273#if defined(LWS_WITH_SECURE_STREAMS)
274LWS_VISIBLE LWS_EXTERN int
275lws_threadpool_foreach_task_ss(struct lws_ss_handle *ss, void *user,
276 int (*cb)(struct lws_threadpool_task *task, void *user));
277#endif
278
279
Definition lws-threadpool.h:68
Definition lws-threadpool.h:73
void * user
Definition lws-threadpool.h:79
const char * name
Definition lws-threadpool.h:80
struct lws * wsi
Definition lws-threadpool.h:77
enum lws_threadpool_task_return(* task)(void *user, enum lws_threadpool_task_status s)
Definition lws-threadpool.h:84
char async_task
Definition lws-threadpool.h:81
void(* cleanup)(struct lws *wsi, void *user)
Definition lws-threadpool.h:87