From 2703d73410b0a0d5d3afb7c6b1e1dfc958eebdeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C7=9D=C9=B9=CA=87=CA=87=C9=90=CA=83=C7=9D=E2=97=96=20x?= =?UTF-8?q?=C4=B1=CA=83=C7=9D=C9=9F?= Date: Tue, 7 Mar 2023 23:49:04 +0000 Subject: [PATCH 1/2] Add latomic when needed. (#427) --- CMakeLists.txt | 6 ++++ cmake/CheckCxxAtomic.cmake | 66 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 cmake/CheckCxxAtomic.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index e5bc4bcf..4be62e59 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -110,6 +110,12 @@ add_executable(tilemaker vector_tile.pb.cc osmformat.pb.cc ${tilemaker_src_files target_link_libraries(tilemaker ${PROTOBUF_LIBRARY} ${LIBSHP_LIBRARIES} ${SQLITE3_LIBRARIES} ${LUAJIT_LIBRARY} ${LUA_LIBRARIES} ${ZLIB_LIBRARY} ${THREAD_LIB} ${CMAKE_DL_LIBS} Boost::system Boost::filesystem Boost::program_options Boost::iostreams) +include(CheckCxxAtomic) +if(NOT HAVE_CXX11_ATOMIC) + string(APPEND CMAKE_CXX_STANDARD_LIBRARIES + " ${LIBATOMIC_LINK_FLAGS}") +endif() + if(MSVC) target_link_libraries(tilemaker unofficial::sqlite3::sqlite3) endif() diff --git a/cmake/CheckCxxAtomic.cmake b/cmake/CheckCxxAtomic.cmake new file mode 100644 index 00000000..a4c8a770 --- /dev/null +++ b/cmake/CheckCxxAtomic.cmake @@ -0,0 +1,66 @@ +# some platforms do not offer support for atomic primitive for all integer +# types, in that case we need to link against libatomic + +include(CheckCXXSourceCompiles) +include(CMakePushCheckState) + + +function(check_cxx_atomics var) + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++11") + check_cxx_source_compiles(" +#include +#include +#include +#if defined(__SIZEOF_INT128__) +// Boost needs 16-byte atomics for tagged pointers. +// These are implemented via inline instructions on the platform +// if 16-byte alignment can be proven, and are delegated to libatomic +// library routines otherwise. Whether or not alignment is provably +// OK for a std::atomic unfortunately depends on compiler version and +// optimization levels, and also on the details of the expression. +// We specifically test access via an otherwise unknown pointer here +// to ensure we get the most complex case. If this access can be +// done without libatomic, then all accesses can be done. +struct tagged_ptr { + int* ptr; + std::size_t tag; +}; +void atomic16(std::atomic *ptr) +{ + tagged_ptr p{nullptr, 1}; + ptr->store(p); + tagged_ptr f = ptr->load(); + tagged_ptr new_tag{nullptr, 0}; + ptr->compare_exchange_strong(f, new_tag); +} +#endif +int main() { +#if defined(__SIZEOF_INT128__) + std::atomic ptr; + atomic16(&ptr); +#endif + std::atomic w1; + std::atomic w2; + std::atomic w4; + std::atomic w8; + return w1 + w2 + w4 + w8; +} +" ${var}) +endfunction(check_cxx_atomics) + +cmake_push_check_state() +check_cxx_atomics(HAVE_CXX11_ATOMIC) +cmake_pop_check_state() + +if(NOT HAVE_CXX11_ATOMIC) + cmake_push_check_state() + set(CMAKE_REQUIRED_LIBRARIES "atomic") + check_cxx_atomics(HAVE_LIBATOMIC) + cmake_pop_check_state() + if(HAVE_LIBATOMIC) + set(LIBATOMIC_LINK_FLAGS "-latomic") + else() + message(FATAL_ERROR + "Host compiler ${CMAKE_CXX_COMPILER} requires libatomic, but it is not found") + endif() +endif() From 653ffb866fc76dad852be71b22fb1c5d91a7cbda Mon Sep 17 00:00:00 2001 From: Richard Fairhurst Date: Tue, 7 Mar 2023 23:49:30 +0000 Subject: [PATCH 2/2] Move centroid error to verbose mode only (#472) --- src/osm_lua_processing.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/osm_lua_processing.cpp b/src/osm_lua_processing.cpp index e57b6821..583055d2 100644 --- a/src/osm_lua_processing.cpp +++ b/src/osm_lua_processing.cpp @@ -415,7 +415,7 @@ void OsmLuaProcessing::LayerAsCentroid(const string &layerName) { cout << "Couldn't find " << (isRelation ? "relation " : isWay ? "way " : "node " ) << originalOsmID << ": " << err.what() << endl; return; } catch (geom::centroid_exception &err) { - cerr << "Problem geometry " << (isRelation ? "relation " : isWay ? "way " : "node " ) << originalOsmID << ": " << err.what() << endl; + if (verbose) cerr << "Problem geometry " << (isRelation ? "relation " : isWay ? "way " : "node " ) << originalOsmID << ": " << err.what() << endl; return; } catch (std::invalid_argument &err) { cerr << "Error in OutputObjectOsmStore constructor for " << (isRelation ? "relation " : isWay ? "way " : "node " ) << originalOsmID << ": " << err.what() << endl;