diff options
author | Mikhail Burakov <mburakov@mailbox.org> | 2022-07-26 12:20:41 +0200 |
---|---|---|
committer | Mikhail Burakov <mburakov@mailbox.org> | 2022-07-26 12:20:41 +0200 |
commit | 5366104ae61e531fbaa7291ba44822b6b38b8b3d (patch) | |
tree | 5aedc1ec5e434365180a6421a9dc335b2bc60f58 /thread_pool.h |
Import existing toolbox components
Diffstat (limited to 'thread_pool.h')
-rw-r--r-- | thread_pool.h | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/thread_pool.h b/thread_pool.h new file mode 100644 index 0000000..496fd9c --- /dev/null +++ b/thread_pool.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2022 Mikhail Burakov. This file is part of toolbox. + * + * toolbox is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * toolbox is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with toolbox. If not, see <https://www.gnu.org/licenses/>. + */ + +#ifndef THREAD_POOL_H_ +#define THREAD_POOL_H_ + +#include <stdatomic.h> +#include <stddef.h> +#include <threads.h> + +struct ThreadPool_Task; + +struct ThreadPool { + atomic_bool running; + thrd_t* threads; + size_t threads_count; + cnd_t tasks_cond; + mtx_t tasks_mutex; + struct ThreadPool_Task* tasks; + size_t tasks_count; +}; + +int ThreadPool_Create(struct ThreadPool* thread_pool, size_t threads_count); +int ThreadPool_Schedule(struct ThreadPool* thread_pool, void (*fun)(void*), + void* user); +void ThreadPool_Destroy(struct ThreadPool* thread_pool); + +#endif // THREAD_POOL_H_ |