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