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

Change-Id: I38e5f4ad5ed6798a14e0075fb7a14b792f8b2413
refs: #4683
diff --git a/core/global-io.cpp b/core/global-io.cpp
index bd73244..f03d13c 100644
--- a/core/global-io.cpp
+++ b/core/global-io.cpp
@@ -35,6 +35,7 @@
 } // namespace scheduler
 
 static boost::thread_specific_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&
@@ -54,12 +55,25 @@
 }
 
 void
+setMainIoService(boost::asio::io_service* mainIo)
+{
+  g_mainIoService = mainIo;
+}
+
+void
 setRibIoService(boost::asio::io_service* ribIo)
 {
   g_ribIoService = ribIo;
 }
 
 boost::asio::io_service&
+getMainIoService()
+{
+  BOOST_ASSERT(g_mainIoService != nullptr);
+  return *g_mainIoService;
+}
+
+boost::asio::io_service&
 getRibIoService()
 {
   BOOST_ASSERT(g_ribIoService != nullptr);
@@ -67,6 +81,12 @@
 }
 
 void
+runOnMainIoService(const std::function<void()>& f)
+{
+  getMainIoService().post(f);
+}
+
+void
 runOnRibIoService(const std::function<void()>& f)
 {
   getRibIoService().post(f);