PipeWire  0.3.33
thread-loop.h
Go to the documentation of this file.
1 /* PipeWire
2  *
3  * Copyright © 2018 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 PIPEWIRE_THREAD_LOOP_H
26 #define PIPEWIRE_THREAD_LOOP_H
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 #include <pipewire/loop.h>
33 
98 struct pw_thread_loop;
99 
102 #define PW_VERSION_THREAD_LOOP_EVENTS 0
103  uint32_t version;
104 
106  void (*destroy) (void *data);
107 };
108 
110 struct pw_thread_loop *
111 pw_thread_loop_new(const char *name, const struct spa_dict *props);
112 
115 struct pw_thread_loop *
116 pw_thread_loop_new_full(struct pw_loop *loop, const char *name, const struct spa_dict *props);
117 
119 void pw_thread_loop_destroy(struct pw_thread_loop *loop);
120 
122 void pw_thread_loop_add_listener(struct pw_thread_loop *loop,
123  struct spa_hook *listener,
124  const struct pw_thread_loop_events *events,
125  void *data);
126 
128 struct pw_loop * pw_thread_loop_get_loop(struct pw_thread_loop *loop);
129 
131 int pw_thread_loop_start(struct pw_thread_loop *loop);
132 
134 void pw_thread_loop_stop(struct pw_thread_loop *loop);
135 
137 void pw_thread_loop_lock(struct pw_thread_loop *loop);
138 
140 void pw_thread_loop_unlock(struct pw_thread_loop *loop);
141 
143 void pw_thread_loop_wait(struct pw_thread_loop *loop);
144 
147 int pw_thread_loop_timed_wait(struct pw_thread_loop *loop, int wait_max_sec);
148 
151 int pw_thread_loop_get_time(struct pw_thread_loop *loop, struct timespec *abstime, int64_t timeout);
152 
156 int pw_thread_loop_timed_wait_full(struct pw_thread_loop *loop, struct timespec *abstime);
157 
159 void pw_thread_loop_signal(struct pw_thread_loop *loop, bool wait_for_accept);
160 
162 void pw_thread_loop_accept(struct pw_thread_loop *loop);
163 
165 bool pw_thread_loop_in_thread(struct pw_thread_loop *loop);
166 
171 #ifdef __cplusplus
172 }
173 #endif
174 
175 #endif /* PIPEWIRE_THREAD_LOOP_H */
pw_loop_new
struct pw_loop * pw_loop_new(const struct spa_dict *props)
Create a new loop.
Definition: loop.c:54
pw_thread_loop_new_full
struct pw_thread_loop * pw_thread_loop_new_full(struct pw_loop *loop, const char *name, const struct spa_dict *props)
Create a new PipeWire Threaded Loop Object.
Definition: thread-loop.c:204
pw_thread_loop_start
int pw_thread_loop_start(struct pw_thread_loop *loop)
Start the thread to handle loop.
Definition: thread-loop.c:281
pw_thread_loop_unlock
void pw_thread_loop_unlock(struct pw_thread_loop *loop)
Unlock the mutex associated with loop.
Definition: thread-loop.c:337
log.h
pw_loop_leave
#define pw_loop_leave(l)
Definition: src/pipewire/loop.h:69
name
const char * name
Definition: media-session.c:2379
loop.h
pw_thread_loop_signal
void pw_thread_loop_signal(struct pw_thread_loop *loop, bool wait_for_accept)
Signal the thread.
Definition: thread-loop.c:353
pw_thread_loop_get_loop
struct pw_loop * pw_thread_loop_get_loop(struct pw_thread_loop *loop)
Get the loop implementation of the thread loop.
Definition: thread-loop.c:245
data
user data to add to an object
Definition: filter.c:75
pw_loop
Definition: src/pipewire/loop.h:47
SPA_EXPORT
#define SPA_EXPORT
Definition: defs.h:208
pw_thread_loop_events::destroy
void(* destroy)(void *data)
the loop is destroyed
Definition: thread-loop.h:106
thread
Definition: module-rtkit.c:70
pw_thread_loop_timed_wait_full
int pw_thread_loop_timed_wait_full(struct pw_thread_loop *loop, struct timespec *abstime)
Wait for the loop thread to call pw_thread_loop_signal() or time out.
Definition: thread-loop.c:436
pw_log_trace
#define pw_log_trace(...)
Definition: src/pipewire/log.h:90
pw_thread_loop_in_thread
bool pw_thread_loop_in_thread(struct pw_thread_loop *loop)
Check if we are inside the thread of the loop.
Definition: thread-loop.c:464
SPA_NSEC_PER_SEC
#define SPA_NSEC_PER_SEC
Definition: defs.h:184
spa_hook_list_append
void spa_hook_list_append(struct spa_hook_list *list, struct spa_hook *hook, const void *funcs, void *data)
Append a hook.
Definition: hook.h:316
CHECK
#define CHECK(expression, label)
Definition: thread-loop.c:99
props
const char * props
Definition: media-session.c:2382
spa_source
Definition: build-12775836/doc/spa/support/loop.h:58
pw_loop_destroy_source
#define pw_loop_destroy_source(l,...)
Definition: src/pipewire/loop.h:80
pw_loop_add_hook
#define pw_loop_add_hook(l,...)
Definition: src/pipewire/loop.h:66
pw_loop_add_event
#define pw_loop_add_event(l,...)
Definition: src/pipewire/loop.h:75
spa_hook
A hook, contains the structure with functions and the data passed to the functions.
Definition: hook.h:295
spa_loop_control_hooks
Control hooks.
Definition: build-12775836/doc/spa/support/loop.h:124
pw_thread_loop_timed_wait
int pw_thread_loop_timed_wait(struct pw_thread_loop *loop, int wait_max_sec)
Wait for the loop thread to call pw_thread_loop_signal() or time out.
Definition: thread-loop.c:392
pw_thread_loop_stop
void pw_thread_loop_stop(struct pw_thread_loop *loop)
Quit the loop and stop its thread.
Definition: thread-loop.c:305
pw_thread_loop_events
Thread loop events.
Definition: thread-loop.h:101
spa_dict
Definition: utils/dict.h:48
pw_loop_signal_event
#define pw_loop_signal_event(l,...)
Definition: src/pipewire/loop.h:76
thread-loop.h
pw_thread_loop_get_time
int pw_thread_loop_get_time(struct pw_thread_loop *loop, struct timespec *abstime, int64_t timeout)
Get the current time of the loop + timeout.
Definition: thread-loop.c:413
spa_strerror
#define spa_strerror(err)
Definition: result.h:51
result.h
pw_thread_loop_wait
void pw_thread_loop_wait(struct pw_thread_loop *loop)
Wait for the loop thread to call pw_thread_loop_signal()
Definition: thread-loop.c:374
pw_log_debug
#define pw_log_debug(...)
Definition: src/pipewire/log.h:89
pw_loop_enter
#define pw_loop_enter(l)
Definition: src/pipewire/loop.h:67
pw_thread_loop_events::version
uint32_t version
Definition: thread-loop.h:103
pw_thread_loop_add_listener
void pw_thread_loop_add_listener(struct pw_thread_loop *loop, struct spa_hook *listener, const struct pw_thread_loop_events *events, void *data)
Add an event listener.
Definition: thread-loop.c:235
pw_loop_iterate
#define pw_loop_iterate(l,...)
Definition: src/pipewire/loop.h:68
spa_hook_list
A list of hooks.
Definition: hook.h:284
pw_log_warn
#define pw_log_warn(...)
Definition: src/pipewire/log.h:87
SPA_VERSION_LOOP_CONTROL_HOOKS
#define SPA_VERSION_LOOP_CONTROL_HOOKS
Definition: build-12775836/doc/spa/support/loop.h:125
pw_thread_loop_events_destroy
#define pw_thread_loop_events_destroy(o)
Definition: thread-loop.c:37
pw_loop_destroy
void pw_loop_destroy(struct pw_loop *loop)
Destroy a loop.
Definition: loop.c:156
pw_thread_loop_destroy
void pw_thread_loop_destroy(struct pw_thread_loop *loop)
Destroy a threaded loop.
Definition: thread-loop.c:212
spa_hook_remove
void spa_hook_remove(struct spa_hook *hook)
Remove a hook.
Definition: hook.h:336
pw_thread_loop_accept
void pw_thread_loop_accept(struct pw_thread_loop *loop)
Signal the loop thread waiting for accept with pw_thread_loop_signal()
Definition: thread-loop.c:451
spa_loop_control_hooks::after
void(* after)(void *data)
Executed right after waiting for events.
Definition: build-12775836/doc/spa/support/loop.h:132
spa_hook_list_init
void spa_hook_list_init(struct spa_hook_list *list)
Initialize a hook list to the empty list.
Definition: hook.h:305
pw_loop::loop
struct spa_loop * loop
wrapped loop
Definition: src/pipewire/loop.h:49
pw_thread_loop_lock
void pw_thread_loop_lock(struct pw_thread_loop *loop)
Lock the mutex associated with loop.
Definition: thread-loop.c:325
pw_thread_loop_new
struct pw_thread_loop * pw_thread_loop_new(const char *name, const struct spa_dict *props)
Create a new PipeWire Threaded Loop Object.
Definition: thread-loop.c:183
spa_hook_list_clean
void spa_hook_list_clean(struct spa_hook_list *list)
Remove all hooks from the list.
Definition: hook.h:344
NAME
#define NAME
Definition: thread-loop.c:34
spa_loop_control_hooks::before
void(* before)(void *data)
Executed right before waiting for events.
Definition: build-12775836/doc/spa/support/loop.h:129