[geos-commits] [SCM] GEOS branch main updated. 917aeecadaaa5db9e7361ecfef2bca7bb64c8ec9

git at osgeo.org git at osgeo.org
Tue Jul 13 12:16:39 PDT 2021


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GEOS".

The branch, main has been updated
       via  917aeecadaaa5db9e7361ecfef2bca7bb64c8ec9 (commit)
       via  100c12247b0081b063a269749ca69868da82da86 (commit)
       via  f3bda6cd4f7ff79b6982a9f8eb0259bd8591f7f9 (commit)
       via  9ff402779ff1b22a2157b4c44c2366745dd53eff (commit)
       via  3fcbd1e0c52843c2ae0b4809c9f89f74ce529afe (commit)
      from  d880957a155d095988ff97060bc1d4ca5643cf90 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 917aeecadaaa5db9e7361ecfef2bca7bb64c8ec9
Merge: d880957 100c122
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date:   Tue Jul 13 12:16:30 2021 -0700

    Merge branch 'jorisvandenbossche-strtree-build-threadsafe' into main


commit 100c12247b0081b063a269749ca69868da82da86
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date:   Tue Jul 13 12:16:16 2021 -0700

    Change test query object in multi-threaded CAPI query test

diff --git a/tests/unit/capi/GEOSSTRtreeTest.cpp b/tests/unit/capi/GEOSSTRtreeTest.cpp
index beeaafc..03400b6 100644
--- a/tests/unit/capi/GEOSSTRtreeTest.cpp
+++ b/tests/unit/capi/GEOSSTRtreeTest.cpp
@@ -366,7 +366,7 @@ void object::test<11>()
     GEOSGeometry* q2 = GEOSBuffer(geoms[40], 10, 48);
 
     std::thread t1(query, q1);
-    std::thread t2(query, q1);
+    std::thread t2(query, q2);
 
     t1.join();
     t2.join();

commit f3bda6cd4f7ff79b6982a9f8eb0259bd8591f7f9
Merge: d880957 9ff4027
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date:   Tue Jul 13 12:15:32 2021 -0700

    Merge branch 'strtree-build-threadsafe' of https://github.com/jorisvandenbossche/geos into jorisvandenbossche-strtree-build-threadsafe


commit 9ff402779ff1b22a2157b4c44c2366745dd53eff
Author: Daniel Baston <dbaston at gmail.com>
Date:   Thu Jun 17 20:22:18 2021 -0400

    Add GEOSSTRtree_query thread-safety test

diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt
index 2249f85..e0d6711 100644
--- a/tests/unit/CMakeLists.txt
+++ b/tests/unit/CMakeLists.txt
@@ -13,7 +13,9 @@ file(GLOB_RECURSE _sources ${CMAKE_CURRENT_LIST_DIR}/*.cpp CONFIGURE_DEPEND)
 add_executable(test_geos_unit ${_sources})
 unset(_sources)
 
-target_link_libraries(test_geos_unit PRIVATE geos geos_c)
+find_package(Threads)
+
+target_link_libraries(test_geos_unit PRIVATE geos geos_c Threads::Threads)
 target_include_directories(test_geos_unit
   PRIVATE
     $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>)
diff --git a/tests/unit/capi/GEOSSTRtreeTest.cpp b/tests/unit/capi/GEOSSTRtreeTest.cpp
index cf42ac9..beeaafc 100644
--- a/tests/unit/capi/GEOSSTRtreeTest.cpp
+++ b/tests/unit/capi/GEOSSTRtreeTest.cpp
@@ -9,6 +9,7 @@
 #include <cstdio>
 #include <cstring>
 #include <cmath>
+#include <thread>
 
 #include "capi_test_utils.h"
 
@@ -339,6 +340,47 @@ void object::test<10>()
     ensure_equals(hitVal, 3u);
 }
 
+// queries are thread-safe
+template<>
+template<>
+void object::test<11>()
+{
+    GEOSSTRtree* tree = GEOSSTRtree_create(10);
+
+    std::vector<GEOSGeometry*> geoms;
+    for (size_t i = 0; i < 100; i++) {
+        geoms.push_back(GEOSGeom_createPointFromXY((double) i, (double) i));
+    }
+    for (const auto& geom : geoms) {
+        GEOSSTRtree_insert(tree, geom, geom);
+    }
+
+    auto query = [tree](const GEOSGeometry* env) {
+        GEOSSTRtree_query(tree, env, [](void* g, void* userdata) {
+            (void) g;
+            (void) userdata;
+        }, nullptr);
+    };
+
+    GEOSGeometry* q1 = GEOSBuffer(geoms[10], 10, 48);
+    GEOSGeometry* q2 = GEOSBuffer(geoms[40], 10, 48);
+
+    std::thread t1(query, q1);
+    std::thread t2(query, q1);
+
+    t1.join();
+    t2.join();
+
+    GEOSGeom_destroy(q1);
+    GEOSGeom_destroy(q2);
+
+    for (auto& geom : geoms) {
+        GEOSGeom_destroy(geom);
+    }
+
+    GEOSSTRtree_destroy(tree);
+}
+
 
 } // namespace tut
 

commit 3fcbd1e0c52843c2ae0b4809c9f89f74ce529afe
Author: Joris Van den Bossche <jorisvandenbossche at gmail.com>
Date:   Thu Jun 17 09:34:48 2021 +0200

    Fix GEOSSTRtree_query_r to be thread-safe on first call (lock TemplateSTRtreeImpl on build)

diff --git a/include/geos/index/strtree/TemplateSTRtree.h b/include/geos/index/strtree/TemplateSTRtree.h
index 4ce189a..10b64e9 100644
--- a/include/geos/index/strtree/TemplateSTRtree.h
+++ b/include/geos/index/strtree/TemplateSTRtree.h
@@ -27,6 +27,7 @@
 
 #include <vector>
 #include <queue>
+#include <mutex>
 
 namespace geos {
 namespace index {
@@ -145,6 +146,25 @@ public:
         nodes.reserve(finalSize);
     }
 
+    /**
+     * Copy constructor, needed because mutex is not copyable
+     */
+    TemplateSTRtreeImpl(const TemplateSTRtreeImpl& other) :
+        root(other.root),
+        nodeCapacity(other.nodeCapacity),
+        numItems(other.numItems) {
+        nodes = other.nodes;
+    }
+
+    TemplateSTRtreeImpl& operator=(TemplateSTRtreeImpl other)
+    {
+        root = other.root;
+        nodeCapacity = other.nodeCapacity;
+        numItems = other.numItems;
+        nodes = other.nodes;
+        return *this;
+    }
+
     /// @}
     /// \defgroup insert Insertion
     /// @{
@@ -320,6 +340,8 @@ public:
 
     /** Build the tree if it has not already been built. */
     void build() {
+        std::lock_guard<std::mutex> lock(lock_);
+
         if (built()) {
             return;
         }
@@ -351,13 +373,14 @@ public:
     }
 
 protected:
+    std::mutex lock_;
     NodeList nodes;      //**< a list of all leaf and branch nodes in the tree. */
     Node* root;          //**< a pointer to the root node, if the tree has been built. */
     size_t nodeCapacity; //*< maximum number of children of each node */
     size_t numItems;     //*< total number of items in the tree, if it has been built. */
 
     // Prevent instantiation of base class.
-    ~TemplateSTRtreeImpl() = default;
+    // ~TemplateSTRtreeImpl() = default;
 
     void createLeafNode(ItemType&& item, const BoundsType& env) {
         nodes.emplace_back(std::forward<ItemType>(item), env);

-----------------------------------------------------------------------

Summary of changes:
 include/geos/index/strtree/TemplateSTRtree.h | 25 ++++++++++++++++-
 tests/unit/CMakeLists.txt                    |  4 ++-
 tests/unit/capi/GEOSSTRtreeTest.cpp          | 42 ++++++++++++++++++++++++++++
 3 files changed, 69 insertions(+), 2 deletions(-)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list