summaryrefslogtreecommitdiff
path: root/src/thread
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2017-02-10 22:41:11 +0100
committerMax Kellermann <max@musicpd.org>2018-01-07 17:20:26 +0100
commit8649ea3d6fcbad110ecb668b8485cf4b8b45caba (patch)
tree0ad6948c8f77286aea01d524a2ca16220983139b /src/thread
parent752ff12c37741d7b2bc52619529dabb59e91a998 (diff)
thread/Thread: use BoundMethod
Diffstat (limited to 'src/thread')
-rw-r--r--src/thread/Thread.cxx11
-rw-r--r--src/thread/Thread.hxx11
2 files changed, 9 insertions, 13 deletions
diff --git a/src/thread/Thread.cxx b/src/thread/Thread.cxx
index 16d68dc23..8d8a429d0 100644
--- a/src/thread/Thread.cxx
+++ b/src/thread/Thread.cxx
@@ -25,14 +25,11 @@
#include "java/Global.hxx"
#endif
-bool
-Thread::Start(void (*_f)(void *ctx), void *_ctx)
+void
+Thread::Start()
{
assert(!IsDefined());
- f = _f;
- ctx = _ctx;
-
#ifdef _WIN32
handle = ::CreateThread(nullptr, 0, ThreadProc, this, 0, &id);
if (handle == nullptr)
@@ -56,8 +53,6 @@ Thread::Start(void (*_f)(void *ctx), void *_ctx)
creating = false;
#endif
#endif
-
- return true;
}
void
@@ -89,7 +84,7 @@ Thread::Run()
#endif
#endif
- f(ctx);
+ f();
#ifdef ANDROID
Java::DetachCurrentThread();
diff --git a/src/thread/Thread.hxx b/src/thread/Thread.hxx
index 9a58614a7..63f34f8e7 100644
--- a/src/thread/Thread.hxx
+++ b/src/thread/Thread.hxx
@@ -21,6 +21,7 @@
#define MPD_THREAD_HXX
#include "check.h"
+#include "util/BindMethod.hxx"
#include "Compiler.h"
#ifdef _WIN32
@@ -32,6 +33,9 @@
#include <assert.h>
class Thread {
+ typedef BoundMethod<void()> Function;
+ const Function f;
+
#ifdef _WIN32
HANDLE handle = nullptr;
DWORD id;
@@ -49,11 +53,8 @@ class Thread {
#endif
#endif
- void (*f)(void *ctx);
- void *ctx;
-
public:
- Thread() = default;
+ explicit Thread(Function _f):f(_f) {}
Thread(const Thread &) = delete;
@@ -89,7 +90,7 @@ public:
#endif
}
- bool Start(void (*f)(void *ctx), void *ctx);
+ void Start();
void Join();
private: