thread/Thread: throw std::system_error on error
This commit is contained in:
parent
fea3f6cc72
commit
d3c7fac606
@ -24,8 +24,6 @@
|
|||||||
#include "thread/Thread.hxx"
|
#include "thread/Thread.hxx"
|
||||||
#include "thread/Name.hxx"
|
#include "thread/Name.hxx"
|
||||||
#include "event/Loop.hxx"
|
#include "event/Loop.hxx"
|
||||||
#include "system/FatalError.hxx"
|
|
||||||
#include "util/Error.hxx"
|
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
@ -75,10 +73,7 @@ io_thread_start()
|
|||||||
assert(!io.thread.IsDefined());
|
assert(!io.thread.IsDefined());
|
||||||
|
|
||||||
const ScopeLock protect(io.mutex);
|
const ScopeLock protect(io.mutex);
|
||||||
|
io.thread.Start(io_thread_func, nullptr);
|
||||||
Error error;
|
|
||||||
if (!io.thread.Start(io_thread_func, nullptr, error))
|
|
||||||
FatalError(error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -27,9 +27,7 @@
|
|||||||
#include "db/plugins/simple/Directory.hxx"
|
#include "db/plugins/simple/Directory.hxx"
|
||||||
#include "storage/CompositeStorage.hxx"
|
#include "storage/CompositeStorage.hxx"
|
||||||
#include "Idle.hxx"
|
#include "Idle.hxx"
|
||||||
#include "util/Error.hxx"
|
|
||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
#include "system/FatalError.hxx"
|
|
||||||
#include "thread/Thread.hxx"
|
#include "thread/Thread.hxx"
|
||||||
#include "thread/Util.hxx"
|
#include "thread/Util.hxx"
|
||||||
|
|
||||||
@ -160,9 +158,7 @@ UpdateService::StartThread(UpdateQueueItem &&i)
|
|||||||
next = std::move(i);
|
next = std::move(i);
|
||||||
walk = new UpdateWalk(GetEventLoop(), listener, *next.storage);
|
walk = new UpdateWalk(GetEventLoop(), listener, *next.storage);
|
||||||
|
|
||||||
Error error;
|
update_thread.Start(Task, this);
|
||||||
if (!update_thread.Start(Task, this, error))
|
|
||||||
FatalError(error);
|
|
||||||
|
|
||||||
FormatDebug(update_domain,
|
FormatDebug(update_domain,
|
||||||
"spawned thread for update job id %i", next.id);
|
"spawned thread for update job id %i", next.id);
|
||||||
|
@ -24,7 +24,6 @@
|
|||||||
#include "DecoderError.hxx"
|
#include "DecoderError.hxx"
|
||||||
#include "DecoderPlugin.hxx"
|
#include "DecoderPlugin.hxx"
|
||||||
#include "DetachedSong.hxx"
|
#include "DetachedSong.hxx"
|
||||||
#include "system/FatalError.hxx"
|
|
||||||
#include "MusicPipe.hxx"
|
#include "MusicPipe.hxx"
|
||||||
#include "fs/Traits.hxx"
|
#include "fs/Traits.hxx"
|
||||||
#include "fs/AllocatedPath.hxx"
|
#include "fs/AllocatedPath.hxx"
|
||||||
@ -520,8 +519,5 @@ decoder_thread_start(DecoderControl &dc)
|
|||||||
assert(!dc.thread.IsDefined());
|
assert(!dc.thread.IsDefined());
|
||||||
|
|
||||||
dc.quit = false;
|
dc.quit = false;
|
||||||
|
dc.thread.Start(decoder_task, &dc);
|
||||||
Error error;
|
|
||||||
if (!dc.thread.Start(decoder_task, &dc, error))
|
|
||||||
FatalError(error);
|
|
||||||
}
|
}
|
||||||
|
@ -44,8 +44,8 @@ ThreadInputStream::~ThreadInputStream()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
InputStream *
|
void
|
||||||
ThreadInputStream::Start(Error &error)
|
ThreadInputStream::Start()
|
||||||
{
|
{
|
||||||
assert(buffer == nullptr);
|
assert(buffer == nullptr);
|
||||||
|
|
||||||
@ -53,11 +53,7 @@ ThreadInputStream::Start(Error &error)
|
|||||||
assert(p != nullptr);
|
assert(p != nullptr);
|
||||||
|
|
||||||
buffer = new CircularBuffer<uint8_t>((uint8_t *)p, buffer_size);
|
buffer = new CircularBuffer<uint8_t>((uint8_t *)p, buffer_size);
|
||||||
|
thread.Start(ThreadFunc, this);
|
||||||
if (!thread.Start(ThreadFunc, this, error))
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
|
@ -78,10 +78,8 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the object and start the thread.
|
* Initialize the object and start the thread.
|
||||||
*
|
|
||||||
* @return false on error
|
|
||||||
*/
|
*/
|
||||||
InputStream *Start(Error &error);
|
void Start();
|
||||||
|
|
||||||
/* virtual methods from InputStream */
|
/* virtual methods from InputStream */
|
||||||
bool Check(Error &error) override final;
|
bool Check(Error &error) override final;
|
||||||
|
@ -73,7 +73,7 @@ MmsInputStream::Open(Error &error)
|
|||||||
static InputStream *
|
static InputStream *
|
||||||
input_mms_open(const char *url,
|
input_mms_open(const char *url,
|
||||||
Mutex &mutex, Cond &cond,
|
Mutex &mutex, Cond &cond,
|
||||||
Error &error)
|
gcc_unused Error &error)
|
||||||
{
|
{
|
||||||
if (!StringStartsWith(url, "mms://") &&
|
if (!StringStartsWith(url, "mms://") &&
|
||||||
!StringStartsWith(url, "mmsh://") &&
|
!StringStartsWith(url, "mmsh://") &&
|
||||||
@ -82,11 +82,8 @@ input_mms_open(const char *url,
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
auto m = new MmsInputStream(url, mutex, cond);
|
auto m = new MmsInputStream(url, mutex, cond);
|
||||||
auto is = m->Start(error);
|
m->Start();
|
||||||
if (is == nullptr)
|
return m;
|
||||||
delete m;
|
|
||||||
|
|
||||||
return is;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
|
@ -83,10 +83,11 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
bool
|
bool
|
||||||
SmbclientNeighborExplorer::Open(Error &error)
|
SmbclientNeighborExplorer::Open(gcc_unused Error &error)
|
||||||
{
|
{
|
||||||
quit = false;
|
quit = false;
|
||||||
return thread.Start(ThreadFunc, this, error);
|
thread.Start(ThreadFunc, this);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -33,7 +33,6 @@
|
|||||||
#include "thread/Util.hxx"
|
#include "thread/Util.hxx"
|
||||||
#include "thread/Slack.hxx"
|
#include "thread/Slack.hxx"
|
||||||
#include "thread/Name.hxx"
|
#include "thread/Name.hxx"
|
||||||
#include "system/FatalError.hxx"
|
|
||||||
#include "util/Error.hxx"
|
#include "util/Error.hxx"
|
||||||
#include "util/ConstBuffer.hxx"
|
#include "util/ConstBuffer.hxx"
|
||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
@ -709,7 +708,5 @@ AudioOutput::StartThread()
|
|||||||
{
|
{
|
||||||
assert(command == Command::NONE);
|
assert(command == Command::NONE);
|
||||||
|
|
||||||
Error error;
|
thread.Start(Task, this);
|
||||||
if (!thread.Start(Task, this, error))
|
|
||||||
FatalError(error);
|
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,6 @@
|
|||||||
#include "MusicBuffer.hxx"
|
#include "MusicBuffer.hxx"
|
||||||
#include "MusicChunk.hxx"
|
#include "MusicChunk.hxx"
|
||||||
#include "DetachedSong.hxx"
|
#include "DetachedSong.hxx"
|
||||||
#include "system/FatalError.hxx"
|
|
||||||
#include "CrossFade.hxx"
|
#include "CrossFade.hxx"
|
||||||
#include "Control.hxx"
|
#include "Control.hxx"
|
||||||
#include "output/MultipleOutputs.hxx"
|
#include "output/MultipleOutputs.hxx"
|
||||||
@ -1235,7 +1234,5 @@ StartPlayerThread(PlayerControl &pc)
|
|||||||
{
|
{
|
||||||
assert(!pc.thread.IsDefined());
|
assert(!pc.thread.IsDefined());
|
||||||
|
|
||||||
Error error;
|
pc.thread.Start(player_task, &pc);
|
||||||
if (!pc.thread.Start(player_task, &pc, error))
|
|
||||||
FatalError(error);
|
|
||||||
}
|
}
|
||||||
|
@ -19,14 +19,14 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "Thread.hxx"
|
#include "Thread.hxx"
|
||||||
#include "util/Error.hxx"
|
#include "system/Error.hxx"
|
||||||
|
|
||||||
#ifdef ANDROID
|
#ifdef ANDROID
|
||||||
#include "java/Global.hxx"
|
#include "java/Global.hxx"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Thread::Start(void (*_f)(void *ctx), void *_ctx, Error &error)
|
Thread::Start(void (*_f)(void *ctx), void *_ctx)
|
||||||
{
|
{
|
||||||
assert(!IsDefined());
|
assert(!IsDefined());
|
||||||
|
|
||||||
@ -35,10 +35,8 @@ Thread::Start(void (*_f)(void *ctx), void *_ctx, Error &error)
|
|||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
handle = ::CreateThread(nullptr, 0, ThreadProc, this, 0, &id);
|
handle = ::CreateThread(nullptr, 0, ThreadProc, this, 0, &id);
|
||||||
if (handle == nullptr) {
|
if (handle == nullptr)
|
||||||
error.SetLastError("Failed to create thread");
|
throw MakeLastError("Failed to create thread");
|
||||||
return false;
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
creating = true;
|
creating = true;
|
||||||
@ -50,8 +48,7 @@ Thread::Start(void (*_f)(void *ctx), void *_ctx, Error &error)
|
|||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
creating = false;
|
creating = false;
|
||||||
#endif
|
#endif
|
||||||
error.SetErrno(e, "Failed to create thread");
|
throw MakeErrno(e, "Failed to create thread");
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
defined = true;
|
defined = true;
|
||||||
|
@ -31,8 +31,6 @@
|
|||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
class Error;
|
|
||||||
|
|
||||||
class Thread {
|
class Thread {
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
HANDLE handle = nullptr;
|
HANDLE handle = nullptr;
|
||||||
@ -91,7 +89,7 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Start(void (*f)(void *ctx), void *ctx, Error &error);
|
bool Start(void (*f)(void *ctx), void *ctx);
|
||||||
void Join();
|
void Join();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user