2 * Copyright (c) 2010-2020 The RetroArch team
3 * Copyright (c) 2017 John Schember <john@nachtimwald.com>
5 * ---------------------------------------------------------------------------------------
6 * The following license statement only applies to this file (tpool.h).
7 * ---------------------------------------------------------------------------------------
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28 #ifndef __LIBRETRO_SDK_TPOOL_H__
29 #define __LIBRETRO_SDK_TPOOL_H__
31 #include <retro_common_api.h>
35 #include <retro_inline.h>
36 #include <retro_miscellaneous.h>
41 typedef struct tpool tpool_t;
47 * Callback function that the pool will call to do work.
49 typedef void (*thread_func_t)(void *arg);
53 * @num : Number of threads the pool should have.
56 * Create a thread pool.
60 tpool_t *tpool_create(size_t num);
66 * Destory a thread pool
67 * The pool can be destroyed while there is outstanding work to process. All
68 * outstanding unprocessed work will be discareded. There may be a delay before
69 * this function returns because it will block for work that is processing to
72 void tpool_destroy(tpool_t *tp);
77 * @func : Function the pool should call.
78 * @arg : Argument to pass to func.
80 * Add work to a thread pool.
82 * Returns: true if work was added, otherwise false.
84 bool tpool_add_work(tpool_t *tp, thread_func_t func, void *arg);
90 * Wait for all work in the pool to be completed.
92 void tpool_wait(tpool_t *tp);