rlib
Convenience library for useful things
Loading...
Searching...
No Matches
rtaskqueue.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_TASK_QUEUE_H__
19#define __R_TASK_QUEUE_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
36#include <stdarg.h>
37
39
65typedef struct RTask RTask;
67typedef struct RTaskQueue RTaskQueue;
75typedef void (*RTaskFunc) (rpointer data, RTaskQueue * queue, RTask * task);
76
78#define r_task_ref r_ref_ref
80#define r_task_unref r_ref_unref
94R_API rboolean r_task_add_dep_v (RTask * task, RTask * dep, va_list args);
106R_API rboolean r_task_cancel (RTask * task, rboolean wait_if_running);
113
121R_API RTaskQueue * r_task_queue_new (ruint groups, ruint threads_per_group) R_ATTR_MALLOC;
126R_API RTaskQueue * r_task_queue_new_pin_and_group_on_numa_node (const RBitset * nodeset, ruint threads_per_group) R_ATTR_MALLOC;
136R_API RTaskQueue * r_task_queue_new_pin_on_each_cpu (const RBitset * cpuset, ruint groups) R_ATTR_MALLOC;
143#define r_task_queue_ref r_ref_ref
145#define r_task_queue_unref r_ref_unref
151
166 rpointer data, RDestroyNotify datanotify);
172#define r_task_queue_add_task(queue, task) \
173 r_task_queue_add_task_with_group (queue, task, RUINT_MAX)
184 RTask * task, ruint group);
185
192#define r_task_queue_add(queue, func, data, datanotify) \
193 r_task_queue_add_full (queue, RUINT_MAX, func, data, datanotify, NULL)
206 RTaskFunc func, rpointer data, RDestroyNotify datanotify,
210 RTaskFunc func, rpointer data, RDestroyNotify datanotify,
211 va_list args) R_ATTR_WARN_UNUSED_RESULT;
212
219
220R_END_DECLS
221
224#endif /* __R_TASK_QUEUE_H__ */
225
#define R_ATTR_WARN_UNUSED_RESULT
Warn if a function's return value is ignored.
Definition rmacros.h:278
#define R_ATTR_NULL_TERMINATED
Mark a variadic function as requiring a NULL sentinel.
Definition rmacros.h:336
#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
rboolean r_task_cancel(RTask *task, rboolean wait_if_running)
Cancel a pending or running task.
RTaskQueue * r_task_queue_new_pin_on_cpu_group_numa_node(const RBitset *nodeset)
One worker per CPU on the selected NUMA nodes, grouped per NUMA node.
rboolean r_task_add_dep(RTask *task, RTask *dep,...)
Add one or more dependencies to a task that has not yet run.
RTask * r_task_queue_add_full(RTaskQueue *queue, ruint group, RTaskFunc func, rpointer data, RDestroyNotify datanotify,...) R_ATTR_WARN_UNUSED_RESULT
Allocate-and-dispatch a task with group and dependencies.
ruint r_task_queue_group_count(const RTaskQueue *queue)
Number of worker groups in queue.
RTaskQueue * r_task_queue_new_pin_on_each_cpu(const RBitset *cpuset, ruint groups)
One worker per CPU in cpuset; workers are partitioned evenly across groups groups.
struct RTaskQueue RTaskQueue
Opaque, refcounted task-queue handle.
Definition rtaskqueue.h:67
RTaskQueue * r_task_queue_new(ruint groups, ruint threads_per_group)
Create a queue with groups worker groups, each containing threads_per_group worker threads.
RTask * r_task_queue_allocate(RTaskQueue *queue, RTaskFunc func, rpointer data, RDestroyNotify datanotify)
Allocate a task bound to queue without dispatching it.
rboolean r_task_wait(RTask *task)
Block until task has finished (cancelled tasks count as finished).
RTaskQueue * r_task_queue_new_pin_and_group_on_numa_node(const RBitset *nodeset, ruint threads_per_group)
One group per NUMA node selected by nodeset, each with threads_per_group workers pinned to that node'...
struct RTask RTask
Opaque, refcounted task handle.
Definition rtaskqueue.h:65
rboolean r_task_queue_add_task_with_group(RTaskQueue *queue, RTask *task, ruint group)
Dispatch a pre-allocated task to a specific group.
rboolean r_task_add_dep_v(RTask *task, RTask *dep, va_list args)
va_list variant of r_task_add_dep.
RTaskQueue * r_task_queue_new_pin_on_each_cpu_group_numa_node(const RBitset *cpuset)
One worker per CPU in cpuset, grouped by the NUMA node each CPU belongs to.
RTask * r_task_queue_add_full_v(RTaskQueue *queue, ruint group, RTaskFunc func, rpointer data, RDestroyNotify datanotify, va_list args) R_ATTR_WARN_UNUSED_RESULT
va_list variant of r_task_queue_add_full.
ruint r_task_queue_thread_count(const RTaskQueue *queue)
Total number of worker threads across all groups.
RTaskQueue * r_task_queue_current(void)
Return the queue owning the calling thread, or NULL if the calling thread is not a queue worker.
void(* RTaskFunc)(rpointer data, RTaskQueue *queue, RTask *task)
Task entry-point signature.
Definition rtaskqueue.h:75
rsize r_task_queue_queued_tasks(const RTaskQueue *queue)
Number of tasks currently queued but not yet running.
int rboolean
Boolean type (typedef'd to int).
Definition rtypes.h:59
unsigned int ruint
Unsigned int.
Definition rtypes.h:157
void(* RDestroyNotify)(rpointer ptr)
Destructor callback: free / release the value at ptr.
Definition rtypes.h:401
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.
Foundational type aliases used by every rlib header.
Fixed-width bitset.
Definition rbitset.h:68