From 2f2b1f874a271d63db19ada6ae0ca6d0bf8671ee Mon Sep 17 00:00:00 2001 From: Sasa Ivetic Date: Wed, 5 Oct 2011 12:48:37 -0500 Subject: [PATCH 01/10] Fixed IntermediateDirectory in createHiearchy.vcproj --- vcprojects/createHierarchy.vcproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vcprojects/createHierarchy.vcproj b/vcprojects/createHierarchy.vcproj index 1d0d982f9..a5846c7ce 100644 --- a/vcprojects/createHierarchy.vcproj +++ b/vcprojects/createHierarchy.vcproj @@ -99,7 +99,7 @@ Date: Wed, 5 Oct 2011 12:54:09 -0500 Subject: [PATCH 02/10] Copy speedprofile.ini for Release build of extractor --- vcprojects/extractor.vcproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vcprojects/extractor.vcproj b/vcprojects/extractor.vcproj index ab0ae5f15..6c7600b75 100644 --- a/vcprojects/extractor.vcproj +++ b/vcprojects/extractor.vcproj @@ -177,7 +177,7 @@ /> From 9091c8702d42050b7f3c2294f176326f9ab9abd0 Mon Sep 17 00:00:00 2001 From: Project OSRM Date: Fri, 7 Oct 2011 17:44:03 +0300 Subject: [PATCH 03/10] Removing superflous statement. --- DataStructures/BaseParser.h | 1 - 1 file changed, 1 deletion(-) diff --git a/DataStructures/BaseParser.h b/DataStructures/BaseParser.h index 8856afffe..32ed8cfc7 100644 --- a/DataStructures/BaseParser.h +++ b/DataStructures/BaseParser.h @@ -28,7 +28,6 @@ public: virtual bool Init() = 0; virtual bool RegisterCallbacks(bool (*nodeCallbackPointer)(NodeT), bool (*restrictionCallbackPointer)(RestrictionT), bool (*wayCallbackPointer)(WayT), bool (*addressCallbackPointer)(NodeT, HashTable)) = 0; virtual bool Parse() = 0; -private: }; #endif /* BASEPARSER_H_ */ From 5e1f621c50171324290d70df6223e894f0aab71d Mon Sep 17 00:00:00 2001 From: Project OSRM Date: Fri, 7 Oct 2011 18:19:43 +0300 Subject: [PATCH 04/10] Removed linebreak --- DataStructures/ImportEdge.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/DataStructures/ImportEdge.h b/DataStructures/ImportEdge.h index 0c9f5da08..fe7224bb7 100644 --- a/DataStructures/ImportEdge.h +++ b/DataStructures/ImportEdge.h @@ -23,8 +23,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include -class Edge -{ +class Edge { public: bool operator< (const Edge& e) const { From 1fb34be11e0b5829563f82a61b8368666df7bd73 Mon Sep 17 00:00:00 2001 From: Project OSRM Date: Fri, 7 Oct 2011 18:38:54 +0300 Subject: [PATCH 05/10] removed linebreak. --- DataStructures/InputReaderFactory.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/DataStructures/InputReaderFactory.h b/DataStructures/InputReaderFactory.h index e10e4fa74..552eb7370 100644 --- a/DataStructures/InputReaderFactory.h +++ b/DataStructures/InputReaderFactory.h @@ -32,8 +32,7 @@ struct BZ2Context { char unused[BZ_MAX_UNUSED]; }; -int readFromBz2Stream( void* pointer, char* buffer, int len ) -{ +int readFromBz2Stream( void* pointer, char* buffer, int len ) { void *unusedTmpVoid=NULL; char *unusedTmp=NULL; BZ2Context* context = (BZ2Context*) pointer; From 5274af77304af061e69bda763fd888846ca312a4 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Sat, 8 Oct 2011 20:37:16 +0200 Subject: [PATCH 06/10] Small performance fixes --- DataStructures/ExtractorCallBacks.h | 6 ++--- extractor.cpp | 40 ++++++++++++++--------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/DataStructures/ExtractorCallBacks.h b/DataStructures/ExtractorCallBacks.h index 1dbfb8c50..cfa2f0b19 100644 --- a/DataStructures/ExtractorCallBacks.h +++ b/DataStructures/ExtractorCallBacks.h @@ -167,13 +167,13 @@ public: w.nameID = strit->second; } + GUARANTEE(w.id != UINT_MAX, "found way with unknown type"); + GUARANTEE(-1 != w.speed, "found way with unknown speed"); + if ( w.direction == _Way::opposite ){ std::reverse( w.path.begin(), w.path.end() ); } - GUARANTEE(w.id != UINT_MAX, "found way with unknown type"); - GUARANTEE(-1 != w.speed, "found way with unknown speed"); - for(vector< NodeID >::size_type n = 0; n < w.path.size()-1; ++n) { externalMemory->allEdges.push_back(_Edge(w.path[n], w.path[n+1], w.type, w.direction, w.speed, w.nameID)); externalMemory->usedNodeIDs.push_back(w.path[n]); diff --git a/extractor.cpp b/extractor.cpp index a345fb2b4..11517362b 100644 --- a/extractor.cpp +++ b/extractor.cpp @@ -229,11 +229,11 @@ int main (int argc, char *argv[]) { while(wayStartAndEndEdgeIT != externalMemory.wayStartEndVector.end() && restrictionsIT != externalMemory.restrictionsVector.end()) { if(wayStartAndEndEdgeIT->wayID < restrictionsIT->fromWay){ - wayStartAndEndEdgeIT++; + ++wayStartAndEndEdgeIT; continue; } if(wayStartAndEndEdgeIT->wayID > restrictionsIT->fromWay) { - restrictionsIT++; + ++restrictionsIT; continue; } assert(wayStartAndEndEdgeIT->wayID == restrictionsIT->fromWay); @@ -248,7 +248,7 @@ int main (int argc, char *argv[]) { } else if(wayStartAndEndEdgeIT->lastTarget == viaNode) { restrictionsIT->restriction.fromNode = wayStartAndEndEdgeIT->lastStart; } - restrictionsIT++; + ++restrictionsIT; } cout << "ok, after " << get_timestamp() - time << "s" << endl; @@ -266,11 +266,11 @@ int main (int argc, char *argv[]) { while(wayStartAndEndEdgeIT != externalMemory.wayStartEndVector.end() && restrictionsIT != externalMemory.restrictionsVector.end()) { if(wayStartAndEndEdgeIT->wayID < restrictionsIT->toWay){ - wayStartAndEndEdgeIT++; + ++wayStartAndEndEdgeIT; continue; } if(wayStartAndEndEdgeIT->wayID > restrictionsIT->toWay) { - restrictionsIT++; + ++restrictionsIT; continue; } NodeID viaNode = restrictionsIT->restriction.viaNode; @@ -285,9 +285,9 @@ int main (int argc, char *argv[]) { } if(UINT_MAX != restrictionsIT->restriction.fromNode && UINT_MAX != restrictionsIT->restriction.toNode) { - usableRestrictionsCounter++; + ++usableRestrictionsCounter; } - restrictionsIT++; + ++restrictionsIT; } cout << "ok, after " << get_timestamp() - time << "s" << endl; @@ -295,7 +295,7 @@ int main (int argc, char *argv[]) { ofstream restrictionsOutstream; restrictionsOutstream.open(restrictionsFileName.c_str(), ios::binary); restrictionsOutstream.write((char*)&usableRestrictionsCounter, sizeof(unsigned)); - for(restrictionsIT = externalMemory.restrictionsVector.begin(); restrictionsIT != externalMemory.restrictionsVector.end(); restrictionsIT++) { + for(restrictionsIT = externalMemory.restrictionsVector.begin(); restrictionsIT != externalMemory.restrictionsVector.end(); ++restrictionsIT) { if(UINT_MAX != restrictionsIT->restriction.fromNode && UINT_MAX != restrictionsIT->restriction.toNode) { restrictionsOutstream.write((char *)&(restrictionsIT->restriction), sizeof(_Restriction)); } @@ -311,20 +311,20 @@ int main (int argc, char *argv[]) { STXXLNodeIDVector::iterator usedNodeIDsIT = externalMemory.usedNodeIDs.begin(); while(usedNodeIDsIT != externalMemory.usedNodeIDs.end() && nodesIT != externalMemory.allNodes.end()) { if(*usedNodeIDsIT < nodesIT->id){ - usedNodeIDsIT++; + ++usedNodeIDsIT; continue; } if(*usedNodeIDsIT > nodesIT->id) { - nodesIT++; + ++nodesIT; continue; } if(*usedNodeIDsIT == nodesIT->id) { fout.write((char*)&(nodesIT->id), sizeof(unsigned)); fout.write((char*)&(nodesIT->lon), sizeof(int)); fout.write((char*)&(nodesIT->lat), sizeof(int)); - usedNodeCounter++; - usedNodeIDsIT++; - nodesIT++; + ++usedNodeCounter; + ++usedNodeIDsIT; + ++nodesIT; } } @@ -353,7 +353,7 @@ int main (int argc, char *argv[]) { STXXLEdgeVector::iterator edgeIT = externalMemory.allEdges.begin(); while(edgeIT != externalMemory.allEdges.end() && nodesIT != externalMemory.allNodes.end()) { if(edgeIT->start < nodesIT->id){ - edgeIT++; + ++edgeIT; continue; } if(edgeIT->start > nodesIT->id) { @@ -363,7 +363,7 @@ int main (int argc, char *argv[]) { if(edgeIT->start == nodesIT->id) { edgeIT->startCoord.lat = nodesIT->lat; edgeIT->startCoord.lon = nodesIT->lon; - edgeIT++; + ++edgeIT; } } cout << "ok, after " << get_timestamp() - time << "s" << endl; @@ -381,11 +381,11 @@ int main (int argc, char *argv[]) { edgeIT = externalMemory.allEdges.begin(); while(edgeIT != externalMemory.allEdges.end() && nodesIT != externalMemory.allNodes.end()) { if(edgeIT->target < nodesIT->id){ - edgeIT++; + ++edgeIT; continue; } if(edgeIT->target > nodesIT->id) { - nodesIT++; + ++nodesIT; continue; } if(edgeIT->target == nodesIT->id) { @@ -430,8 +430,8 @@ int main (int argc, char *argv[]) { fout.write((char*)&edgeType, sizeof(short)); fout.write((char*)&edgeIT->nameID, sizeof(unsigned)); } - usedEdgeCounter++; - edgeIT++; + ++usedEdgeCounter; + ++edgeIT; } } cout << "ok, after " << get_timestamp() - time << "s" << endl; @@ -494,7 +494,7 @@ bool adressFunction(_Node n, HashTable keyVals){ bool restrictionFunction(_RawRestrictionContainer r) { extractCallBacks->restrictionFunction(r); - globalRestrictionCounter++; + ++globalRestrictionCounter; return true; } bool wayFunction(_Way w) { From 2a6275cf38d49c99dc5eb5232917078da5f014bc Mon Sep 17 00:00:00 2001 From: Sasa Ivetic Date: Fri, 14 Oct 2011 09:18:57 -0500 Subject: [PATCH 07/10] Split PBF Parser into a single Read and a single Parse thread to increase parsing speed. --- DataStructures/PBFParser.h | 219 +++++++++++++++++++++++++------------ 1 file changed, 149 insertions(+), 70 deletions(-) diff --git a/DataStructures/PBFParser.h b/DataStructures/PBFParser.h index 09d11d053..99729ada0 100644 --- a/DataStructures/PBFParser.h +++ b/DataStructures/PBFParser.h @@ -32,6 +32,84 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "ExtractorStructs.h" +/* + Concurrent Queue written by Anthony Williams: + http://www.justsoftwaresolutions.co.uk/threading/implementing-a-thread-safe-queue-using-condition-variables.html +*/ +template +class concurrent_queue +{ +private: + std::queue internal_queue; + mutable boost::mutex queue_mutex; + mutable boost::mutex queue_full_mutex; + boost::condition_variable queue_cv; + boost::condition_variable queue_full_cv; + const size_t max_queue_size; + + bool size_exceeded() const { + boost::mutex::scoped_lock lock(queue_mutex); + return internal_queue.size() >= max_queue_size; + } + +public: + concurrent_queue(const size_t max_size) + : max_queue_size(max_size) { + } + + void push(Data const& data) + { + if (size_exceeded()) { + boost::mutex::scoped_lock qf_lock(queue_full_mutex); + queue_full_cv.wait(qf_lock); + } + + boost::mutex::scoped_lock lock(queue_mutex); + internal_queue.push(data); + lock.unlock(); + queue_cv.notify_one(); + } + + bool empty() const + { + boost::mutex::scoped_lock lock(queue_mutex); + return internal_queue.empty(); + } + + bool try_pop(Data& popped_value) + { + boost::mutex::scoped_lock lock(queue_mutex); + if(internal_queue.empty()) + { + return false; + } + + popped_value=internal_queue.front(); + internal_queue.pop(); + queue_full_cv.notify_one(); + return true; + } + + void wait_and_pop(Data& popped_value) + { + boost::mutex::scoped_lock lock(queue_mutex); + while(internal_queue.empty()) + { + queue_cv.wait(lock); + } + + popped_value=internal_queue.front(); + internal_queue.pop(); + queue_full_cv.notify_one(); + } + + int size() const { + boost::mutex::scoped_lock lock(queue_mutex); + return static_cast(internal_queue.size()); + } +}; + + class PBFParser : public BaseParser<_Node, _RawRestrictionContainer, _Way> { enum EntityType { @@ -61,9 +139,9 @@ class PBFParser : public BaseParser<_Node, _RawRestrictionContainer, _Way> { }; public: - PBFParser(const char * fileName) { + PBFParser(const char * fileName) + : threadDataQueue( new concurrent_queue<_ThreadData*>(25) ) { /* Max 25 items in queue */ GOOGLE_PROTOBUF_VERIFY_VERSION; - omp_set_num_threads(1); input.open(fileName, std::ios::in | std::ios::binary); if (!input) { @@ -86,10 +164,12 @@ public: if(input.is_open()) input.close(); - unsigned maxThreads = omp_get_max_threads(); - for ( unsigned threadNum = 0; threadNum < maxThreads; ++threadNum ) { - delete threadDataVector[threadNum]; + // Clean up any leftover ThreadData objects in the queue + _ThreadData* td; + while (threadDataQueue->try_pop(td)) { + delete td; } + delete threadDataQueue; google::protobuf::ShutdownProtobufLibrary(); @@ -100,12 +180,6 @@ public: } bool Init() { - /** Init Vector with ThreadData Objects */ - unsigned maxThreads = omp_get_max_threads(); - for ( unsigned threadNum = 0; threadNum < maxThreads; ++threadNum ) { - threadDataVector.push_back( new _ThreadData( ) ); - } - _ThreadData initData; /** read Header */ if(!readPBFBlobHeader(input, &initData)) { @@ -137,36 +211,58 @@ public: return true; } - bool Parse() { -#pragma omp parallel - { - _ThreadData * threadData = threadDataVector[omp_get_thread_num()]; - //parse through all Blocks - bool keepRunning = true; - // while(readNextBlock(input)) { - do{ -#pragma omp critical - { - keepRunning = readNextBlock(input, threadData); - } - if(keepRunning) { - loadBlock(threadData); - for(int i = 0; i < threadData->PBFprimitiveBlock.primitivegroup_size(); i++) { - threadData->currentGroupID = i; - loadGroup(threadData); + void ReadData() { + bool keepRunning = true; + do { + _ThreadData *threadData = new _ThreadData(); + keepRunning = readNextBlock(input, threadData); - if(threadData->entityTypeIndicator == TypeNode) - parseNode(threadData); - if(threadData->entityTypeIndicator == TypeWay) - parseWay(threadData); - if(threadData->entityTypeIndicator == TypeRelation) - parseRelation(threadData); - if(threadData->entityTypeIndicator == TypeDenseNode) - parseDenseNode(threadData); - } - } - }while(keepRunning); + if (keepRunning) + threadDataQueue->push(threadData); + else + threadDataQueue->push(NULL); // No more data to read, parse stops when NULL encountered + } while(keepRunning); + } + + void ParseData() { + while (1) { + _ThreadData *threadData; + threadDataQueue->wait_and_pop(threadData); + if (threadData == NULL) { + cout << "Parse Data Thread Finished" << endl; + threadDataQueue->push(NULL); // Signal end of data for other threads + break; + } + + loadBlock(threadData); + for(int i = 0; i < threadData->PBFprimitiveBlock.primitivegroup_size(); i++) { + threadData->currentGroupID = i; + loadGroup(threadData); + + if(threadData->entityTypeIndicator == TypeNode) + parseNode(threadData); + if(threadData->entityTypeIndicator == TypeWay) + parseWay(threadData); + if(threadData->entityTypeIndicator == TypeRelation) + parseRelation(threadData); + if(threadData->entityTypeIndicator == TypeDenseNode) + parseDenseNode(threadData); + } + + delete threadData; + threadData = NULL; } + } + + bool Parse() { + // Start the read and parse threads + boost::thread readThread(boost::bind(&PBFParser::ReadData, this)); + boost::thread parseThread(boost::bind(&PBFParser::ParseData, this)); + + // Wait for the threads to finish + readThread.join(); + parseThread.join(); + return true; } @@ -200,27 +296,18 @@ private: keyVals.Add(key, value); denseTagIndex += 2; } -#pragma omp critical - { - if(!(*addressCallback)(n, keyVals)) - std::cerr << "[PBFParser] adress not parsed" << std::endl; - } - -#pragma omp critical - { - if(!(*nodeCallback)(n)) - std::cerr << "[PBFParser] dense node not parsed" << std::endl; - } + if(!(*addressCallback)(n, keyVals)) + std::cerr << "[PBFParser] adress not parsed" << std::endl; + + if(!(*nodeCallback)(n)) + std::cerr << "[PBFParser] dense node not parsed" << std::endl; } } void parseNode(_ThreadData * threadData) { _Node n; -#pragma omp critical - { - if(!(*nodeCallback)(n)) - std::cerr << "[PBFParser] simple node not parsed" << std::endl; - } + if(!(*nodeCallback)(n)) + std::cerr << "[PBFParser] simple node not parsed" << std::endl; } void parseRelation(_ThreadData * threadData) { @@ -291,11 +378,8 @@ private: // cout << "node " << currentRestriction.viaNode; // cout << " to " << currentRestriction.to << endl; // } -#pragma omp critical - { - if(!(*restrictionCallback)(currentRestrictionContainer)) - std::cerr << "[PBFParser] relation not parsed" << std::endl; - } + if(!(*restrictionCallback)(currentRestrictionContainer)) + std::cerr << "[PBFParser] relation not parsed" << std::endl; } } } @@ -317,18 +401,15 @@ private: const std::string val = threadData->PBFprimitiveBlock.stringtable().s(inputWay.vals(i)); w.keyVals.Add(key, val); } -#pragma omp critical - { - if(!(*wayCallback)(w)) { - std::cerr << "[PBFParser] way not parsed" << std::endl; - } + + if(!(*wayCallback)(w)) { + std::cerr << "[PBFParser] way not parsed" << std::endl; } } } } void loadGroup(_ThreadData * threadData) { -#pragma omp atomic groupCount++; const OSMPBF::PrimitiveGroup& group = threadData->PBFprimitiveBlock.primitivegroup( threadData->currentGroupID ); @@ -350,7 +431,6 @@ private: } void loadBlock(_ThreadData * threadData) { -#pragma omp critical blockCount++; threadData->currentGroupID = 0; threadData->currentEntityID = 0; @@ -522,9 +602,8 @@ private: /* the input stream to parse */ std::fstream input; - /* ThreadData Array */ - std::vector < _ThreadData* > threadDataVector; - + /* ThreadData Queue */ + concurrent_queue < _ThreadData* >* threadDataQueue; }; #endif /* PBFPARSER_H_ */ From 63e8793c7f641ddeee53496925b2e9dc0ab2a233 Mon Sep 17 00:00:00 2001 From: Sasa Ivetic Date: Fri, 14 Oct 2011 12:02:40 -0500 Subject: [PATCH 08/10] Moved Concurrent Queue class into its own file --- DataStructures/ConcurrentQueue.h | 103 +++++++++++++++++++++++++++++++ DataStructures/PBFParser.h | 80 +----------------------- vcprojects/extractor.vcproj | 4 ++ 3 files changed, 108 insertions(+), 79 deletions(-) create mode 100644 DataStructures/ConcurrentQueue.h diff --git a/DataStructures/ConcurrentQueue.h b/DataStructures/ConcurrentQueue.h new file mode 100644 index 000000000..dd6c84be0 --- /dev/null +++ b/DataStructures/ConcurrentQueue.h @@ -0,0 +1,103 @@ +/* + open source routing machine + Copyright (C) Dennis Luxen, others 2010 + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU AFFERO General Public License as published by +the Free Software Foundation; either version 3 of the License, or +any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +or see http://www.gnu.org/licenses/agpl.txt. + */ + +#ifndef CONCURRENTQUEUE_H_INCLUDED +#define CONCURRENTQUEUE_H_INCLUDED + +#include "typedefs.h" + +/* + Concurrent Queue written by Anthony Williams: + http://www.justsoftwaresolutions.co.uk/threading/implementing-a-thread-safe-queue-using-condition-variables.html +*/ +template +class concurrent_queue +{ +private: + std::queue internal_queue; + mutable boost::mutex queue_mutex; + mutable boost::mutex queue_full_mutex; + boost::condition_variable queue_cv; + boost::condition_variable queue_full_cv; + const size_t max_queue_size; + + bool size_exceeded() const { + boost::mutex::scoped_lock lock(queue_mutex); + return internal_queue.size() >= max_queue_size; + } + +public: + concurrent_queue(const size_t max_size) + : max_queue_size(max_size) { + } + + void push(Data const& data) + { + if (size_exceeded()) { + boost::mutex::scoped_lock qf_lock(queue_full_mutex); + queue_full_cv.wait(qf_lock); + } + + boost::mutex::scoped_lock lock(queue_mutex); + internal_queue.push(data); + lock.unlock(); + queue_cv.notify_one(); + } + + bool empty() const + { + boost::mutex::scoped_lock lock(queue_mutex); + return internal_queue.empty(); + } + + bool try_pop(Data& popped_value) + { + boost::mutex::scoped_lock lock(queue_mutex); + if(internal_queue.empty()) + { + return false; + } + + popped_value=internal_queue.front(); + internal_queue.pop(); + queue_full_cv.notify_one(); + return true; + } + + void wait_and_pop(Data& popped_value) + { + boost::mutex::scoped_lock lock(queue_mutex); + while(internal_queue.empty()) + { + queue_cv.wait(lock); + } + + popped_value=internal_queue.front(); + internal_queue.pop(); + queue_full_cv.notify_one(); + } + + int size() const { + boost::mutex::scoped_lock lock(queue_mutex); + return static_cast(internal_queue.size()); + } +}; + +#endif //#ifndef CONCURRENTQUEUE_H_INCLUDED \ No newline at end of file diff --git a/DataStructures/PBFParser.h b/DataStructures/PBFParser.h index 99729ada0..ee48885c0 100644 --- a/DataStructures/PBFParser.h +++ b/DataStructures/PBFParser.h @@ -30,85 +30,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../typedefs.h" #include "HashTable.h" #include "ExtractorStructs.h" - - -/* - Concurrent Queue written by Anthony Williams: - http://www.justsoftwaresolutions.co.uk/threading/implementing-a-thread-safe-queue-using-condition-variables.html -*/ -template -class concurrent_queue -{ -private: - std::queue internal_queue; - mutable boost::mutex queue_mutex; - mutable boost::mutex queue_full_mutex; - boost::condition_variable queue_cv; - boost::condition_variable queue_full_cv; - const size_t max_queue_size; - - bool size_exceeded() const { - boost::mutex::scoped_lock lock(queue_mutex); - return internal_queue.size() >= max_queue_size; - } - -public: - concurrent_queue(const size_t max_size) - : max_queue_size(max_size) { - } - - void push(Data const& data) - { - if (size_exceeded()) { - boost::mutex::scoped_lock qf_lock(queue_full_mutex); - queue_full_cv.wait(qf_lock); - } - - boost::mutex::scoped_lock lock(queue_mutex); - internal_queue.push(data); - lock.unlock(); - queue_cv.notify_one(); - } - - bool empty() const - { - boost::mutex::scoped_lock lock(queue_mutex); - return internal_queue.empty(); - } - - bool try_pop(Data& popped_value) - { - boost::mutex::scoped_lock lock(queue_mutex); - if(internal_queue.empty()) - { - return false; - } - - popped_value=internal_queue.front(); - internal_queue.pop(); - queue_full_cv.notify_one(); - return true; - } - - void wait_and_pop(Data& popped_value) - { - boost::mutex::scoped_lock lock(queue_mutex); - while(internal_queue.empty()) - { - queue_cv.wait(lock); - } - - popped_value=internal_queue.front(); - internal_queue.pop(); - queue_full_cv.notify_one(); - } - - int size() const { - boost::mutex::scoped_lock lock(queue_mutex); - return static_cast(internal_queue.size()); - } -}; - +#include "ConcurrentQueue.h" class PBFParser : public BaseParser<_Node, _RawRestrictionContainer, _Way> { diff --git a/vcprojects/extractor.vcproj b/vcprojects/extractor.vcproj index 6c7600b75..57b9eb2fc 100644 --- a/vcprojects/extractor.vcproj +++ b/vcprojects/extractor.vcproj @@ -250,6 +250,10 @@ RelativePath="..\DataStructures\BinaryHeap.h" > + + From 3fcabb642e39b81d51e1903b619e53887ce9c696 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 3 Nov 2011 10:53:40 -0500 Subject: [PATCH 09/10] Compile fixes if OpenMP is not available --- Contractor/Contractor.h | 2 ++ DataStructures/NNGrid.h | 2 ++ createHierarchy.cpp | 5 +++++ routed.cpp | 4 ++++ 4 files changed, 13 insertions(+) diff --git a/Contractor/Contractor.h b/Contractor/Contractor.h index 0fa376e33..66f4ceed7 100644 --- a/Contractor/Contractor.h +++ b/Contractor/Contractor.h @@ -35,7 +35,9 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #include #include +#ifdef _OPEMP #include +#endif class Contractor { diff --git a/DataStructures/NNGrid.h b/DataStructures/NNGrid.h index 33508eaeb..a889d78cc 100644 --- a/DataStructures/NNGrid.h +++ b/DataStructures/NNGrid.h @@ -28,7 +28,9 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #include #include +#ifdef _OPENMP #include +#endif #ifdef _WIN32 #include diff --git a/createHierarchy.cpp b/createHierarchy.cpp index a25976013..0464e36eb 100644 --- a/createHierarchy.cpp +++ b/createHierarchy.cpp @@ -38,6 +38,11 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifdef _OPENMP #include +#else +int omp_get_num_procs() { return 1; } +int omp_get_max_threads() { return 1; } +int omp_get_thread_num() { return 0; } +int omp_set_num_threads(int i) {} #endif #include "typedefs.h" diff --git a/routed.cpp b/routed.cpp index 74d4cba45..69595921f 100644 --- a/routed.cpp +++ b/routed.cpp @@ -23,6 +23,10 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifdef _OPENMP #include +#else +int omp_get_num_procs() { return 1; } +int omp_get_max_threads() { return 1; } +int omp_get_thread_num() { return 0; } #endif #include From 08dd04a0d61f499c5ecf5d38169af183ca3a7404 Mon Sep 17 00:00:00 2001 From: Project OSRM Date: Fri, 4 Nov 2011 10:05:02 -0500 Subject: [PATCH 10/10] Changed prerequesite of boost libraries to 1.41 --- README.TXT | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.TXT b/README.TXT index a99f3cc33..b207b346b 100644 --- a/README.TXT +++ b/README.TXT @@ -5,7 +5,7 @@ Compiling the source code is easy. If you are running a decent linux installing dependencies and running make should suffice. Make sure the following dependencies are installed: - - Boost 1.37+ + - Boost 1.41+ - sparsehash 1.4+ - g++ 4.2+ (with warnings and unsupported), 4.4+ - libxml2 2.7+