core: add a facility to execute functions on the RIB io_service

refs #4279

Change-Id: I29222053348e5d1737d47c85a59d29280b4b791b
diff --git a/core/global-io.cpp b/core/global-io.cpp
index 48566f6..bd73244 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-2015,  Regents of the University of California,
+/*
+ * Copyright (c) 2014-2018,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -34,8 +34,8 @@
 resetGlobalScheduler();
 } // namespace scheduler
 
-
 static boost::thread_specific_ptr<boost::asio::io_service> g_ioService;
+static boost::asio::io_service* g_ribIoService = nullptr;
 
 boost::asio::io_service&
 getGlobalIoService()
@@ -53,4 +53,23 @@
   g_ioService.reset();
 }
 
+void
+setRibIoService(boost::asio::io_service* ribIo)
+{
+  g_ribIoService = ribIo;
+}
+
+boost::asio::io_service&
+getRibIoService()
+{
+  BOOST_ASSERT(g_ribIoService != nullptr);
+  return *g_ribIoService;
+}
+
+void
+runOnRibIoService(const std::function<void()>& f)
+{
+  getRibIoService().post(f);
+}
+
 } // namespace nfd
diff --git a/core/global-io.hpp b/core/global-io.hpp
index d5030ab..f9abccf 100644
--- a/core/global-io.hpp
+++ b/core/global-io.hpp
@@ -1,11 +1,11 @@
 /* -*- 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-2018  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
  *
  * This file is part of NFD (Named Data Networking Forwarding Daemon).
  * See AUTHORS.md for complete list of NFD authors and contributors.
@@ -34,7 +34,18 @@
 boost::asio::io_service&
 getGlobalIoService();
 
+void
+setRibIoService(boost::asio::io_service* ribIo);
+
+/** \brief run a function on the RIB io_service instance
+ */
+void
+runOnRibIoService(const std::function<void()>& f);
+
 #ifdef WITH_TESTS
+boost::asio::io_service&
+getRibIoService();
+
 /** \brief delete the global io_service instance
  *
  *  It will be recreated at the next invocation of getGlobalIoService.