core: Make global io_service and scheduler thread-local
Change-Id: I3d6b6cd3ca7a6e53b0dc0f4cae7a2f3270c7fd50
Refs: #2489
diff --git a/core/scheduler.cpp b/core/scheduler.cpp
index 0979f97..177045f 100644
--- a/core/scheduler.cpp
+++ b/core/scheduler.cpp
@@ -1,12 +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,
- * The University of Memphis
+ * 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.
@@ -26,17 +26,20 @@
#include "scheduler.hpp"
#include "global-io.hpp"
+#include <boost/thread/tss.hpp>
+
namespace nfd {
namespace scheduler {
-static shared_ptr<Scheduler> g_scheduler;
+static boost::thread_specific_ptr<Scheduler> g_scheduler;
-inline Scheduler&
+Scheduler&
getGlobalScheduler()
{
- if (!static_cast<bool>(g_scheduler)) {
- g_scheduler = make_shared<Scheduler>(ref(getGlobalIoService()));
+ if (g_scheduler.get() == nullptr) {
+ g_scheduler.reset(new Scheduler(getGlobalIoService()));
}
+
return *g_scheduler;
}