aboutsummaryrefslogtreecommitdiffstats
path: root/src/IOThread.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-10-17 18:42:14 +0200
committerMax Kellermann <max@duempel.org>2013-10-17 19:29:47 +0200
commit8e676db633aa8888c8408a91ef219d2261ef42e2 (patch)
tree9e61e37ab5d181e90e89c5d4ced99c3434b3976c /src/IOThread.cxx
parentf6d74012b7a583bddf2e3b824193ade91fe09ce7 (diff)
downloadmpd-8e676db633aa8888c8408a91ef219d2261ef42e2.tar.gz
mpd-8e676db633aa8888c8408a91ef219d2261ef42e2.tar.xz
mpd-8e676db633aa8888c8408a91ef219d2261ef42e2.zip
Thread/Thread: replacement library for GThread
Diffstat (limited to 'src/IOThread.cxx')
-rw-r--r--src/IOThread.cxx31
1 files changed, 12 insertions, 19 deletions
diff --git a/src/IOThread.cxx b/src/IOThread.cxx
index dbe206af7..d8805ba7b 100644
--- a/src/IOThread.cxx
+++ b/src/IOThread.cxx
@@ -21,10 +21,10 @@
#include "IOThread.hxx"
#include "thread/Mutex.hxx"
#include "thread/Cond.hxx"
+#include "thread/Thread.hxx"
#include "event/Loop.hxx"
#include "system/FatalError.hxx"
-
-#include <glib.h>
+#include "util/Error.hxx"
#include <assert.h>
@@ -33,7 +33,7 @@ static struct {
Cond cond;
EventLoop *loop;
- GThread *thread;
+ Thread thread;
} io;
void
@@ -45,8 +45,8 @@ io_thread_run(void)
io.loop->Run();
}
-static gpointer
-io_thread_func(gcc_unused gpointer arg)
+static void
+io_thread_func(gcc_unused void *arg)
{
/* lock+unlock to synchronize with io_thread_start(), to be
sure that io.thread is set */
@@ -54,14 +54,13 @@ io_thread_func(gcc_unused gpointer arg)
io.mutex.unlock();
io_thread_run();
- return NULL;
}
void
io_thread_init(void)
{
assert(io.loop == NULL);
- assert(io.thread == NULL);
+ assert(!io.thread.IsDefined());
io.loop = new EventLoop();
}
@@ -70,18 +69,13 @@ void
io_thread_start()
{
assert(io.loop != NULL);
- assert(io.thread == NULL);
+ assert(!io.thread.IsDefined());
const ScopeLock protect(io.mutex);
-#if GLIB_CHECK_VERSION(2,32,0)
- io.thread = g_thread_new("io", io_thread_func, nullptr);
-#else
- GError *error = nullptr;
- io.thread = g_thread_create(io_thread_func, NULL, true, &error);
- if (io.thread == NULL)
+ Error error;
+ if (!io.thread.Start(io_thread_func, nullptr, error))
FatalError(error);
-#endif
}
void
@@ -95,10 +89,9 @@ io_thread_quit(void)
void
io_thread_deinit(void)
{
- if (io.thread != NULL) {
+ if (io.thread.IsDefined()) {
io_thread_quit();
-
- g_thread_join(io.thread);
+ io.thread.Join();
}
delete io.loop;
@@ -115,5 +108,5 @@ io_thread_get()
bool
io_thread_inside(void)
{
- return io.thread != NULL && g_thread_self() == io.thread;
+ return io.thread.IsInside();
}