rlib
Convenience library for useful things
Loading...
Searching...
No Matches
rthreadpool.h
Go to the documentation of this file.
1/* RLIB - Convenience library for useful things
2 * Copyright (C) 2016 Haakon Sporsheim <haakon.sporsheim@gmail.com>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 3.0 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library.
16 * See the COPYING file at the root of the source repository.
17 */
18#ifndef __R_THREAD_POOL_H__
19#define __R_THREAD_POOL_H__
20
21#if !defined(__RLIB_H_INCLUDE_GUARD__) && !defined(RLIB_COMPILATION)
22#error "#include <rlib.h> only please."
23#endif
24
31#include <rlib/rtypes.h>
32#include <rlib/rref.h>
33
34#include <rlib/data/rbitset.h>
35
37
39
60typedef struct RThreadPool RThreadPool;
67typedef rpointer (*RThreadPoolFunc) (rpointer common, rpointer specific);
68
78 RThreadPoolFunc func, rpointer data);
79
81#define r_thread_pool_ref r_ref_ref
83#define r_thread_pool_unref r_ref_unref
84
90 const rchar * name, const RBitset * affinity, rpointer data);
93 rsize cpuidx, rpointer data);
96 const RBitset * cpuset, rpointer data);
102 const RBitset * cpuset, rpointer data);
103
109
112
113
114R_END_DECLS
115
118#endif /* __R_THREAD_POOL_H__ */
119
#define R_API
Public-API decoration: resolves to R_API_EXPORT while building rlib and R_API_IMPORT for consumers.
Definition rmacros.h:115
#define R_BEGIN_DECLS
Open an extern "C" block under C++ (no-op in C).
Definition rmacros.h:196
ruint r_thread_pool_running_threads(RThreadPool *pool)
Return the number of workers currently running in pool.
rboolean r_thread_pool_start_thread(RThreadPool *pool, const rchar *name, const RBitset *affinity, rpointer data)
Spawn one worker with optional name and CPU-affinity mask.
struct RThreadPool RThreadPool
Opaque, refcounted thread-pool handle.
Definition rthreadpool.h:60
void r_thread_pool_join(RThreadPool *pool)
Wait for all workers to finish; the pool must not be used for further _start_thread_* calls after thi...
rboolean r_thread_pool_start_thread_on_cpuset(RThreadPool *pool, const RBitset *cpuset, rpointer data)
Spawn one worker whose affinity is the given cpuset.
rpointer(* RThreadPoolFunc)(rpointer common, rpointer specific)
Worker entry-point signature.
Definition rthreadpool.h:67
rboolean r_thread_pool_start_thread_on_each_cpu(RThreadPool *pool, const RBitset *cpuset, rpointer data)
Spawn one worker per CPU set in cpuset, each pinned to its respective CPU.
RThreadPool * r_thread_pool_new(const rchar *prefix, RThreadPoolFunc func, rpointer data)
Create a new pool that will spawn workers running func.
rboolean r_thread_pool_start_thread_on_cpu(RThreadPool *pool, rsize cpuidx, rpointer data)
Spawn one worker pinned to a single CPU index.
char rchar
Default character type (char).
Definition rtypes.h:137
int rboolean
Boolean type (typedef'd to int).
Definition rtypes.h:59
unsigned int ruint
Unsigned int.
Definition rtypes.h:157
void * rpointer
Generic pointer (alias for void *).
Definition rtypes.h:327
unsigned long rsize
Unsigned pointer-sized size type (like size_t).
Definition rtypes.h:290
Fixed-width bitset with bit / byte / word accessors and bitwise compound operations.
Refcount base struct shared by every refcounted type in rlib.
Threads, mutexes (plain, recursive, read/write), condition variables, thread-specific storage and one...
Foundational type aliases used by every rlib header.
Fixed-width bitset.
Definition rbitset.h:68