Project homepage Mailing List  API Docs  Github Mirror 
{"schema":"libjg2-1", "vpath":"/git/", "avatar":"/git/avatar/", "alang":"en-US,en;q\u003d0.5", "gen_ut":1571182567, "reponame":"libwebsockets", "desc":"libwebsockets lightweight C networking library", "owner": { "name": "Andy Green", "email": "", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" },"url":"", "f":3, "items": [ {"schema":"libjg2-1", "cid":"2d0d9fd6fc4c8ee24a9c644e164e5f97", "oid":{ "oid": "1cae39bb695b7201d43e8cc25eda98e625ceae2f", "alias": [ "refs/heads/master"]},"blobname": "include/libwebsockets/lws-threadpool.h", "blob": "/*\n * libwebsockets - small server side websockets and web server implementation\n *\n * Copyright (C) 2010 - 2019 Andy Green \\u003e\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \u0022Software\u0022), to\n * deal in the Software without restriction, including without limitation the\n * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n * sell copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \u0022AS IS\u0022, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n * IN THE SOFTWARE.\n */\n\n/** \u005cdefgroup threadpool Threadpool related functions\n * ##Threadpool\n * \u005cingroup lwsapi\n *\n * This allows you to create one or more pool of threads which can run tasks\n * associated with a wsi. If the pool is busy, tasks wait on a queue.\n *\n * Tasks don't have to be atomic, if they will take more than a few tens of ms\n * they should return back to the threadpool worker with a return of 0. This\n * will allow them to abort cleanly.\n */\n//@{\n\nstruct lws_threadpool;\nstruct lws_threadpool_task;\n\nenum lws_threadpool_task_status {\n\tLWS_TP_STATUS_QUEUED,\n\tLWS_TP_STATUS_RUNNING,\n\tLWS_TP_STATUS_SYNCING,\n\tLWS_TP_STATUS_STOPPING,\n\tLWS_TP_STATUS_FINISHED, /* lws_threadpool_task_status() frees task */\n\tLWS_TP_STATUS_STOPPED, /* lws_threadpool_task_status() frees task */\n};\n\nenum lws_threadpool_task_return {\n\t/** Still work to do, just confirming not being stopped */\n\tLWS_TP_RETURN_CHECKING_IN,\n\t/** Still work to do, enter cond_wait until service thread syncs. This\n\t * is used if you have filled your buffer(s) of data to the service\n\t * thread and are blocked until the service thread completes sending at\n\t * least one.\n\t */\n\tLWS_TP_RETURN_SYNC,\n\t/** No more work to do... */\n\tLWS_TP_RETURN_FINISHED,\n\t/** Responding to request to stop */\n\tLWS_TP_RETURN_STOPPED,\n\n\t/* OR on to indicate this task wishes to outlive its wsi */\n\tLWS_TP_RETURN_FLAG_OUTLIVE \u003d 64\n};\n\nstruct lws_threadpool_create_args {\n\tint threads;\n\tint max_queue_depth;\n};\n\nstruct lws_threadpool_task_args {\n\tstruct lws *wsi;\t/**\u003c user must set to wsi task is bound to */\n\tvoid *user;\t\t/**\u003c user may set (user-private pointer) */\n\tconst char *name;\t/**\u003c user may set to describe task */\n\tchar async_task;\t/**\u003c set to allow the task to shrug off the loss\n\t\t\t\t of the associated wsi and continue to\n\t\t\t\t completion */\n\tenum lws_threadpool_task_return (*task)(void *user,\n\t\t\t\t\tenum lws_threadpool_task_status s);\n\t/**\u003c user must set to actual task function */\n\tvoid (*cleanup)(struct lws *wsi, void *user);\n\t/**\u003c socket lifecycle may end while task is not stoppable, so the task\n\t * must be able to detach from any wsi and clean itself up when it does\n\t * stop. If NULL, no cleanup necessary, otherwise point to a user-\n\t * supplied function that destroys the stuff in \u005cp user.\n\t *\n\t * wsi may be NULL on entry, indicating the task got detached due to the\n\t * wsi closing before.\n\t */\n};\n\n/**\n * lws_threadpool_create() - create a pool of worker threads\n *\n * \u005cparam context: the lws_context the threadpool will exist inside\n * \u005cparam args: argument struct prepared by caller\n * \u005cparam format: printf-type format for the task name\n * \u005cparam ...: printf type args for the task name format\n *\n * Creates a pool of worker threads with \u005cp threads and a queue of up to\n * \u005cp max_queue_depth waiting tasks if all the threads are busy.\n *\n * Returns NULL if OOM, or a struct lws_threadpool pointer that must be\n * destroyed by lws_threadpool_destroy().\n */\nLWS_VISIBLE LWS_EXTERN struct lws_threadpool *\nlws_threadpool_create(struct lws_context *context,\n\t\t const struct lws_threadpool_create_args *args,\n\t\t const char *format, ...) LWS_FORMAT(3);\n\n/**\n * lws_threadpool_finish() - Stop all pending and running tasks\n *\n * \u005cparam tp: the threadpool object\n *\n * Marks the threadpool as under destruction. Removes everything from the\n * pending queue and completes those tasks as LWS_TP_STATUS_STOPPED.\n *\n * Running tasks will also get LWS_TP_STATUS_STOPPED as soon as they\n * \u0022resurface\u0022.\n *\n * This doesn't reap tasks or free the threadpool, the reaping is done by the\n * lws_threadpool_task_status() on the done task.\n */\nLWS_VISIBLE LWS_EXTERN void\nlws_threadpool_finish(struct lws_threadpool *tp);\n\n/**\n * lws_threadpool_destroy() - Destroy a threadpool\n *\n * \u005cparam tp: the threadpool object\n *\n * Waits for all worker threads to stop, ends the threads and frees the tp.\n */\nLWS_VISIBLE LWS_EXTERN void\nlws_threadpool_destroy(struct lws_threadpool *tp);\n\n/**\n * lws_threadpool_enqueue() - Queue the task and run it on a worker thread when possible\n *\n * \u005cparam tp: the threadpool to queue / run on\n * \u005cparam args: information about what to run\n * \u005cparam format: printf-type format for the task name\n * \u005cparam ...: printf type args for the task name format\n *\n * This asks for a task to run ASAP on a worker thread in threadpool \u005cp tp.\n *\n * The args defines the wsi, a user-private pointer, a timeout in secs and\n * a pointer to the task function.\n *\n * Returns NULL or an opaque pointer to the queued (or running, or completed)\n * task.\n *\n * Once a task is created and enqueued, it can only be destroyed by calling\n * lws_threadpool_task_status() on it after it has reached the state\n * LWS_TP_STATUS_FINISHED or LWS_TP_STATUS_STOPPED.\n */\nLWS_VISIBLE LWS_EXTERN struct lws_threadpool_task *\nlws_threadpool_enqueue(struct lws_threadpool *tp,\n\t\t const struct lws_threadpool_task_args *args,\n\t\t const char *format, ...) LWS_FORMAT(3);\n\n/**\n * lws_threadpool_dequeue() - Dequeue or try to stop a running task\n *\n * \u005cparam wsi: the wsi whose current task we want to eliminate\n *\n * Returns 0 is the task was dequeued or already compeleted, or 1 if the task\n * has been asked to stop asynchronously.\n *\n * This doesn't free the task. It only shortcuts it to state\n * LWS_TP_STATUS_STOPPED. lws_threadpool_task_status() must be performed on\n * the task separately once it is in LWS_TP_STATUS_STOPPED to free the task.\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_threadpool_dequeue(struct lws *wsi);\n\n/**\n * lws_threadpool_task_status() - Dequeue or try to stop a running task\n *\n * \u005cparam wsi: the wsi to query the current task of\n * \u005cparam task: receives a pointer to the opaque task\n * \u005cparam user: receives a void * pointer to the task user data\n *\n * This is the equivalent of posix waitpid()... it returns the status of the\n * task, and if the task is in state LWS_TP_STATUS_FINISHED or\n * LWS_TP_STATUS_STOPPED, frees \u005cp task. If in another state, the task\n * continues to exist.\n *\n * This is designed to be called from the service thread.\n *\n * Its use is to make sure the service thread has seen the state of the task\n * before deleting it.\n */\nLWS_VISIBLE LWS_EXTERN enum lws_threadpool_task_status\nlws_threadpool_task_status_wsi(struct lws *wsi,\n\t\t\t struct lws_threadpool_task **task, void **user);\n\n/**\n * lws_threadpool_task_sync() - Indicate to a stalled task it may continue\n *\n * \u005cparam task: the task to unblock\n * \u005cparam stop: 0 \u003d run after unblock, 1 \u003d when he unblocks, stop him\n *\n * Inform the task that the service thread has finished with the shared data\n * and that the task, if blocked in LWS_TP_RETURN_SYNC, may continue.\n *\n * If the lws service context determined that the task must be aborted, it\n * should still call this but with stop \u003d 1, causing the task to finish.\n */\nLWS_VISIBLE LWS_EXTERN void\nlws_threadpool_task_sync(struct lws_threadpool_task *task, int stop);\n\n/**\n * lws_threadpool_dump() - dump the state of a threadpool to the log\n *\n * \u005cparam tp: The threadpool to dump\n *\n * This locks the threadpool and then dumps the pending queue, the worker\n * threads and the done queue, together with time information for how long\n * the tasks have been in their current state, how long they have occupied a\n * thread, etc.\n *\n * This only does anything on lws builds with CMAKE_BUILD_TYPE\u003dDEBUG, otherwise\n * while it still exists, it's a NOP.\n */\n\nLWS_VISIBLE LWS_EXTERN void\nlws_threadpool_dump(struct lws_threadpool *tp);\n//@}\n","s":{"c":1571182567,"u": 593}} ],"g": 2867,"chitpc": 0,"ehitpc": 0, "indexed":0 }