Skip to content

Commit

Permalink
Merge pull request #240 from Sokolmish/master
Browse files Browse the repository at this point in the history
Add ifdef to disable pthreads usage
  • Loading branch information
jlblancoc authored Apr 22, 2024
2 parents 923c2ac + 0ca9c75 commit 3900193
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
8 changes: 8 additions & 0 deletions include/nanoflann.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1627,10 +1627,14 @@ class KDTreeSingleIndexAdaptor
}
else
{
#ifndef NANOFLANN_NO_THREADS
std::atomic<unsigned int> 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 */
}
}

Expand Down Expand Up @@ -2090,10 +2094,14 @@ class KDTreeSingleIndexDynamicAdaptor_
}
else
{
#ifndef NANOFLANN_NO_THREADS
std::atomic<unsigned int> 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 */
}
}

Expand Down

0 comments on commit 3900193

Please sign in to comment.