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-2018 Andy Green <andy@warmcat.com>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation:
9  * version 2.1 of the License.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19  * MA 02110-1301 USA
20  *
21  * included from libwebsockets.h
22  */
23 
36 
37 struct lws_threadpool;
38 struct lws_threadpool_task;
39 
40 enum lws_threadpool_task_status {
41  LWS_TP_STATUS_QUEUED,
42  LWS_TP_STATUS_RUNNING,
43  LWS_TP_STATUS_SYNCING,
44  LWS_TP_STATUS_STOPPING,
45  LWS_TP_STATUS_FINISHED, /* lws_threadpool_task_status() frees task */
46  LWS_TP_STATUS_STOPPED, /* lws_threadpool_task_status() frees task */
47 };
48 
49 enum lws_threadpool_task_return {
51  LWS_TP_RETURN_CHECKING_IN,
57  LWS_TP_RETURN_SYNC,
59  LWS_TP_RETURN_FINISHED,
61  LWS_TP_RETURN_STOPPED,
62 
63  /* OR on to indicate this task wishes to outlive its wsi */
64  LWS_TP_RETURN_FLAG_OUTLIVE = 64
65 };
66 
68  int threads;
69  int max_queue_depth;
70 };
71 
73  struct lws *wsi;
74  void *user;
75  const char *name;
76  char async_task;
79  enum lws_threadpool_task_return (*task)(void *user,
80  enum lws_threadpool_task_status s);
82  void (*cleanup)(struct lws *wsi, void *user);
91 };
92 
107 LWS_VISIBLE LWS_EXTERN struct lws_threadpool *
108 lws_threadpool_create(struct lws_context *context,
109  const struct lws_threadpool_create_args *args,
110  const char *format, ...) LWS_FORMAT(3);
111 
126 LWS_VISIBLE LWS_EXTERN void
127 lws_threadpool_finish(struct lws_threadpool *tp);
128 
136 LWS_VISIBLE LWS_EXTERN void
137 lws_threadpool_destroy(struct lws_threadpool *tp);
138 
159 LWS_VISIBLE LWS_EXTERN struct lws_threadpool_task *
160 lws_threadpool_enqueue(struct lws_threadpool *tp,
161  const struct lws_threadpool_task_args *args,
162  const char *format, ...) LWS_FORMAT(3);
163 
176 LWS_VISIBLE LWS_EXTERN int
177 lws_threadpool_dequeue(struct lws *wsi);
178 
196 LWS_VISIBLE LWS_EXTERN enum lws_threadpool_task_status
197 lws_threadpool_task_status_wsi(struct lws *wsi,
198  struct lws_threadpool_task **task, void **user);
199 
212 LWS_VISIBLE LWS_EXTERN void
213 lws_threadpool_task_sync(struct lws_threadpool_task *task, int stop);
214 
229 LWS_VISIBLE LWS_EXTERN void
230 lws_threadpool_dump(struct lws_threadpool *tp);
lws_threadpool_task_args::cleanup
void(* cleanup)(struct lws *wsi, void *user)
Definition: lws-threadpool.h:82
lws_threadpool_task_args::task
enum lws_threadpool_task_return(* task)(void *user, enum lws_threadpool_task_status s)
Definition: lws-threadpool.h:79
lws_threadpool_task_args::user
void * user
Definition: lws-threadpool.h:74
lws_threadpool_task_args::wsi
struct lws * wsi
Definition: lws-threadpool.h:73
lws_threadpool_create_args
Definition: lws-threadpool.h:67
lws_threadpool_task_args
Definition: lws-threadpool.h:72
lws_threadpool_task_args::async_task
char async_task
Definition: lws-threadpool.h:76
lws_threadpool_task_args::name
const char * name
Definition: lws-threadpool.h:75