1 /*
2  * Copyright 2003-2021 The Music Player Daemon Project
3  * http://www.musicpd.org
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #pragma once
21 
22 #ifdef __GNUC__
23 #pragma GCC diagnostic push
24 /* oh no, libspa likes to cast away "const"! */
25 #pragma GCC diagnostic ignored "-Wcast-qual"
26 /* suppress more annoying warnings */
27 #pragma GCC diagnostic ignored "-Wmissing-field-initializers"
28 #endif
29 
30 #include <pipewire/thread-loop.h>
31 
32 #ifdef __GNUC__
33 #pragma GCC diagnostic pop
34 #endif
35 
36 namespace PipeWire {
37 
38 class ThreadLoopLock {
39 	struct pw_thread_loop *const loop;
40 
41 public:
ThreadLoopLock(struct pw_thread_loop * _loop)42 	explicit ThreadLoopLock(struct pw_thread_loop *_loop) noexcept
43 		:loop(_loop)
44 	{
45 		pw_thread_loop_lock(loop);
46 	}
47 
~ThreadLoopLock()48 	~ThreadLoopLock() noexcept {
49 		pw_thread_loop_unlock(loop);
50 	}
51 
52 	ThreadLoopLock(const ThreadLoopLock &) = delete;
53 	ThreadLoopLock &operator=(const ThreadLoopLock &) = delete;
54 };
55 
56 } // namespace PipeWire
57