| 1 | /* |
| 2 | * Copyright (c) 2010-2020 The RetroArch team |
| 3 | * Copyright (c) 2017 John Schember <john@nachtimwald.com> |
| 4 | * |
| 5 | * --------------------------------------------------------------------------------------- |
| 6 | * The following license statement only applies to this file (tpool.h). |
| 7 | * --------------------------------------------------------------------------------------- |
| 8 | * |
| 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: |
| 15 | * |
| 16 | * The above copyright notice and this permission notice shall be included in |
| 17 | * all copies or substantial portions of the Software. |
| 18 | * |
| 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 |
| 25 | * THE SOFTWARE |
| 26 | */ |
| 27 | |
| 28 | #ifndef __LIBRETRO_SDK_TPOOL_H__ |
| 29 | #define __LIBRETRO_SDK_TPOOL_H__ |
| 30 | |
| 31 | #include <retro_common_api.h> |
| 32 | |
| 33 | #include <boolean.h> |
| 34 | |
| 35 | #include <retro_inline.h> |
| 36 | #include <retro_miscellaneous.h> |
| 37 | |
| 38 | RETRO_BEGIN_DECLS |
| 39 | |
| 40 | struct tpool; |
| 41 | typedef struct tpool tpool_t; |
| 42 | |
| 43 | /** |
| 44 | * (*thread_func_t): |
| 45 | * @arg : Argument. |
| 46 | * |
| 47 | * Callback function that the pool will call to do work. |
| 48 | **/ |
| 49 | typedef void (*thread_func_t)(void *arg); |
| 50 | |
| 51 | /** |
| 52 | * tpool_create: |
| 53 | * @num : Number of threads the pool should have. |
| 54 | * If 0 defaults to 2. |
| 55 | * |
| 56 | * Create a thread pool. |
| 57 | * |
| 58 | * Returns: pool. |
| 59 | */ |
| 60 | tpool_t *tpool_create(size_t num); |
| 61 | |
| 62 | /** |
| 63 | * tpool_destroy: |
| 64 | * @tp : Thread pool. |
| 65 | * |
| 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 |
| 70 | * complete. |
| 71 | **/ |
| 72 | void tpool_destroy(tpool_t *tp); |
| 73 | |
| 74 | /** |
| 75 | * tpool_add_work: |
| 76 | * @tp : Thread pool. |
| 77 | * @func : Function the pool should call. |
| 78 | * @arg : Argument to pass to func. |
| 79 | * |
| 80 | * Add work to a thread pool. |
| 81 | * |
| 82 | * Returns: true if work was added, otherwise false. |
| 83 | **/ |
| 84 | bool tpool_add_work(tpool_t *tp, thread_func_t func, void *arg); |
| 85 | |
| 86 | /** |
| 87 | * tpool_wait: |
| 88 | * @tp Thread pool. |
| 89 | * |
| 90 | * Wait for all work in the pool to be completed. |
| 91 | */ |
| 92 | void tpool_wait(tpool_t *tp); |
| 93 | |
| 94 | RETRO_END_DECLS |
| 95 | |
| 96 | #endif |