libwebsockets
Lightweight C library for HTML5 websockets
lws-threadpool.h
Go to the documentation of this file.
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 
38 struct lws_threadpool;
39 struct lws_threadpool_task;
40 
46  LWS_TP_STATUS_FINISHED, /* lws_threadpool_task_status() frees task */
47  LWS_TP_STATUS_STOPPED, /* lws_threadpool_task_status() frees task */
48 };
49 
63 
64  /* OR on to indicate this task wishes to outlive its wsi */
66 };
67 
69  int threads;
71 };
72 
74 #if defined(LWS_WITH_SECURE_STREAMS)
75  struct lws_ss_handle *ss;
76 #endif
77  struct lws *wsi;
79  void *user;
80  const char *name;
81  char async_task;
84  enum lws_threadpool_task_return (*task)(void *user,
87  void (*cleanup)(struct lws *wsi, void *user);
96 };
97 
112 LWS_VISIBLE LWS_EXTERN struct lws_threadpool *
113 lws_threadpool_create(struct lws_context *context,
114  const struct lws_threadpool_create_args *args,
115  const char *format, ...) LWS_FORMAT(3);
116 
132 lws_threadpool_finish(struct lws_threadpool *tp);
133 
142 lws_threadpool_destroy(struct lws_threadpool *tp);
143 
164 LWS_VISIBLE LWS_EXTERN struct lws_threadpool_task *
165 lws_threadpool_enqueue(struct lws_threadpool *tp,
166  const struct lws_threadpool_task_args *args,
167  const char *format, ...) LWS_FORMAT(3);
168 
188 
190 lws_threadpool_dequeue_task(struct lws_threadpool_task *task);
191 
192 
215 lws_threadpool_task_status_wsi(struct lws *wsi,
216  struct lws_threadpool_task **task, void **user)
218 
220 lws_threadpool_task_status(struct lws_threadpool_task *task, void **user);
221 
223 lws_threadpool_task_status_noreap(struct lws_threadpool_task *task);
224 
238 lws_threadpool_task_sync(struct lws_threadpool_task *task, int stop);
239 
255 lws_threadpool_dump(struct lws_threadpool *tp);
256 
257 
258 
259 LWS_VISIBLE LWS_EXTERN struct lws_threadpool_task *
261 
262 #if defined(LWS_WITH_SECURE_STREAMS)
263 LWS_VISIBLE LWS_EXTERN struct lws_threadpool_task *
264 lws_threadpool_get_task_ss(struct lws_ss_handle *ss);
265 #endif
266 
267 
269 lws_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)
275 lws_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 
#define LWS_WARN_DEPRECATED
#define LWS_FORMAT(string_index)
#define LWS_EXTERN
#define LWS_VISIBLE
LWS_VISIBLE LWS_EXTERN void lws_threadpool_destroy(struct lws_threadpool *tp)
lws_threadpool_task_status
@ LWS_TP_STATUS_FINISHED
@ LWS_TP_STATUS_SYNCING
@ LWS_TP_STATUS_STOPPING
@ LWS_TP_STATUS_QUEUED
@ LWS_TP_STATUS_RUNNING
@ LWS_TP_STATUS_STOPPED
lws_threadpool_task_return
@ LWS_TP_RETURN_STOPPED
@ LWS_TP_RETURN_FLAG_OUTLIVE
@ LWS_TP_RETURN_CHECKING_IN
@ LWS_TP_RETURN_FINISHED
@ LWS_TP_RETURN_SYNC
LWS_VISIBLE LWS_EXTERN int lws_threadpool_dequeue_task(struct lws_threadpool_task *task)
LWS_VISIBLE LWS_EXTERN void lws_threadpool_task_sync(struct lws_threadpool_task *task, int stop)
LWS_VISIBLE LWS_EXTERN enum lws_threadpool_task_status lws_threadpool_task_status_wsi(struct lws *wsi, struct lws_threadpool_task **task, void **user) LWS_WARN_DEPRECATED
LWS_VISIBLE LWS_EXTERN int lws_threadpool_foreach_task_wsi(struct lws *wsi, void *user, int(*cb)(struct lws_threadpool_task *task, void *user))
LWS_VISIBLE LWS_EXTERN void lws_threadpool_dump(struct lws_threadpool *tp)
LWS_VISIBLE LWS_EXTERN struct lws_threadpool * lws_threadpool_create(struct lws_context *context, const struct lws_threadpool_create_args *args, const char *format,...) LWS_FORMAT(3)
LWS_VISIBLE LWS_EXTERN int lws_threadpool_dequeue(struct lws *wsi) LWS_WARN_DEPRECATED
LWS_VISIBLE LWS_EXTERN enum lws_threadpool_task_status lws_threadpool_task_status_noreap(struct lws_threadpool_task *task)
LWS_VISIBLE LWS_EXTERN struct lws_threadpool_task * lws_threadpool_get_task_wsi(struct lws *wsi)
LWS_VISIBLE LWS_EXTERN struct lws_threadpool_task * lws_threadpool_enqueue(struct lws_threadpool *tp, const struct lws_threadpool_task_args *args, const char *format,...) LWS_FORMAT(3)
LWS_VISIBLE LWS_EXTERN void lws_threadpool_finish(struct lws_threadpool *tp)
enum lws_threadpool_task_return(* task)(void *user, enum lws_threadpool_task_status s)
void(* cleanup)(struct lws *wsi, void *user)