diff --git a/orc-rt/include/orc-rt/Service.h b/orc-rt/include/orc-rt/Service.h index 23c3f189ae6a..172ebe96338f 100644 --- a/orc-rt/include/orc-rt/Service.h +++ b/orc-rt/include/orc-rt/Service.h @@ -28,14 +28,22 @@ public: virtual ~Service(); - /// The onDetach method will be called if the controller disconnects from the - /// session without shutting the session down. + /// The onDetach method will be called when the controller disconnects from + /// the session (or if the Session is shut down without a controller ever + /// being attached). /// - /// Since no further requests to the Service will be made, the Service may - /// discard any book-keeping data-structures that are only needed to serve - /// ongoing requests. E.g. a JIT memory manager may discard its free-list, - /// since no further JIT'd allocations will happen. - virtual void onDetach(OnCompleteFn OnComplete) = 0; + /// Once onDetach is called no further requests will be made to the Service + /// by the controller. Note that JIT'd code may continue to make requests to + /// the service concurrent with a call to onDetach. + /// + /// If ShutdownRequested is true then a Session shutdown is already pending, + /// and will proceed after all Services have been notified of the detach. + /// + /// onDetach provides an opportunity for Services to release any resources + /// that are only required while the Session is attached to the controller. + /// It is expected that many Services will implement this operation as a + /// no-op. + virtual void onDetach(OnCompleteFn OnComplete, bool ShutdownRequested) = 0; /// The onShutdown operation will be called at the end of the session. /// diff --git a/orc-rt/include/orc-rt/SimpleNativeMemoryMap.h b/orc-rt/include/orc-rt/SimpleNativeMemoryMap.h index f54ea17420e7..df8b60260e3b 100644 --- a/orc-rt/include/orc-rt/SimpleNativeMemoryMap.h +++ b/orc-rt/include/orc-rt/SimpleNativeMemoryMap.h @@ -110,7 +110,8 @@ public: void deinitializeMultiple(OnDeinitializeCompleteFn &&OnComplete, std::vector Bases); - void onDetach(Service::OnCompleteFn OnComplete) override; + void onDetach(Service::OnCompleteFn OnComplete, + bool ShutdownRequested) override; void onShutdown(Service::OnCompleteFn OnComplete) override; private: diff --git a/orc-rt/lib/executor/SimpleNativeMemoryMap.cpp b/orc-rt/lib/executor/SimpleNativeMemoryMap.cpp index 7bf40367c0d3..c77994e6acb0 100644 --- a/orc-rt/lib/executor/SimpleNativeMemoryMap.cpp +++ b/orc-rt/lib/executor/SimpleNativeMemoryMap.cpp @@ -200,7 +200,8 @@ void SimpleNativeMemoryMap::deinitializeMultiple( Error::success()); } -void SimpleNativeMemoryMap::onDetach(Service::OnCompleteFn OnComplete) { +void SimpleNativeMemoryMap::onDetach(Service::OnCompleteFn OnComplete, + bool ShutdownRequested) { // Detach is a noop for now: we just retain all actions to run at shutdown // time. OnComplete(); diff --git a/orc-rt/unittests/SessionTest.cpp b/orc-rt/unittests/SessionTest.cpp index ce0c77c9af76..323e7d20ec70 100644 --- a/orc-rt/unittests/SessionTest.cpp +++ b/orc-rt/unittests/SessionTest.cpp @@ -40,7 +40,7 @@ public: : DetachOpIdx(DetachOpIdx), ShutdownOpIdx(ShutdownOpIdx), OpIdx(OpIdx), GenResult(std::move(GenResult)) {} - void onDetach(OnCompleteFn OnComplete) override { + void onDetach(OnCompleteFn OnComplete, bool ShutdownRequested) override { DetachOpIdx = OpIdx++; GenResult(Op::Detach); OnComplete(); @@ -63,7 +63,9 @@ class ConfigurableService : public Service { public: ConfigurableService(int ConstructorOption) {} - void onDetach(OnCompleteFn OnComplete) override { OnComplete(); } + void onDetach(OnCompleteFn OnComplete, bool ShutdownRequested) override { + OnComplete(); + } void onShutdown(OnCompleteFn OnComplete) override { OnComplete(); } diff --git a/orc-rt/unittests/SimpleNativeMemoryMapSPSCITest.cpp b/orc-rt/unittests/SimpleNativeMemoryMapSPSCITest.cpp index 7398293fb9e4..f5761e289401 100644 --- a/orc-rt/unittests/SimpleNativeMemoryMapSPSCITest.cpp +++ b/orc-rt/unittests/SimpleNativeMemoryMapSPSCITest.cpp @@ -313,7 +313,7 @@ TEST_F(SimpleNativeMemoryMapSPSCITest, ReserveInitializeDetachShutdown) { EXPECT_EQ(SentinelValue, 0U); std::future DetachResult; - SNMM->onDetach(waitFor(DetachResult)); + SNMM->onDetach(waitFor(DetachResult), /* ShutdownRequested */ false); DetachResult.get(); EXPECT_EQ(SentinelValue, 0); diff --git a/orc-rt/unittests/SimpleNativeMemoryMapTest.cpp b/orc-rt/unittests/SimpleNativeMemoryMapTest.cpp index d42aa0952b25..151237a550f6 100644 --- a/orc-rt/unittests/SimpleNativeMemoryMapTest.cpp +++ b/orc-rt/unittests/SimpleNativeMemoryMapTest.cpp @@ -317,7 +317,7 @@ TEST(SimpleNativeMemoryMapTest, ReserveInitializeDetachShutdown) { EXPECT_EQ(SentinelValue, 0U); std::future DetachResult; - SNMM->onDetach(waitFor(DetachResult)); + SNMM->onDetach(waitFor(DetachResult), /* ShutdownRequested */ false); DetachResult.get(); EXPECT_EQ(SentinelValue, 0);