Flatten main executable entry points by using functional try blocks
This commit is contained in:
parent
fd84827e51
commit
79650ca3fd
@ -93,22 +93,20 @@ void delete_region(const SharedDataType region)
|
||||
}
|
||||
}
|
||||
|
||||
int main(const int argc, const char *argv[])
|
||||
int main(const int argc, const char *argv[]) try
|
||||
{
|
||||
LogPolicy::GetInstance().Unmute();
|
||||
SharedBarriers barrier;
|
||||
|
||||
try
|
||||
{
|
||||
#ifdef __linux__
|
||||
// try to disable swapping on Linux
|
||||
const bool lock_flags = MCL_CURRENT | MCL_FUTURE;
|
||||
if (-1 == mlockall(lock_flags))
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "Process " << argv[0]
|
||||
<< " could not request RAM lock";
|
||||
SimpleLogger().Write(logWARNING) << "Process " << argv[0] << " could not request RAM lock";
|
||||
}
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
boost::interprocess::scoped_lock<boost::interprocess::named_mutex> pending_lock(
|
||||
@ -119,14 +117,7 @@ int main(const int argc, const char *argv[])
|
||||
// hard unlock in case of any exception.
|
||||
barrier.pending_update_mutex.unlock();
|
||||
}
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "[exception] " << e.what();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
SimpleLogger().Write(logDEBUG) << "Checking input parameters";
|
||||
|
||||
ServerPaths server_paths;
|
||||
@ -227,8 +218,7 @@ int main(const int argc, const char *argv[])
|
||||
}();
|
||||
|
||||
// Allocate a memory layout in shared memory, deallocate previous
|
||||
SharedMemory *layout_memory =
|
||||
SharedMemoryFactory::Get(layout_region, sizeof(SharedDataLayout));
|
||||
SharedMemory *layout_memory = SharedMemoryFactory::Get(layout_region, sizeof(SharedDataLayout));
|
||||
SharedDataLayout *shared_layout_ptr = new (layout_memory->Ptr()) SharedDataLayout();
|
||||
|
||||
shared_layout_ptr->SetBlockSize<char>(SharedDataLayout::FILE_INDEX_PATH,
|
||||
@ -292,15 +282,15 @@ int main(const int argc, const char *argv[])
|
||||
hsgr_input_stream.read((char *)&number_of_graph_nodes, sizeof(unsigned));
|
||||
|
||||
BOOST_ASSERT_MSG((0 != number_of_graph_nodes), "number of nodes is zero");
|
||||
shared_layout_ptr->SetBlockSize<QueryGraph::NodeArrayEntry>(
|
||||
SharedDataLayout::GRAPH_NODE_LIST, number_of_graph_nodes);
|
||||
shared_layout_ptr->SetBlockSize<QueryGraph::NodeArrayEntry>(SharedDataLayout::GRAPH_NODE_LIST,
|
||||
number_of_graph_nodes);
|
||||
|
||||
// load graph edge size
|
||||
unsigned number_of_graph_edges = 0;
|
||||
hsgr_input_stream.read((char *)&number_of_graph_edges, sizeof(unsigned));
|
||||
// BOOST_ASSERT_MSG(0 != number_of_graph_edges, "number of graph edges is zero");
|
||||
shared_layout_ptr->SetBlockSize<QueryGraph::EdgeArrayEntry>(
|
||||
SharedDataLayout::GRAPH_EDGE_LIST, number_of_graph_edges);
|
||||
shared_layout_ptr->SetBlockSize<QueryGraph::EdgeArrayEntry>(SharedDataLayout::GRAPH_EDGE_LIST,
|
||||
number_of_graph_edges);
|
||||
|
||||
// load rsearch tree size
|
||||
boost::filesystem::ifstream tree_node_file(ram_index_path, std::ios::binary);
|
||||
@ -316,8 +306,7 @@ int main(const int argc, const char *argv[])
|
||||
boost::filesystem::ifstream timestamp_stream(timestamp_path);
|
||||
if (!timestamp_stream)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << timestamp_path
|
||||
<< " not found. setting to default";
|
||||
SimpleLogger().Write(logWARNING) << timestamp_path << " not found. setting to default";
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -340,7 +329,8 @@ int main(const int argc, const char *argv[])
|
||||
|
||||
uint32_t number_of_core_markers = 0;
|
||||
core_marker_file.read((char *)&number_of_core_markers, sizeof(uint32_t));
|
||||
shared_layout_ptr->SetBlockSize<unsigned>(SharedDataLayout::CORE_MARKER, number_of_core_markers);
|
||||
shared_layout_ptr->SetBlockSize<unsigned>(SharedDataLayout::CORE_MARKER,
|
||||
number_of_core_markers);
|
||||
|
||||
// load coordinate size
|
||||
boost::filesystem::ifstream nodes_input_stream(nodes_data_path, std::ios::binary);
|
||||
@ -350,22 +340,21 @@ int main(const int argc, const char *argv[])
|
||||
coordinate_list_size);
|
||||
|
||||
// load geometries sizes
|
||||
std::ifstream geometry_input_stream(geometries_data_path.string().c_str(),
|
||||
std::ios::binary);
|
||||
std::ifstream geometry_input_stream(geometries_data_path.string().c_str(), std::ios::binary);
|
||||
unsigned number_of_geometries_indices = 0;
|
||||
unsigned number_of_compressed_geometries = 0;
|
||||
|
||||
geometry_input_stream.read((char *)&number_of_geometries_indices, sizeof(unsigned));
|
||||
shared_layout_ptr->SetBlockSize<unsigned>(SharedDataLayout::GEOMETRIES_INDEX,
|
||||
number_of_geometries_indices);
|
||||
boost::iostreams::seek(geometry_input_stream,
|
||||
number_of_geometries_indices * sizeof(unsigned), BOOST_IOS::cur);
|
||||
boost::iostreams::seek(geometry_input_stream, number_of_geometries_indices * sizeof(unsigned),
|
||||
BOOST_IOS::cur);
|
||||
geometry_input_stream.read((char *)&number_of_compressed_geometries, sizeof(unsigned));
|
||||
shared_layout_ptr->SetBlockSize<unsigned>(SharedDataLayout::GEOMETRIES_LIST,
|
||||
number_of_compressed_geometries);
|
||||
// allocate shared memory block
|
||||
SimpleLogger().Write() << "allocating shared memory of "
|
||||
<< shared_layout_ptr->GetSizeOfLayout() << " bytes";
|
||||
SimpleLogger().Write() << "allocating shared memory of " << shared_layout_ptr->GetSizeOfLayout()
|
||||
<< " bytes";
|
||||
SharedMemory *shared_memory =
|
||||
SharedMemoryFactory::Get(data_region, shared_layout_ptr->GetSizeOfLayout());
|
||||
char *shared_memory_ptr = static_cast<char *>(shared_memory->Ptr());
|
||||
@ -431,8 +420,7 @@ int main(const int argc, const char *argv[])
|
||||
TravelMode *travel_mode_ptr = shared_layout_ptr->GetBlockPtr<TravelMode, true>(
|
||||
shared_memory_ptr, SharedDataLayout::TRAVEL_MODE);
|
||||
|
||||
TurnInstruction *turn_instructions_ptr =
|
||||
shared_layout_ptr->GetBlockPtr<TurnInstruction, true>(
|
||||
TurnInstruction *turn_instructions_ptr = shared_layout_ptr->GetBlockPtr<TurnInstruction, true>(
|
||||
shared_memory_ptr, SharedDataLayout::TURN_INSTRUCTION);
|
||||
|
||||
unsigned *geometries_indicator_ptr = shared_layout_ptr->GetBlockPtr<unsigned, true>(
|
||||
@ -508,13 +496,13 @@ int main(const int argc, const char *argv[])
|
||||
nodes_input_stream.close();
|
||||
|
||||
// store timestamp
|
||||
char *timestamp_ptr = shared_layout_ptr->GetBlockPtr<char, true>(
|
||||
shared_memory_ptr, SharedDataLayout::TIMESTAMP);
|
||||
char *timestamp_ptr =
|
||||
shared_layout_ptr->GetBlockPtr<char, true>(shared_memory_ptr, SharedDataLayout::TIMESTAMP);
|
||||
std::copy(m_timestamp.c_str(), m_timestamp.c_str() + m_timestamp.length(), timestamp_ptr);
|
||||
|
||||
// store search tree portion of rtree
|
||||
char *rtree_ptr = shared_layout_ptr->GetBlockPtr<char, true>(
|
||||
shared_memory_ptr, SharedDataLayout::R_SEARCH_TREE);
|
||||
char *rtree_ptr = shared_layout_ptr->GetBlockPtr<char, true>(shared_memory_ptr,
|
||||
SharedDataLayout::R_SEARCH_TREE);
|
||||
|
||||
if (tree_size > 0)
|
||||
{
|
||||
@ -524,7 +512,8 @@ int main(const int argc, const char *argv[])
|
||||
|
||||
// load core markers
|
||||
std::vector<char> unpacked_core_markers(number_of_core_markers);
|
||||
core_marker_file.read((char *)unpacked_core_markers.data(), sizeof(char)*number_of_core_markers);
|
||||
core_marker_file.read((char *)unpacked_core_markers.data(),
|
||||
sizeof(char) * number_of_core_markers);
|
||||
|
||||
unsigned *core_marker_ptr = shared_layout_ptr->GetBlockPtr<unsigned, true>(
|
||||
shared_memory_ptr, SharedDataLayout::CORE_MARKER);
|
||||
@ -557,8 +546,7 @@ int main(const int argc, const char *argv[])
|
||||
shared_memory_ptr, SharedDataLayout::GRAPH_NODE_LIST);
|
||||
if (shared_layout_ptr->GetBlockSize(SharedDataLayout::GRAPH_NODE_LIST) > 0)
|
||||
{
|
||||
hsgr_input_stream.read(
|
||||
(char *)graph_node_list_ptr,
|
||||
hsgr_input_stream.read((char *)graph_node_list_ptr,
|
||||
shared_layout_ptr->GetBlockSize(SharedDataLayout::GRAPH_NODE_LIST));
|
||||
}
|
||||
|
||||
@ -568,8 +556,7 @@ int main(const int argc, const char *argv[])
|
||||
shared_memory_ptr, SharedDataLayout::GRAPH_EDGE_LIST);
|
||||
if (shared_layout_ptr->GetBlockSize(SharedDataLayout::GRAPH_EDGE_LIST) > 0)
|
||||
{
|
||||
hsgr_input_stream.read(
|
||||
(char *)graph_edge_list_ptr,
|
||||
hsgr_input_stream.read((char *)graph_edge_list_ptr,
|
||||
shared_layout_ptr->GetBlockSize(SharedDataLayout::GRAPH_EDGE_LIST));
|
||||
}
|
||||
hsgr_input_stream.close();
|
||||
@ -597,11 +584,8 @@ int main(const int argc, const char *argv[])
|
||||
SimpleLogger().Write() << "all data loaded";
|
||||
|
||||
shared_layout_ptr->PrintInformation();
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "caught exception: " << e.what();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "caught exception: " << e.what();
|
||||
}
|
||||
|
30
extract.cpp
30
extract.cpp
@ -31,12 +31,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <exception>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[]) try
|
||||
{
|
||||
try
|
||||
{
|
||||
LogPolicy::GetInstance().Unmute();
|
||||
ExtractorConfig extractor_config;
|
||||
|
||||
@ -44,12 +43,12 @@ int main(int argc, char *argv[])
|
||||
|
||||
if (return_code::fail == result)
|
||||
{
|
||||
return 1;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (return_code::exit == result)
|
||||
{
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
ExtractorOptions::GenerateOutputFilesNames(extractor_config);
|
||||
@ -57,27 +56,26 @@ int main(int argc, char *argv[])
|
||||
if (1 > extractor_config.requested_num_threads)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "Number of threads must be 1 or larger";
|
||||
return 1;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (!boost::filesystem::is_regular_file(extractor_config.input_path))
|
||||
{
|
||||
SimpleLogger().Write(logWARNING)
|
||||
<< "Input file " << extractor_config.input_path.string() << " not found!";
|
||||
return 1;
|
||||
SimpleLogger().Write(logWARNING) << "Input file " << extractor_config.input_path.string()
|
||||
<< " not found!";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (!boost::filesystem::is_regular_file(extractor_config.profile_path))
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "Profile " << extractor_config.profile_path.string()
|
||||
<< " not found!";
|
||||
return 1;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return extractor(extractor_config).run();
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "[exception] " << e.what();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "[exception] " << e.what();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
19
prepare.cpp
19
prepare.cpp
@ -33,13 +33,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <tbb/task_scheduler_init.h>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <exception>
|
||||
#include <ostream>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[]) try
|
||||
{
|
||||
try
|
||||
{
|
||||
LogPolicy::GetInstance().Unmute();
|
||||
ContractorConfig contractor_config;
|
||||
|
||||
@ -86,17 +85,17 @@ int main(int argc, char *argv[])
|
||||
return 1;
|
||||
}
|
||||
|
||||
SimpleLogger().Write() << "Input file: " << contractor_config.osrm_input_path.filename().string();
|
||||
SimpleLogger().Write() << "Input file: "
|
||||
<< contractor_config.osrm_input_path.filename().string();
|
||||
SimpleLogger().Write() << "Profile: " << contractor_config.profile_path.filename().string();
|
||||
SimpleLogger().Write() << "Threads: " << contractor_config.requested_num_threads;
|
||||
|
||||
tbb::task_scheduler_init init(contractor_config.requested_num_threads);
|
||||
|
||||
return Prepare(contractor_config).Run();
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "[exception] " << e.what();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "[exception] " << e.what();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user