PipeWire: spa/support/thread.h Source File

PipeWire 0.3.61

Loading...
Searching...
No Matches
thread.h
Go to the documentation of this file.
1/* Simple Plugin API
2 *
3 * Copyright © 2021 Wim Taymans
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
25#ifndef SPA_THREAD_H
26#define SPA_THREAD_H
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32#include <string.h>
33#include <errno.h>
34
35#include <spa/utils/defs.h>
36#include <spa/utils/hook.h>
37#include <spa/utils/dict.h>
38
51#define SPA_TYPE_INFO_Thread SPA_TYPE_INFO_POINTER_BASE "Thread"
52struct spa_thread;
53
54#define SPA_TYPE_INTERFACE_ThreadUtils SPA_TYPE_INFO_INTERFACE_BASE "ThreadUtils"
55#define SPA_VERSION_THREAD_UTILS 0
56struct spa_thread_utils { struct spa_interface iface; };
57
59struct spa_thread_utils_methods {
60#define SPA_VERSION_THREAD_UTILS_METHODS 0
61 uint32_t version;
62
64 struct spa_thread * (*create) (void *object, const struct spa_dict *props,
65 void *(*start)(void*), void *arg);
67 int (*join)(void *object, struct spa_thread *thread, void **retval);
68
70 int (*get_rt_range) (void *object, const struct spa_dict *props, int *min, int *max);
74 int (*acquire_rt) (void *object, struct spa_thread *thread, int priority);
76 int (*drop_rt) (void *object, struct spa_thread *thread);
77};
78
81static inline struct spa_thread *spa_thread_utils_create(struct spa_thread_utils *o,
82 const struct spa_dict *props, void *(*start_routine)(void*), void *arg)
83{
84 struct spa_thread *res = NULL;
85 spa_interface_call_res(&o->iface,
86 struct spa_thread_utils_methods, res, create, 0,
87 props, start_routine, arg);
88 return res;
89}
90
93static inline int spa_thread_utils_join(struct spa_thread_utils *o,
94 struct spa_thread *thread, void **retval)
95{
96 int res = -ENOTSUP;
97 spa_interface_call_res(&o->iface,
98 struct spa_thread_utils_methods, res, join, 0,
99 thread, retval);
100 return res;
101}
102
105static inline int spa_thread_utils_get_rt_range(struct spa_thread_utils *o,
106 const struct spa_dict *props, int *min, int *max)
107{
108 int res = -ENOTSUP;
109 spa_interface_call_res(&o->iface,
110 struct spa_thread_utils_methods, res, get_rt_range, 0,
111 props, min, max);
112 return res;
113}
114
117static inline int spa_thread_utils_acquire_rt(struct spa_thread_utils *o,
118 struct spa_thread *thread, int priority)
119{
120 int res = -ENOTSUP;
121 spa_interface_call_res(&o->iface,
122 struct spa_thread_utils_methods, res, acquire_rt, 0,
123 thread, priority);
124 return res;
125}
126
129static inline int spa_thread_utils_drop_rt(struct spa_thread_utils *o,
130 struct spa_thread *thread)
131{
132 int res = -ENOTSUP;
133 spa_interface_call_res(&o->iface,
134 struct spa_thread_utils_methods, res, drop_rt, 0, thread);
135 return res;
136}
137
138#define SPA_KEY_THREAD_NAME "thread.name" /* the thread name */
139#define SPA_KEY_THREAD_STACK_SIZE "thread.stack-size" /* the stack size of the thread */
140
145#ifdef __cplusplus
146} /* extern "C" */
147#endif
148
149#endif /* SPA_THREAD_H */
defs.h
spa/utils/defs.h
spa_interface_call_res
#define spa_interface_call_res(iface, method_type, res, method, vers,...)
Invoke method named method in the callbacks on the given interface object.
Definition: hook.h:255
spa_thread_utils_acquire_rt
static int spa_thread_utils_acquire_rt(struct spa_thread_utils *o, struct spa_thread *thread, int priority)
acquire realtime priority, a priority of -1 refers to the priority configured in the realtime module
Definition: thread.h:127
spa_thread_utils_get_rt_range
static int spa_thread_utils_get_rt_range(struct spa_thread_utils *o, const struct spa_dict *props, int *min, int *max)
get realtime priority range for threads created with props\ifile "/build/pipewire/src/pipewire/spa/i...
Definition: thread.h:115
spa_thread_utils_create
static struct spa_thread * spa_thread_utils_create(struct spa_thread_utils *o, const struct spa_dict *props, void *(*start_routine)(void *), void *arg)
create a new thread that runs start with arg\ifile "/build/pipewire/src/pipewire/spa/include/spa/sup...
Definition: thread.h:91
spa_thread_utils_join
static int spa_thread_utils_join(struct spa_thread_utils *o, struct spa_thread *thread, void **retval)
stop and join a thread
Definition: thread.h:103
spa_thread_utils_drop_rt
static int spa_thread_utils_drop_rt(struct spa_thread_utils *o, struct spa_thread *thread)
drop realtime priority
Definition: thread.h:139
hook.h
spa/utils/hook.h
string.h
spa/utils/string.h
spa_dict
Definition: dict.h:59
spa_interface
Definition: hook.h:158
spa_thread_utils_methods
thread utils
Definition: thread.h:68
spa_thread_utils_methods::drop_rt
int(* drop_rt)(void *object, struct spa_thread *thread)
drop realtime priority
Definition: thread.h:86
spa_thread_utils_methods::version
uint32_t version
Definition: thread.h:71
spa_thread_utils_methods::get_rt_range
int(* get_rt_range)(void *object, const struct spa_dict *props, int *min, int *max)
get realtime priority range for threads created with props
Definition: thread.h:80
spa_thread_utils_methods::join
int(* join)(void *object, struct spa_thread *thread, void **retval)
stop and join a thread
Definition: thread.h:77
spa_thread_utils_methods::acquire_rt
int(* acquire_rt)(void *object, struct spa_thread *thread, int priority)
acquire realtime priority, a priority of -1 refers to the priority configured in the realtime module
Definition: thread.h:84
spa_thread_utils
Definition: thread.h:65
spa_thread_utils::iface
struct spa_interface iface
Definition: thread.h:65
spa_thread
dict.h
spa/utils/dict.h