From 0ca9c75e825c70a6564bd64303614b04858e7269 Mon Sep 17 00:00:00 2001 From: Mikhail Sokolovskiy Date: Fri, 19 Apr 2024 20:39:36 +0300 Subject: [PATCH] Add ifdef to disable pthreads usage --- README.md | 6 ++++++ include/nanoflann.hpp | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/README.md b/README.md index 4d0c332..4484cf4 100644 --- a/README.md +++ b/README.md @@ -158,6 +158,12 @@ You can download and install nanoflann using the [vcpkg](https://github.com/Micr The nanoflann port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository. + +### 1.9. Compile time definitions + + * `NANOFLANN_FIRST_MATCH`: If defined and two points have the same distance, the one with the lowest-index will be returned first. Otherwise there is no particular order. + * `NANOFLANN_NO_THREADS`: If defined, multithreading capabilities will be disabled, so that the library can be used without linking with pthreads. If one tries to use multiple threads, an exception will be thrown. + ------ ## 2. Any help choosing the KD-tree parameters? diff --git a/include/nanoflann.hpp b/include/nanoflann.hpp index 08ea6bb..80995d6 100644 --- a/include/nanoflann.hpp +++ b/include/nanoflann.hpp @@ -1627,10 +1627,14 @@ class KDTreeSingleIndexAdaptor } else { +#ifndef NANOFLANN_NO_THREADS std::atomic thread_count(0u); std::mutex mutex; Base::root_node_ = this->divideTreeConcurrent( *this, 0, Base::size_, Base::root_bbox_, thread_count, mutex); +#else /* NANOFLANN_NO_THREADS */ + throw std::runtime_error("Multithreading is disabled"); +#endif /* NANOFLANN_NO_THREADS */ } } @@ -2090,10 +2094,14 @@ class KDTreeSingleIndexDynamicAdaptor_ } else { +#ifndef NANOFLANN_NO_THREADS std::atomic thread_count(0u); std::mutex mutex; Base::root_node_ = this->divideTreeConcurrent( *this, 0, Base::size_, Base::root_bbox_, thread_count, mutex); +#else /* NANOFLANN_NO_THREADS */ + throw std::runtime_error("Multithreading is disabled"); +#endif /* NANOFLANN_NO_THREADS */ } }