Skip to content

Commit e2fabbf

Browse files
committed
Merge pull request #246 from pnorman/lockfree_config
Switch boost lockfree queue check into configure
2 parents 7c60fd5 + 943684a commit e2fabbf

3 files changed

Lines changed: 19 additions & 8 deletions

File tree

configure.ac

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,18 @@ AX_BOOST_SYSTEM
128128
AX_BOOST_FILESYSTEM
129129
AX_BOOST_THREAD
130130

131+
dnl Check if Boost is recent enough for lockfree, and if it hasn't been overridden
132+
AC_ARG_WITH([lockfree],
133+
[AS_HELP_STRING([--without-lockfree],
134+
[disable lockfree queue])],
135+
[],
136+
[with_lockfree=yes])
137+
138+
if test "x$with_lockfree" = "xyes"
139+
then
140+
AX_BOOST_BASE([1.53], AC_DEFINE([HAVE_LOCKFREE], [1], [Using lockfree queue]), [])
141+
fi
142+
131143
dnl Check for Lua libraries and headers
132144
AX_PROG_LUA([5.0],[],[
133145
AX_LUA_HEADERS([

osmdata.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
#include <stdexcept>
1111
#include <utility>
1212

13-
#if BOOST_VERSION < 105300
14-
#else
13+
#ifdef HAVE_LOCKFREE
1514
#include <boost/atomic.hpp>
1615
#endif
1716

@@ -167,7 +166,7 @@ struct pending_threaded_processor : public middle_t::pending_processor {
167166
typedef std::vector<boost::shared_ptr<output_t> > output_vec_t;
168167
typedef std::pair<boost::shared_ptr<const middle_query_t>, output_vec_t> clone_t;
169168

170-
#if BOOST_VERSION < 105300
169+
#ifndef HAVE_LOCKFREE
171170
static void do_jobs(output_vec_t const& outputs, pending_queue_t& queue, size_t& ids_done, boost::mutex& mutex, int append, bool ways) {
172171
while (true) {
173172
//get the job off the queue synchronously
@@ -209,7 +208,7 @@ struct pending_threaded_processor : public middle_t::pending_processor {
209208

210209
//starts up count threads and works on the queue
211210
pending_threaded_processor(boost::shared_ptr<middle_query_t> mid, const output_vec_t& outs, size_t thread_count, size_t job_count, int append)
212-
#if BOOST_VERSION < 105300
211+
#ifndef HAVE_LOCKFREE
213212
//note that we cant hint to the stack how large it should be ahead of time
214213
//we could use a different datastructure like a deque or vector but then
215214
//the outputs the enqueue jobs would need the version check for the push(_back) method
@@ -256,7 +255,7 @@ struct pending_threaded_processor : public middle_t::pending_processor {
256255

257256
//make the threads and start them
258257
for (size_t i = 0; i < clones.size(); ++i) {
259-
#if BOOST_VERSION < 105300
258+
#ifndef HAVE_LOCKFREE
260259
workers.create_thread(boost::bind(do_jobs, boost::cref(clones[i].second), boost::ref(queue), boost::ref(ids_done), boost::ref(mutex), append, true));
261260
#else
262261
workers.create_thread(boost::bind(do_jobs, boost::cref(clones[i].second), boost::ref(queue), boost::ref(ids_done), append, true));
@@ -307,7 +306,7 @@ struct pending_threaded_processor : public middle_t::pending_processor {
307306

308307
//make the threads and start them
309308
for (size_t i = 0; i < clones.size(); ++i) {
310-
#if BOOST_VERSION < 105300
309+
#ifndef HAVE_LOCKFREE
311310
workers.create_thread(boost::bind(do_jobs, boost::cref(clones[i].second), boost::ref(queue), boost::ref(ids_done), boost::ref(mutex), append, false));
312311
#else
313312
workers.create_thread(boost::bind(do_jobs, boost::cref(clones[i].second), boost::ref(queue), boost::ref(ids_done), append, false));
@@ -353,7 +352,7 @@ struct pending_threaded_processor : public middle_t::pending_processor {
353352
//job queue
354353
pending_queue_t queue;
355354

356-
#if BOOST_VERSION < 105300
355+
#ifndef HAVE_LOCKFREE
357356
//how many ids within the job have been processed
358357
size_t ids_done;
359358
//so the threads can manage some of the shared state

output.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include <utility>
2121

2222
typedef std::pair<osmid_t, size_t> pending_job_t;
23-
#if BOOST_VERSION < 105300
23+
#ifndef HAVE_LOCKFREE
2424
#include <stack>
2525
typedef std::stack<pending_job_t> pending_queue_t;
2626
#else

0 commit comments

Comments
 (0)