2
* Copyright (C) 2003-2013 The Music Player Daemon Project
3
* http://www.musicpd.org
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.
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.
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.
23
#include "DeferredMonitor.hxx"
24
#include "thread/Mutex.hxx"
25
#include "thread/Cond.hxx"
30
class BlockingCallMonitor final
35
const std::function<void()> f;
44
BlockingCallMonitor(EventLoop &loop, std::function<void()> &&_f)
45
:f(std::move(_f)), done(false) {
46
loop.AddCall([this](){
51
BlockingCallMonitor(EventLoop &_loop, std::function<void()> &&_f)
52
:DeferredMonitor(_loop), f(std::move(_f)), done(false) {}
70
virtual void RunDeferred() override {
90
BlockingCall(EventLoop &loop, std::function<void()> &&f)
92
if (loop.IsInside()) {
93
/* we're already inside the loop - we can simply call
97
/* outside the EventLoop's thread - defer execution to
98
the EventLoop, wait for completion */
99
BlockingCallMonitor m(loop, std::move(f));