thread/Thread: throw std::system_error on error

This commit is contained in:
Max Kellermann
2016-06-17 19:06:30 +02:00
parent fea3f6cc72
commit d3c7fac606
11 changed files with 21 additions and 53 deletions

View File

@@ -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;

View File

@@ -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: