PipeWire 0.3.43
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; };
60#define SPA_VERSION_THREAD_UTILS_METHODS 0
61 uint32_t version;
64 struct spa_thread * (*create) (void *data, const struct spa_dict *props,
65 void *(*start)(void*), void *arg);
67 int (*join)(void *data, struct spa_thread *thread, void **retval);
70 int (*get_rt_range) (void *data, const struct spa_dict *props, int *min, int *max);
72 int (*acquire_rt) (void *data, struct spa_thread *thread, int priority);
74 int (*drop_rt) (void *data, struct spa_thread *thread);
75};
76
79static inline struct spa_thread *spa_thread_utils_create(struct spa_thread_utils *o,
80 const struct spa_dict *props, void *(*start_routine)(void*), void *arg)
81{
82 struct spa_thread *res = NULL;
84 struct spa_thread_utils_methods, res, create, 0,
85 props, start_routine, arg);
86 return res;
87}
88
91static inline int spa_thread_utils_join(struct spa_thread_utils *o,
92 struct spa_thread *thread, void **retval)
93{
94 int res = -ENOTSUP;
96 struct spa_thread_utils_methods, res, join, 0,
97 thread, retval);
98 return res;
99}
100
103static inline int spa_thread_utils_get_rt_range(struct spa_thread_utils *o,
104 const struct spa_dict *props, int *min, int *max)
105{
106 int res = -ENOTSUP;
108 struct spa_thread_utils_methods, res, get_rt_range, 0,
109 props, min, max);
110 return res;
111}
112
115static inline int spa_thread_utils_acquire_rt(struct spa_thread_utils *o,
116 struct spa_thread *thread, int priority)
117{
118 int res = -ENOTSUP;
120 struct spa_thread_utils_methods, res, acquire_rt, 0,
121 thread, priority);
122 return res;
123}
124
127static inline int spa_thread_utils_drop_rt(struct spa_thread_utils *o,
128 struct spa_thread *thread)
129{
130 int res = -ENOTSUP;
132 struct spa_thread_utils_methods, res, drop_rt, 0, thread);
133 return res;
134}
135
140#ifdef __cplusplus
141} /* extern "C" */
142#endif
143
144#endif /* SPA_THREAD_H */
spa/utils/defs.h
#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
static int spa_thread_utils_acquire_rt(struct spa_thread_utils *o, struct spa_thread *thread, int priority)
acquire realtime priority
Definition: thread.h:125
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
Definition: thread.h:113
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
Definition: thread.h:89
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:101
static int spa_thread_utils_drop_rt(struct spa_thread_utils *o, struct spa_thread *thread)
drop realtime priority
Definition: thread.h:137
spa/utils/hook.h
spa/utils/string.h
Definition: dict.h:59
Definition: hook.h:158
thread utils
Definition: thread.h:68
int(* join)(void *data, struct spa_thread *thread, void **retval)
stop and join a thread
Definition: thread.h:77
int(* acquire_rt)(void *data, struct spa_thread *thread, int priority)
acquire realtime priority
Definition: thread.h:82
int(* drop_rt)(void *data, struct spa_thread *thread)
drop realtime priority
Definition: thread.h:84
uint32_t version
Definition: thread.h:71
int(* get_rt_range)(void *data, const struct spa_dict *props, int *min, int *max)
get realtime priority range for threads created with props
Definition: thread.h:80
Definition: thread.h:65
struct spa_interface iface
Definition: thread.h:65
spa/utils/dict.h