input/Open: move code to WaitReady()
This commit is contained in:
parent
5dd07ac040
commit
1f47fe47c7
@ -5,8 +5,8 @@
|
|||||||
#include "Registry.hxx"
|
#include "Registry.hxx"
|
||||||
#include "InputPlugin.hxx"
|
#include "InputPlugin.hxx"
|
||||||
#include "LocalOpen.hxx"
|
#include "LocalOpen.hxx"
|
||||||
#include "CondHandler.hxx"
|
|
||||||
#include "RewindInputStream.hxx"
|
#include "RewindInputStream.hxx"
|
||||||
|
#include "WaitReady.hxx"
|
||||||
#include "fs/Traits.hxx"
|
#include "fs/Traits.hxx"
|
||||||
#include "fs/AllocatedPath.hxx"
|
#include "fs/AllocatedPath.hxx"
|
||||||
|
|
||||||
@ -35,22 +35,7 @@ InputStream::Open(const char *url, Mutex &mutex)
|
|||||||
InputStreamPtr
|
InputStreamPtr
|
||||||
InputStream::OpenReady(const char *uri, Mutex &mutex)
|
InputStream::OpenReady(const char *uri, Mutex &mutex)
|
||||||
{
|
{
|
||||||
CondInputStreamHandler handler;
|
|
||||||
|
|
||||||
auto is = Open(uri, mutex);
|
auto is = Open(uri, mutex);
|
||||||
is->SetHandler(&handler);
|
LockWaitReady(*is);
|
||||||
|
|
||||||
{
|
|
||||||
std::unique_lock<Mutex> lock(mutex);
|
|
||||||
|
|
||||||
handler.cond.wait(lock, [&is]{
|
|
||||||
is->Update();
|
|
||||||
return is->IsReady();
|
|
||||||
});
|
|
||||||
|
|
||||||
is->Check();
|
|
||||||
}
|
|
||||||
|
|
||||||
is->SetHandler(nullptr);
|
|
||||||
return is;
|
return is;
|
||||||
}
|
}
|
||||||
|
27
src/input/WaitReady.cxx
Normal file
27
src/input/WaitReady.cxx
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
// Copyright The Music Player Daemon Project
|
||||||
|
|
||||||
|
#include "WaitReady.hxx"
|
||||||
|
#include "InputStream.hxx"
|
||||||
|
#include "CondHandler.hxx"
|
||||||
|
|
||||||
|
void
|
||||||
|
WaitReady(InputStream &is, std::unique_lock<Mutex> &lock)
|
||||||
|
{
|
||||||
|
CondInputStreamHandler handler;
|
||||||
|
const ScopeExchangeInputStreamHandler h{is, &handler};
|
||||||
|
|
||||||
|
handler.cond.wait(lock, [&is]{
|
||||||
|
is.Update();
|
||||||
|
return is.IsReady();
|
||||||
|
});
|
||||||
|
|
||||||
|
is.Check();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
LockWaitReady(InputStream &is)
|
||||||
|
{
|
||||||
|
std::unique_lock lock{is.mutex};
|
||||||
|
WaitReady(is, lock);
|
||||||
|
}
|
14
src/input/WaitReady.hxx
Normal file
14
src/input/WaitReady.hxx
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
// Copyright The Music Player Daemon Project
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "thread/Mutex.hxx"
|
||||||
|
|
||||||
|
class InputStream;
|
||||||
|
|
||||||
|
void
|
||||||
|
WaitReady(InputStream &is, std::unique_lock<Mutex> &lock);
|
||||||
|
|
||||||
|
void
|
||||||
|
LockWaitReady(InputStream &is);
|
@ -28,6 +28,7 @@ input_glue = static_library(
|
|||||||
'input_glue',
|
'input_glue',
|
||||||
'Init.cxx',
|
'Init.cxx',
|
||||||
'Registry.cxx',
|
'Registry.cxx',
|
||||||
|
'WaitReady.cxx',
|
||||||
'Open.cxx',
|
'Open.cxx',
|
||||||
'LocalOpen.cxx',
|
'LocalOpen.cxx',
|
||||||
'ScanTags.cxx',
|
'ScanTags.cxx',
|
||||||
|
Loading…
Reference in New Issue
Block a user