PipeWire 0.3.65
spa/include/spa/support/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 *object, const struct spa_dict *props,
65 void *(*start)(void*), void *arg);
67 int (*join)(void *object, struct spa_thread *thread, void **retval);
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;
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;
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;
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;
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;
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 */
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, a priority of -1 refers to the priority configured in the realtime module
Definition: spa/include/spa/support/thread.h:127
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: spa/include/spa/support/thread.h:115
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: spa/include/spa/support/thread.h:91
static int spa_thread_utils_join(struct spa_thread_utils *o, struct spa_thread *thread, void **retval)
stop and join a thread
Definition: spa/include/spa/support/thread.h:103
static int spa_thread_utils_drop_rt(struct spa_thread_utils *o, struct spa_thread *thread)
drop realtime priority
Definition: spa/include/spa/support/thread.h:139
spa/utils/hook.h
spa/utils/string.h
Definition: utils/dict.h:59
Definition: hook.h:158
thread utils
Definition: spa/include/spa/support/thread.h:68
int(* drop_rt)(void *object, struct spa_thread *thread)
drop realtime priority
Definition: spa/include/spa/support/thread.h:86
uint32_t version
Definition: spa/include/spa/support/thread.h:71
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: spa/include/spa/support/thread.h:80
int(* join)(void *object, struct spa_thread *thread, void **retval)
stop and join a thread
Definition: spa/include/spa/support/thread.h:77
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: spa/include/spa/support/thread.h:84
Definition: spa/include/spa/support/thread.h:65
struct spa_interface iface
Definition: spa/include/spa/support/thread.h:65
spa/utils/dict.h