core: Make global io_service and scheduler thread-local
Change-Id: I3d6b6cd3ca7a6e53b0dc0f4cae7a2f3270c7fd50
Refs: #2489
diff --git a/core/global-io.cpp b/core/global-io.cpp
index f8d8270..48566f6 100644
--- a/core/global-io.cpp
+++ b/core/global-io.cpp
@@ -1,11 +1,12 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014 Regents of the University of California,
- * Arizona Board of Regents,
- * Colorado State University,
- * University Pierre & Marie Curie, Sorbonne University,
- * Washington University in St. Louis,
- * Beijing Institute of Technology
+ * Copyright (c) 2014-2015, Regents of the University of California,
+ * Arizona Board of Regents,
+ * Colorado State University,
+ * University Pierre & Marie Curie, Sorbonne University,
+ * Washington University in St. Louis,
+ * Beijing Institute of Technology,
+ * The University of Memphis.
*
* This file is part of NFD (Named Data Networking Forwarding Daemon).
* See AUTHORS.md for complete list of NFD authors and contributors.
@@ -20,9 +21,10 @@
*
* You should have received a copy of the GNU General Public License along with
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- **/
+ */
#include "global-io.hpp"
+#include <boost/thread/tss.hpp>
namespace nfd {
@@ -32,13 +34,14 @@
resetGlobalScheduler();
} // namespace scheduler
-static shared_ptr<boost::asio::io_service> g_ioService;
+
+static boost::thread_specific_ptr<boost::asio::io_service> g_ioService;
boost::asio::io_service&
getGlobalIoService()
{
- if (!static_cast<bool>(g_ioService)) {
- g_ioService = make_shared<boost::asio::io_service>();
+ if (g_ioService.get() == nullptr) {
+ g_ioService.reset(new boost::asio::io_service());
}
return *g_ioService;
}