adb: make fdevent_test, socket_test compile on Windows.
Switch pthread_* to use the adb_thread_* abstractions to allow the fdevent
and socket tests to compile on Win32.
Bug: http://b/27105824
Change-Id: I6541bb1398780b999837e701837d7f86a5eee8ca
diff --git a/adb/fdevent.cpp b/adb/fdevent.cpp
index 4617364..902548e 100644
--- a/adb/fdevent.cpp
+++ b/adb/fdevent.cpp
@@ -25,6 +25,7 @@
#include <string.h>
#include <unistd.h>
+#include <atomic>
#include <list>
#include <unordered_map>
#include <vector>
@@ -70,6 +71,7 @@
// That's why we don't need a lock for fdevent.
static auto& g_poll_node_map = *new std::unordered_map<int, PollNode>();
static auto& g_pending_list = *new std::list<fdevent*>();
+static std::atomic<bool> terminate_loop(false);
static bool main_thread_valid;
static unsigned long main_thread_id;
@@ -364,6 +366,10 @@
#endif // !ADB_HOST
while (true) {
+ if (terminate_loop) {
+ return;
+ }
+
D("--- --- waiting for events");
fdevent_process();
@@ -376,6 +382,10 @@
}
}
+void fdevent_terminate_loop() {
+ terminate_loop = true;
+}
+
size_t fdevent_installed_count() {
return g_poll_node_map.size();
}
@@ -384,4 +394,5 @@
g_poll_node_map.clear();
g_pending_list.clear();
main_thread_valid = false;
+ terminate_loop = false;
}