@@ -49,6 +49,23 @@ namespace cppmicroservices
4949 ComponentManager& operator =(ComponentManager&&) = delete ;
5050 virtual ~ComponentManager () = default ;
5151
52+ /* *
53+ * Waits for the provided future from the asynchronous thread pool and executes
54+ * the task on current thread if the thread pool has stalled.
55+ *
56+ * We determine a likely stall by timeout (50ms) while waiting for the future. After this timeout, we
57+ * atomically compare and set the bool, asyncStarted, to 'take ownership' of execution of this task. If that
58+ * bool was already set, then the spwaned thread has already taken ownership of the task and we do not need
59+ * to execute it again. Otherwise, we execute the task. If we do not hit the timeout, then there was no
60+ * stall and we can get() the future.
61+ *
62+ * \param fut The future to wait on
63+ * \param asyncStarted The bool used to synchronize the waiting and posted thread
64+ * \return void, once the future has been satisfied
65+ */
66+ virtual void WaitForFuture (std::shared_future<void >& fut, std::shared_ptr<std::atomic<bool >> asyncStarted)
67+ = 0;
68+
5269 /* *
5370 * Returns the name of the component managed by this object. The name is the same
5471 * as specified in the component description.
@@ -69,15 +86,33 @@ namespace cppmicroservices
6986 * This method changes the state of the ComponentManager to ENABLED. The method returns
7087 * immediately after changing the state. Any configurations created as a result of the
7188 * state change will happen asynchronously on a separate thread.
89+ *
90+ * \param asyncStarted The bool used to synchronize the waiting and posted thread
91+ * \parblock
92+ * If returned future IS blocked on: create asyncStarted value and pass in on calling thread.
93+ * Once the future is returned, call WaitForFuture() with the returned future and your asyncStarted value
94+ *
95+ * If future IS NOT blocked on: call Enable(), or explicitly Enable(nullptr), no other action is required
96+ * \endparblock
97+ * \return std::shared_future<void> assosciated with the state change
7298 */
73- virtual std::shared_future<void > Enable () = 0;
99+ virtual std::shared_future<void > Enable (std::shared_ptr<std::atomic< bool >> asyncStarted = nullptr ) = 0;
74100
75101 /* *
76102 * This method changes the state of the ComponentManager to DISABLED. The method returns
77103 * immediately after changing the state. Any configurations deleted as a result of the
78- * state change will happen asynchronously on a separate thread.
104+ * state change will happen asynchronously on a separate thread.
105+ *
106+ * \param asyncStarted The bool used to synchronize the waiting and posted thread
107+ * \parblock
108+ * If future IS blocked on: create asyncStarted value and pass in on calling thread.
109+ * Once the future is returned, call WaitForFuture() with the returned future and your asyncStarted value
110+ *
111+ * If future IS NOT blocked on: call Disable(), or explicitly Disable(nullptr), no other action is required
112+ * \endparblock
113+ * \return std::shared_future<void> assosciated with the state change
79114 */
80- virtual std::shared_future<void > Disable () = 0;
115+ virtual std::shared_future<void > Disable (std::shared_ptr<std::atomic< bool >> asyncStarted = nullptr ) = 0;
81116
82117 /* *
83118 * Returns a vector of ComponentConfiguration objects representing each of the configurations
@@ -89,7 +124,7 @@ namespace cppmicroservices
89124 * Returns the metadata object representing the component description for the
90125 * component managed by this object.
91126 */
92- virtual std::shared_ptr<const metadata::ComponentMetadata> GetMetadata () const = 0;
127+ virtual std::shared_ptr<metadata::ComponentMetadata const > GetMetadata () const = 0;
93128 };
94129 } // namespace scrimpl
95130} // namespace cppmicroservices
0 commit comments