Skip to content

Commit 3900193

Browse files
authored
Merge pull request #240 from Sokolmish/master
Add ifdef to disable pthreads usage
2 parents 923c2ac + 0ca9c75 commit 3900193

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ You can download and install nanoflann using the [vcpkg](https://github.com/Micr
158158

159159
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.
160160

161+
162+
### 1.9. Compile time definitions
163+
164+
* `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.
165+
* `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.
166+
161167
------
162168

163169
## 2. Any help choosing the KD-tree parameters?

include/nanoflann.hpp

+8
Original file line numberDiff line numberDiff line change
@@ -1627,10 +1627,14 @@ class KDTreeSingleIndexAdaptor
16271627
}
16281628
else
16291629
{
1630+
#ifndef NANOFLANN_NO_THREADS
16301631
std::atomic<unsigned int> thread_count(0u);
16311632
std::mutex mutex;
16321633
Base::root_node_ = this->divideTreeConcurrent(
16331634
*this, 0, Base::size_, Base::root_bbox_, thread_count, mutex);
1635+
#else /* NANOFLANN_NO_THREADS */
1636+
throw std::runtime_error("Multithreading is disabled");
1637+
#endif /* NANOFLANN_NO_THREADS */
16341638
}
16351639
}
16361640

@@ -2090,10 +2094,14 @@ class KDTreeSingleIndexDynamicAdaptor_
20902094
}
20912095
else
20922096
{
2097+
#ifndef NANOFLANN_NO_THREADS
20932098
std::atomic<unsigned int> thread_count(0u);
20942099
std::mutex mutex;
20952100
Base::root_node_ = this->divideTreeConcurrent(
20962101
*this, 0, Base::size_, Base::root_bbox_, thread_count, mutex);
2102+
#else /* NANOFLANN_NO_THREADS */
2103+
throw std::runtime_error("Multithreading is disabled");
2104+
#endif /* NANOFLANN_NO_THREADS */
20972105
}
20982106
}
20992107

0 commit comments

Comments
 (0)