Make watchdog a singleton instance
References: https://github.com/Project-OSRM/osrm-backend/issues/3619 https://github.com/Project-OSRM/osrm-backend/pull/3627#issuecomment-276288138
This commit is contained in:
		
							parent
							
								
									c22ce3ae1f
								
							
						
					
					
						commit
						b3ef27d104
					
				| @ -49,8 +49,6 @@ class Engine final | ||||
|     Status Tile(const api::TileParameters ¶meters, std::string &result) const; | ||||
| 
 | ||||
|   private: | ||||
|     std::unique_ptr<DataWatchdog> watchdog; | ||||
| 
 | ||||
|     const plugins::ViaRoutePlugin route_plugin; | ||||
|     const plugins::TablePlugin table_plugin; | ||||
|     const plugins::NearestPlugin nearest_plugin; | ||||
|  | ||||
| @ -18,27 +18,28 @@ | ||||
| 
 | ||||
| namespace | ||||
| { | ||||
| 
 | ||||
| auto GetWatchdogDataFacade() | ||||
| { | ||||
|     static osrm::engine::DataWatchdog watchdog; | ||||
|     return watchdog.GetDataFacade(); | ||||
| } | ||||
| 
 | ||||
| // Abstracted away the query locking into a template function
 | ||||
| // Works the same for every plugin.
 | ||||
| template <typename ParameterT, typename PluginT, typename ResultT> | ||||
| osrm::engine::Status | ||||
| RunQuery(const std::unique_ptr<osrm::engine::DataWatchdog> &watchdog, | ||||
|          const std::shared_ptr<const osrm::engine::datafacade::BaseDataFacade> &immutable_facade, | ||||
| RunQuery(const std::shared_ptr<const osrm::engine::datafacade::BaseDataFacade> &immutable_facade, | ||||
|          const ParameterT ¶meters, | ||||
|          PluginT &plugin, | ||||
|          ResultT &result) | ||||
| { | ||||
|     if (watchdog) | ||||
|     if (immutable_facade) | ||||
|     { | ||||
|         BOOST_ASSERT(!immutable_facade); | ||||
|         auto facade = watchdog->GetDataFacade(); | ||||
| 
 | ||||
|         return plugin.HandleRequest(facade, parameters, result); | ||||
|         return plugin.HandleRequest(immutable_facade, parameters, result); | ||||
|     } | ||||
| 
 | ||||
|     BOOST_ASSERT(immutable_facade); | ||||
| 
 | ||||
|     return plugin.HandleRequest(immutable_facade, parameters, result); | ||||
|     return plugin.HandleRequest(GetWatchdogDataFacade(), parameters, result); | ||||
| } | ||||
| 
 | ||||
| } // anon. ns
 | ||||
| @ -57,12 +58,7 @@ Engine::Engine(const EngineConfig &config) | ||||
|       tile_plugin()                                      //
 | ||||
| 
 | ||||
| { | ||||
|     if (config.use_shared_memory) | ||||
|     { | ||||
|         watchdog = std::make_unique<DataWatchdog>(); | ||||
|         BOOST_ASSERT(watchdog); | ||||
|     } | ||||
|     else | ||||
|     if (!config.use_shared_memory) | ||||
|     { | ||||
|         if (!config.storage_config.IsValid()) | ||||
|         { | ||||
| @ -78,32 +74,32 @@ Engine::Engine(const EngineConfig &config) | ||||
| 
 | ||||
| Status Engine::Route(const api::RouteParameters ¶ms, util::json::Object &result) const | ||||
| { | ||||
|     return RunQuery(watchdog, immutable_data_facade, params, route_plugin, result); | ||||
|     return RunQuery(immutable_data_facade, params, route_plugin, result); | ||||
| } | ||||
| 
 | ||||
| Status Engine::Table(const api::TableParameters ¶ms, util::json::Object &result) const | ||||
| { | ||||
|     return RunQuery(watchdog, immutable_data_facade, params, table_plugin, result); | ||||
|     return RunQuery(immutable_data_facade, params, table_plugin, result); | ||||
| } | ||||
| 
 | ||||
| Status Engine::Nearest(const api::NearestParameters ¶ms, util::json::Object &result) const | ||||
| { | ||||
|     return RunQuery(watchdog, immutable_data_facade, params, nearest_plugin, result); | ||||
|     return RunQuery(immutable_data_facade, params, nearest_plugin, result); | ||||
| } | ||||
| 
 | ||||
| Status Engine::Trip(const api::TripParameters ¶ms, util::json::Object &result) const | ||||
| { | ||||
|     return RunQuery(watchdog, immutable_data_facade, params, trip_plugin, result); | ||||
|     return RunQuery(immutable_data_facade, params, trip_plugin, result); | ||||
| } | ||||
| 
 | ||||
| Status Engine::Match(const api::MatchParameters ¶ms, util::json::Object &result) const | ||||
| { | ||||
|     return RunQuery(watchdog, immutable_data_facade, params, match_plugin, result); | ||||
|     return RunQuery(immutable_data_facade, params, match_plugin, result); | ||||
| } | ||||
| 
 | ||||
| Status Engine::Tile(const api::TileParameters ¶ms, std::string &result) const | ||||
| { | ||||
|     return RunQuery(watchdog, immutable_data_facade, params, tile_plugin, result); | ||||
|     return RunQuery(immutable_data_facade, params, tile_plugin, result); | ||||
| } | ||||
| 
 | ||||
| } // engine ns
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user