Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop win rebased #880

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Algorithms/DouglasPeucker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

*/

#include <boost/math/special_functions/fpclassify.hpp>
#include "DouglasPeucker.h"
#include "../DataStructures/SegmentInformation.h"
#include "../Util/MercatorUtil.h"
Expand Down Expand Up @@ -86,15 +87,15 @@ double DouglasPeucker::ComputeDistance(
}

double r = (p - nY*a)/c;
if( std::isnan(r) ) {
if( boost::math::isnan(r) ) {
r = ((segB.lat == point.lat) && (segB.lon == point.lon)) ? 1. : 0.;
} else if( std::abs(r) <= std::numeric_limits<double>::epsilon() ) {
r = 0.;
} else if( std::abs(r-1.) <= std::numeric_limits<double>::epsilon() ) {
r = 1.;
}
FixedPointCoordinate nearest_location;
BOOST_ASSERT( !std::isnan(r) );
BOOST_ASSERT( !boost::math::isnan(r) );
if( r <= 0. ){
nearest_location.lat = segA.lat;
nearest_location.lon = segA.lon;
Expand Down
7 changes: 7 additions & 0 deletions Algorithms/IteratorBasedCRC32.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class IteratorbasedCRC32 {
CRC32_Processor.process_bytes( str, len);
return CRC32_Processor.checksum();
}
#ifndef _MSC_VER
unsigned SSEBasedCRC32( char *str, unsigned len, unsigned crc){
unsigned q=len/sizeof(unsigned),
r=len%sizeof(unsigned),
Expand Down Expand Up @@ -82,8 +83,13 @@ class IteratorbasedCRC32 {
asm("cpuid" : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx) : "a" (functionInput));
return ecx;
}
#endif

CRC32CFunctionPtr detectBestCRC32C(){
#ifdef _MSC_VER
SimpleLogger().Write() << "Microsfot compiler -> using software based CRC32 computation";
return &IteratorbasedCRC32::SoftwareBasedCRC32; //crc32cSlicingBy8;
#else
static const int SSE42_BIT = 20;
unsigned ecx = cpuid(1);
bool hasSSE42 = ecx & (1 << SSE42_BIT);
Expand All @@ -94,6 +100,7 @@ class IteratorbasedCRC32 {
SimpleLogger().Write() << "using software based CRC32 computation";
return &IteratorbasedCRC32::SoftwareBasedCRC32; //crc32cSlicingBy8;
}
#endif
}
CRC32CFunctionPtr crcFunction;
public:
Expand Down
15 changes: 12 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
include(GetGitRevisionDescription)
git_describe(GIT_DESCRIPTION)

OPTION(WITH_TOOLS "Build ORSM tools" ON)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

set(bitness 32)
Expand All @@ -30,7 +31,11 @@ add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/Util/UUID.cpp UUID.cpp.alwaysbuild

add_custom_target(UUIDConfigure DEPENDS ${CMAKE_SOURCE_DIR}/Util/UUID.cpp)

set(BOOST_COMPONENTS filesystem iostreams program_options regex system thread)
if(WIN32)
set(MORE_BOOST_LIBS date_time chrono zlib)
message(STATUS "Windows build, some more boost libraries are used")
endif()
set(BOOST_COMPONENTS filesystem iostreams program_options regex system thread ${MORE_BOOST_LIBS})

configure_file(
${CMAKE_SOURCE_DIR}/Util/GitDescription.cpp.in
Expand Down Expand Up @@ -101,6 +106,8 @@ elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-intel -wd10237 -Wall -openmp -ipo -fPIC")
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
# using Visual Studio C++
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_definitions(-DNOMINMAX) # avoid min and max macros that can break compilation
endif()

# Configuring other platform dependencies
Expand Down Expand Up @@ -204,8 +211,10 @@ if(WITH_TOOLS)
endif()
add_executable(osrm-cli Tools/simpleclient.cpp)
target_link_libraries(osrm-cli ${Boost_LIBRARIES} OSRM UUID GITDESCRIPTION)
add_executable(osrm-io-benchmark Tools/io-benchmark.cpp)
target_link_libraries(osrm-io-benchmark ${Boost_LIBRARIES} GITDESCRIPTION)
if(NOT WIN32)
add_executable(osrm-io-benchmark Tools/io-benchmark.cpp)
target_link_libraries(osrm-io-benchmark ${Boost_LIBRARIES} GITDESCRIPTION)
endif()
add_executable(osrm-unlock-all Tools/unlock_all_mutexes.cpp)
target_link_libraries(osrm-unlock-all ${Boost_LIBRARIES} GITDESCRIPTION)
if(UNIX AND NOT APPLE)
Expand Down
5 changes: 3 additions & 2 deletions DataStructures/EdgeBasedNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <cmath>

#include <boost/assert.hpp>
#include <boost/math/special_functions/fpclassify.hpp>

#include "../Util/MercatorUtil.h"
#include "../Util/SimpleLogger.h"
Expand Down Expand Up @@ -63,14 +64,14 @@ struct EdgeBasedNode {
r = (p - nY*a)/c;// These values are actually n/m+n and m/m+n , we need
// not calculate the explicit values of m an n as we
// are just interested in the ratio
if( std::isnan(r) ) {
if( boost::math::isnan(r) ) {
r = ((lat2 == query_location.lat) && (lon2 == query_location.lon)) ? 1. : 0.;
} else if( std::abs(r) <= std::numeric_limits<double>::epsilon() ) {
r = 0.;
} else if( std::abs(r-1.) <= std::numeric_limits<double>::epsilon() ) {
r = 1.;
}
BOOST_ASSERT( !std::isnan(r) );
BOOST_ASSERT( !boost::math::isnan(r) );
if( r <= 0. ){
nearest_location.lat = lat1;
nearest_location.lon = lon1;
Expand Down
7 changes: 7 additions & 0 deletions DataStructures/SearchEngineData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,10 @@ void SearchEngineData::InitializeOrClearThirdThreadLocalStorage(const unsigned n
backwardHeap3->Clear();
}
}

SearchEngineData::SearchEngineHeapPtr SearchEngineData::forwardHeap;
SearchEngineData::SearchEngineHeapPtr SearchEngineData::backwardHeap;
SearchEngineData::SearchEngineHeapPtr SearchEngineData::forwardHeap2;
SearchEngineData::SearchEngineHeapPtr SearchEngineData::backwardHeap2;
SearchEngineData::SearchEngineHeapPtr SearchEngineData::forwardHeap3;
SearchEngineData::SearchEngineHeapPtr SearchEngineData::backwardHeap3;
147 changes: 147 additions & 0 deletions DataStructures/SharedMemoryFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <boost/filesystem/fstream.hpp>
#include <boost/integer.hpp>
#include <boost/interprocess/mapped_region.hpp>
#ifndef WIN32
#include <boost/interprocess/xsi_shared_memory.hpp>
#else
#include <boost/interprocess/shared_memory_object.hpp>
#endif

#ifdef __linux__
#include <sys/ipc.h>
Expand All @@ -57,6 +61,7 @@ struct OSRMLockFile {
}
};

#ifndef WIN32
class SharedMemory : boost::noncopyable {

//Remove shared memory on destruction
Expand Down Expand Up @@ -204,6 +209,148 @@ class SharedMemory : boost::noncopyable {
boost::interprocess::mapped_region region;
shm_remove remover;
};
#else
// Windows - specific code
class SharedMemory : boost::noncopyable {

//Remove shared memory on destruction
class shm_remove : boost::noncopyable {
private:
char* m_shmid;
bool m_initialized;
public:
void SetID(char* shmid) {
m_shmid = shmid;
m_initialized = true;
}

shm_remove() : m_shmid("undefined"), m_initialized(false) {}

~shm_remove(){
if(m_initialized) {
SimpleLogger().Write(logDEBUG) <<
"automatic memory deallocation";
if(!boost::interprocess::shared_memory_object::remove(m_shmid)) {
SimpleLogger().Write(logDEBUG) << "could not deallocate id " << m_shmid;
}
}
}
};

public:
void * Ptr() const {
return region.get_address();
}

SharedMemory(
const boost::filesystem::path & lock_file,
const int id,
const uint64_t size = 0,
bool read_write = false,
bool remove_prev = true
) {
sprintf(key,"%s.%d","osrm.lock", id);
if( 0 == size ){ //read_only
shm = boost::interprocess::shared_memory_object(
boost::interprocess::open_only,
key,
read_write ?
boost::interprocess::read_write :
boost::interprocess::read_only
);
region = boost::interprocess::mapped_region (
shm,
(
read_write ?
boost::interprocess::read_write :
boost::interprocess::read_only
)
);
} else { //writeable pointer
//remove previously allocated mem
if( remove_prev ) {
Remove(key);
}
shm = boost::interprocess::shared_memory_object (
boost::interprocess::open_or_create,
key,
boost::interprocess::read_write
);
shm.truncate(size);
region = boost::interprocess::mapped_region (
shm,
boost::interprocess::read_write
);

remover.SetID( key );
SimpleLogger().Write(logDEBUG) <<
"writeable memory allocated " << size << " bytes";
}
}

static bool RegionExists(
const int id
) {
bool result = true;
try {
char k[500];
build_key(id, k);
result = RegionExists(k);
} catch(...) {
result = false;
}
return result;
}

static bool Remove(
const int id
) {
char k[500];
build_key(id, k);
return Remove(k);
}

private:
static void build_key(int id, char* key) {
OSRMLockFile lock_file;
sprintf(key,"%s.%d","osrm.lock", id);
}
static bool RegionExists( const char* key ) {
bool result = true;
try {

boost::interprocess::shared_memory_object shm(
boost::interprocess::open_only,
key,
boost::interprocess::read_write
);
} catch(...) {
result = false;
}
return result;
}

static bool Remove(
char* key
) {
bool ret = false;
try{
SimpleLogger().Write(logDEBUG) << "deallocating prev memory";
ret = boost::interprocess::shared_memory_object::remove(key);
} catch(const boost::interprocess::interprocess_exception &e){
if(e.get_error_code() != boost::interprocess::not_found_error) {
throw;
}
}
return ret;
}

char key[500];
boost::interprocess::shared_memory_object shm;
boost::interprocess::mapped_region region;
shm_remove remover;
};
#endif

template<class LockFileT = OSRMLockFile>
class SharedMemoryFactory_tmpl : boost::noncopyable {
Expand Down
2 changes: 1 addition & 1 deletion DataStructures/StaticRTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ class StaticRTree : boost::noncopyable {
found_a_nearest_edge = true;
} else
if( DoubleEpsilonCompare(current_perpendicular_distance, min_dist) &&
( 1 == abs(current_edge.id - result_phantom_node.edgeBasedNode ) ) &&
( current_edge.id == result_phantom_node.edgeBasedNode+1 || current_edge.id+1 == result_phantom_node.edgeBasedNode ) &&
EdgesAreEquivalent(
current_start_coordinate,
FixedPointCoordinate(
Expand Down
6 changes: 3 additions & 3 deletions Extractor/ExtractionContainers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ void ExtractionContainers::PrepareData(
//serialize restrictions
std::ofstream restrictions_out_stream;
restrictions_out_stream.open(restrictions_file_name.c_str(), std::ios::binary);
restrictions_out_stream.write((char*)&uuid, sizeof(UUID));
restrictions_out_stream.write((char*)&uuid, sizeof(UUIDC));
restrictions_out_stream.write(
(char*)&usableRestrictionsCounter,
sizeof(unsigned)
Expand All @@ -216,7 +216,7 @@ void ExtractionContainers::PrepareData(

std::ofstream file_out_stream;
file_out_stream.open(output_file_name.c_str(), std::ios::binary);
file_out_stream.write((char*)&uuid, sizeof(UUID));
file_out_stream.write((char*)&uuid, sizeof(UUIDC));
file_out_stream.write((char*)&number_of_used_nodes, sizeof(unsigned));
time = get_timestamp();
std::cout << "[extractor] Confirming/Writing used nodes ... " << std::flush;
Expand Down Expand Up @@ -252,7 +252,7 @@ void ExtractionContainers::PrepareData(

std::cout << "[extractor] setting number of nodes ... " << std::flush;
std::ios::pos_type previous_file_position = file_out_stream.tellp();
file_out_stream.seekp(std::ios::beg+sizeof(UUID));
file_out_stream.seekp(std::ios::beg+sizeof(UUIDC));
file_out_stream.write((char*)&number_of_used_nodes, sizeof(unsigned));
file_out_stream.seekp(previous_file_position);

Expand Down
2 changes: 1 addition & 1 deletion Extractor/ExtractionContainers.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ExtractionContainers {
STXXLStringVector name_list;
STXXLRestrictionsVector restrictions_list;
STXXLWayIDStartEndVector way_start_end_id_list;
const UUID uuid;
const UUIDC uuid;

ExtractionContainers();

Expand Down
7 changes: 0 additions & 7 deletions RoutingAlgorithms/BasicRoutingInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include <stack>

SearchEngineData::SearchEngineHeapPtr SearchEngineData::forwardHeap;
SearchEngineData::SearchEngineHeapPtr SearchEngineData::backwardHeap;
SearchEngineData::SearchEngineHeapPtr SearchEngineData::forwardHeap2;
SearchEngineData::SearchEngineHeapPtr SearchEngineData::backwardHeap2;
SearchEngineData::SearchEngineHeapPtr SearchEngineData::forwardHeap3;
SearchEngineData::SearchEngineHeapPtr SearchEngineData::backwardHeap3;

template<class DataFacadeT>
class BasicRoutingInterface : boost::noncopyable {
private:
Expand Down
6 changes: 3 additions & 3 deletions Tools/componentAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ int main (int argc, char * argv[]) {
SimpleLogger().Write() <<
"Using restrictions from file: " << argv[2];
std::ifstream restriction_ifstream(argv[2], std::ios::binary);
const UUID uuid_orig;
UUID uuid_loaded;
restriction_ifstream.read((char *) &uuid_loaded, sizeof(UUID));
const UUIDC uuid_orig;
UUIDC uuid_loaded;
restriction_ifstream.read((char *) &uuid_loaded, sizeof(UUIDC));

if( !uuid_loaded.TestGraphUtil(uuid_orig) ) {
SimpleLogger().Write(logWARNING) <<
Expand Down
10 changes: 5 additions & 5 deletions Util/GraphLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ NodeID readBinaryOSRMGraphFromStream(
std::vector<NodeInfo> * int_to_ext_node_id_map,
std::vector<TurnRestriction> & restriction_list
) {
const UUID uuid_orig;
UUID uuid_loaded;
input_stream.read((char *) &uuid_loaded, sizeof(UUID));
const UUIDC uuid_orig;
UUIDC uuid_loaded;
input_stream.read((char *) &uuid_loaded, sizeof(UUIDC));

if( !uuid_loaded.TestGraphUtil(uuid_orig) ) {
SimpleLogger().Write(logWARNING) <<
Expand Down Expand Up @@ -430,8 +430,8 @@ unsigned readHSGRFromStream(

boost::filesystem::ifstream hsgr_input_stream(hsgr_file, std::ios::binary);

UUID uuid_loaded, uuid_orig;
hsgr_input_stream.read((char *)&uuid_loaded, sizeof(UUID));
UUIDC uuid_loaded, uuid_orig;
hsgr_input_stream.read((char *)&uuid_loaded, sizeof(UUIDC));
if( !uuid_loaded.TestGraphUtil(uuid_orig) ) {
SimpleLogger().Write(logWARNING) <<
".hsgr was prepared with different build. "
Expand Down
Loading