From 175e1e6b513560272ef16d58a71318691868a83a Mon Sep 17 00:00:00 2001 From: Frank Celler Date: Wed, 27 Jan 2016 15:30:51 +0100 Subject: [PATCH 1/2] moved low level mutex in Mutex class --- arangod/Actions/RestActionHandler.h | 2 +- arangod/Actions/actions.h | 4 +- arangod/Aql/Optimizer.cpp | 2 +- arangod/Aql/Optimizer.h | 2 +- arangod/Aql/QueryCache.h | 2 +- arangod/Aql/tokens.cpp | 13 ----- arangod/Cluster/ClusterInfo.h | 4 +- arangod/Cluster/HeartbeatThread.h | 2 +- arangod/Cluster/ServerJob.cpp | 2 +- arangod/Cluster/ServerJob.h | 2 +- arangod/Dispatcher/DispatcherQueue.h | 4 +- arangod/HttpServer/HttpServer.h | 2 +- arangod/RestHandler/RestCursorHandler.h | 2 +- arangod/RestHandler/RestSimpleHandler.h | 2 +- arangod/RestServer/ConsoleThread.h | 2 +- arangod/RestServer/VocbaseContext.cpp | 2 +- arangod/Scheduler/ListenTask.h | 2 +- arangod/Scheduler/Scheduler.h | 2 +- arangod/Scheduler/SchedulerThread.h | 2 +- arangod/Scheduler/SignalTask.h | 2 +- arangod/Statistics/statistics.cpp | 4 +- arangod/Utils/CollectionKeysRepository.h | 2 +- arangod/Utils/CursorRepository.h | 2 +- arangod/V8Server/ApplicationV8.h | 2 +- arangod/VocBase/Ditch.h | 2 +- arangod/VocBase/KeyGenerator.h | 2 +- arangod/VocBase/VocShaper.h | 6 +-- arangod/VocBase/document-collection.h | 2 +- arangod/VocBase/server.cpp | 2 +- arangod/VocBase/server.h | 2 +- arangod/Wal/CollectorThread.h | 2 +- arangod/Wal/LogfileManager.h | 4 +- arangod/Wal/Slots.h | 2 +- arangosh/Benchmark/BenchmarkCounter.h | 2 +- lib/Basics/AssocMulti.h | 2 +- lib/Basics/AssocUnique.h | 2 +- lib/Basics/DeadlockDetector.h | 2 +- lib/Basics/Mutex.cpp | 67 ++++++++++++++++++++++-- lib/Basics/Mutex.h | 19 +++++-- lib/Basics/Nonce.cpp | 50 ++++-------------- lib/Basics/RandomGenerator.cpp | 1 + lib/Basics/logging.cpp | 15 +++--- lib/Basics/process-utils.cpp | 2 +- lib/Utilities/ScriptLoader.h | 2 +- 44 files changed, 140 insertions(+), 115 deletions(-) diff --git a/arangod/Actions/RestActionHandler.h b/arangod/Actions/RestActionHandler.h index f682ee47ba..e65dd7366a 100644 --- a/arangod/Actions/RestActionHandler.h +++ b/arangod/Actions/RestActionHandler.h @@ -74,7 +74,7 @@ class RestActionHandler : public RestVocbaseBaseHandler { /// @brief data lock ////////////////////////////////////////////////////////////////////////////// - basics::Mutex _dataLock; + Mutex _dataLock; ////////////////////////////////////////////////////////////////////////////// /// @brief data for cancelation diff --git a/arangod/Actions/actions.h b/arangod/Actions/actions.h index d2b96b076b..a6f2ee51dd 100644 --- a/arangod/Actions/actions.h +++ b/arangod/Actions/actions.h @@ -76,10 +76,10 @@ class TRI_action_t { virtual TRI_action_result_t execute(TRI_vocbase_t*, arangodb::rest::HttpRequest*, - arangodb::basics::Mutex* dataLock, + arangodb::Mutex* dataLock, void** data) = 0; - virtual bool cancel(arangodb::basics::Mutex* dataLock, void** data) = 0; + virtual bool cancel(arangodb::Mutex* dataLock, void** data) = 0; std::string _type; std::string _url; diff --git a/arangod/Aql/Optimizer.cpp b/arangod/Aql/Optimizer.cpp index 872916f132..5f8467d184 100644 --- a/arangod/Aql/Optimizer.cpp +++ b/arangod/Aql/Optimizer.cpp @@ -28,7 +28,7 @@ using namespace arangodb::aql; -arangodb::basics::Mutex Optimizer::SetupLock; +arangodb::Mutex Optimizer::SetupLock; //////////////////////////////////////////////////////////////////////////////// // @brief list of all rules diff --git a/arangod/Aql/Optimizer.h b/arangod/Aql/Optimizer.h index 31aa0d4a5a..b11eb99876 100644 --- a/arangod/Aql/Optimizer.h +++ b/arangod/Aql/Optimizer.h @@ -609,7 +609,7 @@ class Optimizer { /// @brief mutex to protect rule setup ////////////////////////////////////////////////////////////////////////////// - static arangodb::basics::Mutex SetupLock; + static arangodb::Mutex SetupLock; ////////////////////////////////////////////////////////////////////////////// /// @brief the current set of plans to be optimized diff --git a/arangod/Aql/QueryCache.h b/arangod/Aql/QueryCache.h index ba5e9783d0..b7b55d70d3 100644 --- a/arangod/Aql/QueryCache.h +++ b/arangod/Aql/QueryCache.h @@ -359,7 +359,7 @@ class QueryCache { /// @brief protect mode changes with a mutex ////////////////////////////////////////////////////////////////////////////// - arangodb::basics::Mutex _propertiesLock; + arangodb::Mutex _propertiesLock; ////////////////////////////////////////////////////////////////////////////// /// @brief read-write lock for the cache diff --git a/arangod/Aql/tokens.cpp b/arangod/Aql/tokens.cpp index 9c2e299dd0..f8739f3166 100644 --- a/arangod/Aql/tokens.cpp +++ b/arangod/Aql/tokens.cpp @@ -162,15 +162,7 @@ typedef void* yyscan_t; /* Size of default input buffer. */ #ifndef YY_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k. - * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. - * Ditto for the __ia64__ case accordingly. - */ -#define YY_BUF_SIZE 32768 -#else #define YY_BUF_SIZE 16384 -#endif /* __ia64__ */ #endif /* The state buf must be large enough to hold one state per character in the main buffer. @@ -853,12 +845,7 @@ static int input (yyscan_t yyscanner ); /* Amount of stuff to slurp up with each read. */ #ifndef YY_READ_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k */ -#define YY_READ_BUF_SIZE 16384 -#else #define YY_READ_BUF_SIZE 8192 -#endif /* __ia64__ */ #endif /* Copy whatever the last rule matched to the standard output. */ diff --git a/arangod/Cluster/ClusterInfo.h b/arangod/Cluster/ClusterInfo.h index a70e75c31d..b4427ee6b4 100644 --- a/arangod/Cluster/ClusterInfo.h +++ b/arangod/Cluster/ClusterInfo.h @@ -886,7 +886,7 @@ class ClusterInfo { struct ProtectionData { std::atomic isValid; - arangodb::basics::Mutex mutex; + arangodb::Mutex mutex; std::atomic version; arangodb::basics::ReadWriteLock lock; @@ -962,7 +962,7 @@ class ClusterInfo { /// @brief lock for uniqid sequence ////////////////////////////////////////////////////////////////////////////// - arangodb::basics::Mutex _idLock; + arangodb::Mutex _idLock; ////////////////////////////////////////////////////////////////////////////// /// @brief the sole instance diff --git a/arangod/Cluster/HeartbeatThread.h b/arangod/Cluster/HeartbeatThread.h index f844e41ad8..70ede02b0a 100644 --- a/arangod/Cluster/HeartbeatThread.h +++ b/arangod/Cluster/HeartbeatThread.h @@ -197,7 +197,7 @@ class HeartbeatThread : public basics::Thread { /// @brief status lock ////////////////////////////////////////////////////////////////////////////// - arangodb::basics::Mutex _statusLock; + arangodb::Mutex _statusLock; ////////////////////////////////////////////////////////////////////////////// /// @brief AgencyComm instance diff --git a/arangod/Cluster/ServerJob.cpp b/arangod/Cluster/ServerJob.cpp index d232a270a6..7a58428822 100644 --- a/arangod/Cluster/ServerJob.cpp +++ b/arangod/Cluster/ServerJob.cpp @@ -36,7 +36,7 @@ using namespace arangodb; using namespace arangodb::rest; -static arangodb::basics::Mutex ExecutorLock; +static arangodb::Mutex ExecutorLock; //////////////////////////////////////////////////////////////////////////////// /// @brief constructs a new db server job diff --git a/arangod/Cluster/ServerJob.h b/arangod/Cluster/ServerJob.h index 2d46505f01..fd7af6e559 100644 --- a/arangod/Cluster/ServerJob.h +++ b/arangod/Cluster/ServerJob.h @@ -122,7 +122,7 @@ class ServerJob : public arangodb::rest::Job { /// @brief server is dead lock ////////////////////////////////////////////////////////////////////////////// - basics::Mutex _abandonLock; + Mutex _abandonLock; ////////////////////////////////////////////////////////////////////////////// /// @brief server is dead diff --git a/arangod/Dispatcher/DispatcherQueue.h b/arangod/Dispatcher/DispatcherQueue.h index befb7e3b16..ad7f8e82df 100644 --- a/arangod/Dispatcher/DispatcherQueue.h +++ b/arangod/Dispatcher/DispatcherQueue.h @@ -189,7 +189,7 @@ class DispatcherQueue { /// @brief guard for hazard pointer ////////////////////////////////////////////////////////////////////////////// - basics::Mutex _hazardLock; + Mutex _hazardLock; ////////////////////////////////////////////////////////////////////////////// /// @brief hazard pointer for jobs @@ -207,7 +207,7 @@ class DispatcherQueue { /// @brief guard for _startedThreads ////////////////////////////////////////////////////////////////////////////// - basics::Mutex _threadsLock; + Mutex _threadsLock; ////////////////////////////////////////////////////////////////////////////// /// @brief list of started threads diff --git a/arangod/HttpServer/HttpServer.h b/arangod/HttpServer/HttpServer.h index 912dcf1b3e..7afb00b170 100644 --- a/arangod/HttpServer/HttpServer.h +++ b/arangod/HttpServer/HttpServer.h @@ -244,7 +244,7 @@ class HttpServer : protected TaskManager { /// @brief mutex for comm tasks ////////////////////////////////////////////////////////////////////////////// - arangodb::basics::Mutex _commTasksLock; + arangodb::Mutex _commTasksLock; ////////////////////////////////////////////////////////////////////////////// /// @brief active comm tasks diff --git a/arangod/RestHandler/RestCursorHandler.h b/arangod/RestHandler/RestCursorHandler.h index 4f85b003a8..488c6646f0 100644 --- a/arangod/RestHandler/RestCursorHandler.h +++ b/arangod/RestHandler/RestCursorHandler.h @@ -150,7 +150,7 @@ class RestCursorHandler : public RestVocbaseBaseHandler { /// @brief lock for currently running query ////////////////////////////////////////////////////////////////////////////// - arangodb::basics::Mutex _queryLock; + Mutex _queryLock; ////////////////////////////////////////////////////////////////////////////// /// @brief currently running query diff --git a/arangod/RestHandler/RestSimpleHandler.h b/arangod/RestHandler/RestSimpleHandler.h index d09cff7b86..2a067cfcd7 100644 --- a/arangod/RestHandler/RestSimpleHandler.h +++ b/arangod/RestHandler/RestSimpleHandler.h @@ -106,7 +106,7 @@ class RestSimpleHandler : public RestVocbaseBaseHandler { /// @brief lock for currently running query ////////////////////////////////////////////////////////////////////////////// - arangodb::basics::Mutex _queryLock; + Mutex _queryLock; ////////////////////////////////////////////////////////////////////////////// /// @brief currently running query diff --git a/arangod/RestServer/ConsoleThread.h b/arangod/RestServer/ConsoleThread.h index a867921fa4..c02e986a20 100644 --- a/arangod/RestServer/ConsoleThread.h +++ b/arangod/RestServer/ConsoleThread.h @@ -59,7 +59,7 @@ class ConsoleThread : public basics::Thread { /// @brief mutex for console access ////////////////////////////////////////////////////////////////////////////// - static arangodb::basics::Mutex serverConsoleMutex; + static arangodb::Mutex serverConsoleMutex; public: ConsoleThread(arangodb::rest::ApplicationServer*, ApplicationV8*, diff --git a/arangod/RestServer/VocbaseContext.cpp b/arangod/RestServer/VocbaseContext.cpp index 01ebf0f492..98e3df6be2 100644 --- a/arangod/RestServer/VocbaseContext.cpp +++ b/arangod/RestServer/VocbaseContext.cpp @@ -39,7 +39,7 @@ using namespace arangodb::rest; /// @brief sid lock //////////////////////////////////////////////////////////////////////////////// -static arangodb::basics::Mutex SidLock; +static arangodb::Mutex SidLock; //////////////////////////////////////////////////////////////////////////////// /// @brief sid cache diff --git a/arangod/Scheduler/ListenTask.h b/arangod/Scheduler/ListenTask.h index f061756df0..ecb8f5eb7e 100644 --- a/arangod/Scheduler/ListenTask.h +++ b/arangod/Scheduler/ListenTask.h @@ -126,7 +126,7 @@ class ListenTask : virtual public Task { size_t _acceptFailures; - mutable basics::Mutex _changeLock; + mutable Mutex _changeLock; }; } } diff --git a/arangod/Scheduler/Scheduler.h b/arangod/Scheduler/Scheduler.h index 7f0276368b..934bded2ee 100644 --- a/arangod/Scheduler/Scheduler.h +++ b/arangod/Scheduler/Scheduler.h @@ -358,7 +358,7 @@ class Scheduler : private TaskManager { /// @brief lock for scheduler threads ////////////////////////////////////////////////////////////////////////////// - basics::Mutex schedulerLock; + Mutex schedulerLock; ////////////////////////////////////////////////////////////////////////////// /// @brief tasks to thread diff --git a/arangod/Scheduler/SchedulerThread.h b/arangod/Scheduler/SchedulerThread.h index 3f98e4bd91..d0f033f43f 100644 --- a/arangod/Scheduler/SchedulerThread.h +++ b/arangod/Scheduler/SchedulerThread.h @@ -159,7 +159,7 @@ class SchedulerThread : public basics::Thread, private TaskManager { /// @brief queue lock //////////////////////////////////////////////////////////////////////////////// - arangodb::basics::Mutex _queueLock; + Mutex _queueLock; ////////////////////////////////////////////////////////////////////////////// /// @brief work queue diff --git a/arangod/Scheduler/SignalTask.h b/arangod/Scheduler/SignalTask.h index e60a39f8c2..1ffa35be87 100644 --- a/arangod/Scheduler/SignalTask.h +++ b/arangod/Scheduler/SignalTask.h @@ -96,7 +96,7 @@ class SignalTask : virtual public Task { private: std::set _signals; - basics::Mutex _changeLock; + Mutex _changeLock; }; } } diff --git a/arangod/Statistics/statistics.cpp b/arangod/Statistics/statistics.cpp index 0cdaa4265b..a170f2978a 100644 --- a/arangod/Statistics/statistics.cpp +++ b/arangod/Statistics/statistics.cpp @@ -37,7 +37,7 @@ static size_t const QUEUE_SIZE = 1000; /// @brief lock for request statistics data //////////////////////////////////////////////////////////////////////////////// -static arangodb::basics::Mutex RequestDataLock; +static arangodb::Mutex RequestDataLock; //////////////////////////////////////////////////////////////////////////////// /// @brief the request statistics queue @@ -196,7 +196,7 @@ void TRI_FillRequestStatistics(StatisticsDistribution& totalTime, /// @brief lock for connection data //////////////////////////////////////////////////////////////////////////////// -static arangodb::basics::Mutex ConnectionDataLock; +static arangodb::Mutex ConnectionDataLock; //////////////////////////////////////////////////////////////////////////////// /// @brief free list diff --git a/arangod/Utils/CollectionKeysRepository.h b/arangod/Utils/CollectionKeysRepository.h index 4cb3f6b8d9..d56e99403f 100644 --- a/arangod/Utils/CollectionKeysRepository.h +++ b/arangod/Utils/CollectionKeysRepository.h @@ -93,7 +93,7 @@ class CollectionKeysRepository { /// @brief mutex for the repository ////////////////////////////////////////////////////////////////////////////// - arangodb::basics::Mutex _lock; + Mutex _lock; ////////////////////////////////////////////////////////////////////////////// /// @brief list of current keys diff --git a/arangod/Utils/CursorRepository.h b/arangod/Utils/CursorRepository.h index 96510e86e6..b974361ab9 100644 --- a/arangod/Utils/CursorRepository.h +++ b/arangod/Utils/CursorRepository.h @@ -111,7 +111,7 @@ class CursorRepository { /// @brief mutex for the cursors repository ////////////////////////////////////////////////////////////////////////////// - arangodb::basics::Mutex _lock; + Mutex _lock; ////////////////////////////////////////////////////////////////////////////// /// @brief list of current cursors diff --git a/arangod/V8Server/ApplicationV8.h b/arangod/V8Server/ApplicationV8.h index 5fc4912379..d284578232 100644 --- a/arangod/V8Server/ApplicationV8.h +++ b/arangod/V8Server/ApplicationV8.h @@ -229,7 +229,7 @@ class ApplicationV8 : public rest::ApplicationFeature { /// @brief mutex to protect _globalMethods //////////////////////////////////////////////////////////////////////////////// - basics::Mutex _globalMethodsLock; + Mutex _globalMethodsLock; //////////////////////////////////////////////////////////////////////////////// /// @brief open global methods diff --git a/arangod/VocBase/Ditch.h b/arangod/VocBase/Ditch.h index 4d20ee2dfb..d2e90a2ec3 100644 --- a/arangod/VocBase/Ditch.h +++ b/arangod/VocBase/Ditch.h @@ -421,7 +421,7 @@ class Ditches { private: struct TRI_document_collection_t* _collection; - arangodb::basics::Mutex _lock; + arangodb::Mutex _lock; Ditch* _begin; Ditch* _end; uint64_t _numDocumentDitches; diff --git a/arangod/VocBase/KeyGenerator.h b/arangod/VocBase/KeyGenerator.h index 70ee810d20..731ee95b58 100644 --- a/arangod/VocBase/KeyGenerator.h +++ b/arangod/VocBase/KeyGenerator.h @@ -244,7 +244,7 @@ class AutoIncrementKeyGenerator : public KeyGenerator { virtual void toVelocyPack(arangodb::velocypack::Builder&) const override; private: - arangodb::basics::Mutex _lock; + arangodb::Mutex _lock; uint64_t _lastValue; // last value assigned diff --git a/arangod/VocBase/VocShaper.h b/arangod/VocBase/VocShaper.h index 6cc779e924..21734606a4 100644 --- a/arangod/VocBase/VocShaper.h +++ b/arangod/VocBase/VocShaper.h @@ -154,7 +154,7 @@ class VocShaper : public Shaper { TRI_document_collection_t* _collection; // attribute paths - arangodb::basics::Mutex _attributePathsCreateLock; + arangodb::Mutex _attributePathsCreateLock; arangodb::basics::ReadWriteLock _attributePathsByNameLock; TRI_associative_pointer_t _attributePathsByName; @@ -163,7 +163,7 @@ class VocShaper : public Shaper { TRI_associative_pointer_t _attributePathsByPid; // attributes - arangodb::basics::Mutex _attributeCreateLock; + arangodb::Mutex _attributeCreateLock; arangodb::basics::ReadWriteLock _attributeNamesLock; TRI_associative_pointer_t _attributeNames; @@ -172,7 +172,7 @@ class VocShaper : public Shaper { TRI_associative_pointer_t _attributeIds; // shapes - arangodb::basics::Mutex _shapeCreateLock; + arangodb::Mutex _shapeCreateLock; arangodb::basics::ReadWriteLock _shapeDictionaryLock; TRI_associative_pointer_t _shapeDictionary; diff --git a/arangod/VocBase/document-collection.h b/arangod/VocBase/document-collection.h index 5cb4c00950..729781b71c 100644 --- a/arangod/VocBase/document-collection.h +++ b/arangod/VocBase/document-collection.h @@ -248,7 +248,7 @@ struct TRI_document_collection_t : public TRI_collection_t { private: VocShaper* _shaper; - arangodb::basics::Mutex _compactionStatusLock; + arangodb::Mutex _compactionStatusLock; size_t _nextCompactionStartIndex; char const* _lastCompactionStatus; char _lastCompactionStamp[21]; diff --git a/arangod/VocBase/server.cpp b/arangod/VocBase/server.cpp index d0b8acff09..1cd0a379c8 100644 --- a/arangod/VocBase/server.cpp +++ b/arangod/VocBase/server.cpp @@ -73,7 +73,7 @@ size_t PageSize; /// @brief lock for serializing the creation of database //////////////////////////////////////////////////////////////////////////////// -static arangodb::basics::Mutex DatabaseCreateLock; +static arangodb::Mutex DatabaseCreateLock; //////////////////////////////////////////////////////////////////////////////// /// @brief variable protecting the server shutdown diff --git a/arangod/VocBase/server.h b/arangod/VocBase/server.h index 65821fc356..4d69f6ec51 100644 --- a/arangod/VocBase/server.h +++ b/arangod/VocBase/server.h @@ -65,7 +65,7 @@ struct TRI_server_t { // TODO: Make this again a template once everybody has gcc >= 4.9.2 // arangodb::basics::DataProtector<64> arangodb::basics::DataProtector _databasesProtector; - arangodb::basics::Mutex _databasesMutex; + arangodb::Mutex _databasesMutex; TRI_thread_t _databaseManager; diff --git a/arangod/Wal/CollectorThread.h b/arangod/Wal/CollectorThread.h index 1a2a900ccf..18cf0544d1 100644 --- a/arangod/Wal/CollectorThread.h +++ b/arangod/Wal/CollectorThread.h @@ -360,7 +360,7 @@ class CollectorThread : public basics::Thread { /// @brief operations lock ////////////////////////////////////////////////////////////////////////////// - arangodb::basics::Mutex _operationsQueueLock; + arangodb::Mutex _operationsQueueLock; ////////////////////////////////////////////////////////////////////////////// /// @brief operations to collect later diff --git a/arangod/Wal/LogfileManager.h b/arangod/Wal/LogfileManager.h index ecd68a95b9..ba79634489 100644 --- a/arangod/Wal/LogfileManager.h +++ b/arangod/Wal/LogfileManager.h @@ -886,7 +886,7 @@ class LogfileManager : public rest::ApplicationFeature { /// @brief a lock protecting the shutdown file ////////////////////////////////////////////////////////////////////////////// - basics::Mutex _shutdownFileLock; + Mutex _shutdownFileLock; ////////////////////////////////////////////////////////////////////////////// /// @brief a lock protecting _transactions and _failedTransactions @@ -926,7 +926,7 @@ class LogfileManager : public rest::ApplicationFeature { /// and _lastOpenedId ////////////////////////////////////////////////////////////////////////////// - basics::Mutex _idLock; + Mutex _idLock; ////////////////////////////////////////////////////////////////////////////// /// @brief whether or not write-throttling is currently enabled diff --git a/arangod/Wal/Slots.h b/arangod/Wal/Slots.h index 0005531a6f..b23c67bc75 100644 --- a/arangod/Wal/Slots.h +++ b/arangod/Wal/Slots.h @@ -208,7 +208,7 @@ class Slots { /// @brief mutex protecting the slots interface ////////////////////////////////////////////////////////////////////////////// - basics::Mutex _lock; + Mutex _lock; ////////////////////////////////////////////////////////////////////////////// /// @brief all slots diff --git a/arangosh/Benchmark/BenchmarkCounter.h b/arangosh/Benchmark/BenchmarkCounter.h index b6e1eaf866..be18a23dce 100644 --- a/arangosh/Benchmark/BenchmarkCounter.h +++ b/arangosh/Benchmark/BenchmarkCounter.h @@ -146,7 +146,7 @@ class BenchmarkCounter { /// @brief mutex protecting the counter ////////////////////////////////////////////////////////////////////////////// - arangodb::basics::Mutex _mutex; + arangodb::Mutex _mutex; ////////////////////////////////////////////////////////////////////////////// /// @brief the current value diff --git a/lib/Basics/AssocMulti.h b/lib/Basics/AssocMulti.h index 1d306abd84..db3e6d4a73 100644 --- a/lib/Basics/AssocMulti.h +++ b/lib/Basics/AssocMulti.h @@ -387,7 +387,7 @@ class AssocMulti { typedef std::vector> DocumentsPerBucket; - arangodb::basics::Mutex bucketMapLocker; + arangodb::Mutex bucketMapLocker; std::unordered_map> allBuckets; diff --git a/lib/Basics/AssocUnique.h b/lib/Basics/AssocUnique.h index cad83186d5..a7909c7684 100644 --- a/lib/Basics/AssocUnique.h +++ b/lib/Basics/AssocUnique.h @@ -595,7 +595,7 @@ class AssocUnique { size_t const chunkSize = elements.size() / numThreads; typedef std::vector> DocumentsPerBucket; - arangodb::basics::Mutex bucketMapLocker; + arangodb::Mutex bucketMapLocker; std::unordered_map> allBuckets; diff --git a/lib/Basics/DeadlockDetector.h b/lib/Basics/DeadlockDetector.h index 29da928db5..fe2d4e7673 100644 --- a/lib/Basics/DeadlockDetector.h +++ b/lib/Basics/DeadlockDetector.h @@ -152,7 +152,7 @@ class DeadlockDetector { /// @brief lock for managing the readers ////////////////////////////////////////////////////////////////////////////// - arangodb::basics::Mutex _readersLock; + arangodb::Mutex _readersLock; ////////////////////////////////////////////////////////////////////////////// /// @brief readers that are blocked on writers diff --git a/lib/Basics/Mutex.cpp b/lib/Basics/Mutex.cpp index 919af65e6f..a4e7f69dfb 100644 --- a/lib/Basics/Mutex.cpp +++ b/lib/Basics/Mutex.cpp @@ -24,28 +24,85 @@ #include "Mutex.h" -using namespace arangodb::basics; +#include "Basics/logging.h" + +using namespace arangodb; //////////////////////////////////////////////////////////////////////////////// /// @brief constructs a mutex //////////////////////////////////////////////////////////////////////////////// -Mutex::Mutex() : _mutex() { TRI_InitMutex(&_mutex); } +#ifdef TRI_HAVE_POSIX_THREADS + +Mutex::Mutex() : _mutex() { pthread_mutex_init(&_mutex, nullptr); } + +#endif + +#ifdef TRI_HAVE_WIN32_THREADS + +Mutex::Mutex() : _mutex() { InitializeSRWLock(&_mutex); } + +#endif //////////////////////////////////////////////////////////////////////////////// /// @brief deletes the mutex //////////////////////////////////////////////////////////////////////////////// -Mutex::~Mutex() { TRI_DestroyMutex(&_mutex); } +#ifdef TRI_HAVE_POSIX_THREADS + +Mutex::~Mutex() { pthread_mutex_destroy(&_mutex); } + +#endif + +#ifdef TRI_HAVE_WIN32_THREADS + +Mutex::~Mutex() {} +#endif //////////////////////////////////////////////////////////////////////////////// /// @brief acquires the lock //////////////////////////////////////////////////////////////////////////////// -void Mutex::lock() { TRI_LockMutex(&_mutex); } +#ifdef TRI_HAVE_POSIX_THREADS + +void Mutex::lock() { + int rc = pthread_mutex_lock(&_mutex); + + if (rc != 0) { + if (rc == EDEADLK) { + LOG_ERROR("mutex deadlock detected"); + } + + LOG_FATAL_AND_EXIT("could not lock the mutex: %s", strerror(rc)); + } +} + +#endif + +#ifdef TRI_HAVE_WIN32_THREADS + +void Mutex::lock() { AcquireSRWLockExclusive(&_mutex); } + +#endif //////////////////////////////////////////////////////////////////////////////// /// @brief releases the lock //////////////////////////////////////////////////////////////////////////////// -void Mutex::unlock() { TRI_UnlockMutex(&_mutex); } +#ifdef TRI_HAVE_POSIX_THREADS + +void Mutex::unlock() { + int rc = pthread_mutex_unlock(&_mutex); + + if (rc != 0) { + LOG_FATAL_AND_EXIT("could not release the mutex: %s", strerror(rc)); + } +} + +#endif + +#ifdef TRI_HAVE_WIN32_THREADS + +void Mutex::unlock() { ReleaseSRWLockExclusive(&_mutex); } + +#endif diff --git a/lib/Basics/Mutex.h b/lib/Basics/Mutex.h index 3d7e042737..09b3a99978 100644 --- a/lib/Basics/Mutex.h +++ b/lib/Basics/Mutex.h @@ -26,10 +26,8 @@ #define LIB_BASICS_MUTEX_H 1 #include "Basics/Common.h" -#include "Basics/locks.h" namespace arangodb { -namespace basics { //////////////////////////////////////////////////////////////////////////////// /// @brief mutex @@ -67,13 +65,24 @@ class Mutex { void unlock(); private: +#ifdef TRI_HAVE_POSIX_THREADS ////////////////////////////////////////////////////////////////////////////// - /// @brief mutex variable + /// @brief pthread mutex ////////////////////////////////////////////////////////////////////////////// - TRI_mutex_t _mutex; + pthread_mutex_t _mutex; +#endif + +#ifdef TRI_HAVE_WIN32_THREADS + ////////////////////////////////////////////////////////////////////////////// + /// @brief SRWLocks + /// + /// as of VS2013, exclusive SRWLocks tend to be faster than native mutexes + ////////////////////////////////////////////////////////////////////////////// + + SRWLOCK _mutex; +#endif }; } -} #endif diff --git a/lib/Basics/Nonce.cpp b/lib/Basics/Nonce.cpp index c996790d19..93ddd8e58a 100644 --- a/lib/Basics/Nonce.cpp +++ b/lib/Basics/Nonce.cpp @@ -32,12 +32,9 @@ #include "Basics/StringUtils.h" using namespace std; +using namespace arangodb; using namespace arangodb::basics; -// ----------------------------------------------------------------------------- -// statistic nonce buffer -// ----------------------------------------------------------------------------- - namespace { Mutex MutexNonce; @@ -45,48 +42,21 @@ size_t SizeNonces = 16777216; uint32_t* TimestampNonces = 0; -uint32_t StatisticsNonces[32][5] = {{0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0}}; +uint32_t StatisticsNonces[32][5] = { + {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}}; } namespace arangodb { namespace basics { namespace Nonce { -// ----------------------------------------------------------------------------- -// static functions -// ----------------------------------------------------------------------------- - void create(size_t size) { if (SizeNonces < 64) { SizeNonces = 64; diff --git a/lib/Basics/RandomGenerator.cpp b/lib/Basics/RandomGenerator.cpp index a8aecf4eff..8ea2f70cab 100644 --- a/lib/Basics/RandomGenerator.cpp +++ b/lib/Basics/RandomGenerator.cpp @@ -33,6 +33,7 @@ #include using namespace std; +using namespace arangodb; using namespace arangodb::basics; // ----------------------------------------------------------------------------- diff --git a/lib/Basics/logging.cpp b/lib/Basics/logging.cpp index d9f2c8bff2..693aed0f37 100644 --- a/lib/Basics/logging.cpp +++ b/lib/Basics/logging.cpp @@ -35,12 +35,13 @@ #endif #include "Basics/Exceptions.h" -#include "Basics/files.h" -#include "Basics/hashes.h" #include "Basics/Mutex.h" #include "Basics/MutexLocker.h" -#include "Basics/shell-colors.h" #include "Basics/Thread.h" +#include "Basics/files.h" +#include "Basics/hashes.h" +#include "Basics/locks.h" +#include "Basics/shell-colors.h" #include "Basics/tri-strings.h" #include "Basics/vector.h" @@ -173,7 +174,7 @@ static std::vector Appenders; /// @brief log appenders //////////////////////////////////////////////////////////////////////////////// -static arangodb::basics::Mutex AppendersLock; +static arangodb::Mutex AppendersLock; //////////////////////////////////////////////////////////////////////////////// /// @brief maximal output length @@ -215,7 +216,7 @@ static TRI_log_buffer_t BufferOutput[OUTPUT_LOG_LEVELS][OUTPUT_BUFFER_SIZE]; /// @brief buffer lock //////////////////////////////////////////////////////////////////////////////// -static arangodb::basics::Mutex BufferLock; +static arangodb::Mutex BufferLock; //////////////////////////////////////////////////////////////////////////////// /// @brief condition variable for the logger @@ -227,7 +228,7 @@ static TRI_condition_t LogCondition; /// @brief message queue lock //////////////////////////////////////////////////////////////////////////////// -static arangodb::basics::Mutex LogMessageQueueLock; +static arangodb::Mutex LogMessageQueueLock; //////////////////////////////////////////////////////////////////////////////// /// @brief message queue @@ -1496,7 +1497,7 @@ struct log_appender_syslog_t : public TRI_log_appender_t { char const* typeName() override final { return "syslog"; } private: - arangodb::basics::Mutex _lock; + arangodb::Mutex _lock; bool _opened; }; diff --git a/lib/Basics/process-utils.cpp b/lib/Basics/process-utils.cpp index c803b03878..fae88a0a74 100644 --- a/lib/Basics/process-utils.cpp +++ b/lib/Basics/process-utils.cpp @@ -183,7 +183,7 @@ static std::vector ExternalProcesses; /// @brief lock for protected access to vector ExternalProcesses //////////////////////////////////////////////////////////////////////////////// -static arangodb::basics::Mutex ExternalProcessesLock; +static arangodb::Mutex ExternalProcessesLock; //////////////////////////////////////////////////////////////////////////////// /// @brief creates pipe pair diff --git a/lib/Utilities/ScriptLoader.h b/lib/Utilities/ScriptLoader.h index 07a3330d67..9c6037c1c0 100644 --- a/lib/Utilities/ScriptLoader.h +++ b/lib/Utilities/ScriptLoader.h @@ -98,7 +98,7 @@ class ScriptLoader { /// @brief mutex for _scripts ////////////////////////////////////////////////////////////////////////////// - basics::Mutex _lock; + Mutex _lock; }; } From 7a11220accc22104238c91c341a8e05b78794af5 Mon Sep 17 00:00:00 2001 From: Frank Celler Date: Wed, 27 Jan 2016 16:17:17 +0100 Subject: [PATCH 2/2] fixed missing namespace --- lib/Basics/MutexLocker.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Basics/MutexLocker.cpp b/lib/Basics/MutexLocker.cpp index 45aa729ca2..ac6e28f2ec 100644 --- a/lib/Basics/MutexLocker.cpp +++ b/lib/Basics/MutexLocker.cpp @@ -28,6 +28,7 @@ #include "Basics/logging.h" #endif +using namespace arangodb; using namespace arangodb::basics; ////////////////////////////////////////////////////////////////////////////////