core+main: switch to std::thread and thread_local

Change-Id: I892eb7d87639c2b0d24a8ed457b9d32635269216
diff --git a/core/global-io.cpp b/core/global-io.cpp
index f03d13c..e906999 100644
--- a/core/global-io.cpp
+++ b/core/global-io.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2018,  Regents of the University of California,
+ * Copyright (c) 2014-2019,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -24,35 +24,35 @@
  */
 
 #include "global-io.hpp"
-#include <boost/thread/tss.hpp>
 
 namespace nfd {
 
-namespace scheduler {
-// defined in scheduler.cpp
-void
-resetGlobalScheduler();
-} // namespace scheduler
-
-static boost::thread_specific_ptr<boost::asio::io_service> g_ioService;
+static thread_local unique_ptr<boost::asio::io_service> g_ioService;
 static boost::asio::io_service* g_mainIoService = nullptr;
 static boost::asio::io_service* g_ribIoService = nullptr;
 
 boost::asio::io_service&
 getGlobalIoService()
 {
-  if (g_ioService.get() == nullptr) {
-    g_ioService.reset(new boost::asio::io_service());
+  if (g_ioService == nullptr) {
+    g_ioService = make_unique<boost::asio::io_service>();
   }
   return *g_ioService;
 }
 
+#ifdef WITH_TESTS
+namespace scheduler {
+void
+resetGlobalScheduler(); // defined in scheduler.cpp
+} // namespace scheduler
+
 void
 resetGlobalIoService()
 {
   scheduler::resetGlobalScheduler();
   g_ioService.reset();
 }
+#endif
 
 void
 setMainIoService(boost::asio::io_service* mainIo)
diff --git a/core/scheduler.cpp b/core/scheduler.cpp
index 094c188..68f7c75 100644
--- a/core/scheduler.cpp
+++ b/core/scheduler.cpp
@@ -26,20 +26,17 @@
 #include "scheduler.hpp"
 #include "global-io.hpp"
 
-#include <boost/thread/tss.hpp>
-
 namespace nfd {
 namespace scheduler {
 
-static boost::thread_specific_ptr<Scheduler> g_scheduler;
+static thread_local unique_ptr<Scheduler> g_scheduler;
 
 Scheduler&
 getGlobalScheduler()
 {
-  if (g_scheduler.get() == nullptr) {
-    g_scheduler.reset(new Scheduler(getGlobalIoService()));
+  if (g_scheduler == nullptr) {
+    g_scheduler = make_unique<Scheduler>(getGlobalIoService());
   }
-
   return *g_scheduler;
 }
 
@@ -49,11 +46,13 @@
   return getGlobalScheduler().scheduleEvent(after, event);
 }
 
+#ifdef WITH_TESTS
 void
 resetGlobalScheduler()
 {
   g_scheduler.reset();
 }
+#endif
 
 } // namespace scheduler
 } // namespace nfd