Tidy up threading handling of Windows versus non-Windows.
Fixes #53.
Change-Id: I102273a99618a4619a1e726f3c76c3880be869bc
Reviewed-on: https://code-review.googlesource.com/3499
Reviewed-by: Paul Wankadia <junyer@google.com>
diff --git a/util/thread.cc b/util/thread.cc
index 7349991..b620105 100644
--- a/util/thread.cc
+++ b/util/thread.cc
@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-#include <pthread.h>
-
#include "util/util.h"
#include "util/thread.h"
diff --git a/util/thread.h b/util/thread.h
index b9610e0..fb67bdc 100644
--- a/util/thread.h
+++ b/util/thread.h
@@ -5,7 +5,11 @@
#ifndef RE2_UTIL_THREAD_H__
#define RE2_UTIL_THREAD_H__
+#ifdef _WIN32
+#include <windows.h>
+#else
#include <pthread.h>
+#endif
class Thread {
public:
@@ -15,12 +19,15 @@
void Join();
void SetJoinable(bool);
virtual void Run() = 0;
-
+
private:
+#ifdef _WIN32
+ HANDLE pid_;
+#else
pthread_t pid_;
+#endif
bool running_;
bool joinable_;
};
#endif // RE2_UTIL_THREAD_H__
-
diff --git a/util/threadwin.cc b/util/threadwin.cc
index f1e456e..7b431ee 100644
--- a/util/threadwin.cc
+++ b/util/threadwin.cc
@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-#include <windows.h>
-
#include "util/util.h"
#include "util/thread.h"
@@ -26,8 +24,7 @@
CHECK(!running_);
pid_ = CreateThread(NULL, 0, startThread, this, 0, NULL);
running_ = true;
- if (!joinable_)
- {
+ if (!joinable_) {
CloseHandle(pid_);
pid_ = 0;
}
@@ -36,10 +33,8 @@
void Thread::Join() {
CHECK(running_);
CHECK(joinable_);
- if (0 != pid_)
- {
- WaitForSingleObject(pid_, INFINITE);
- }
+ if (pid_ != 0)
+ WaitForSingleObject(pid_, INFINITE);
running_ = 0;
}