Update cram_md5 to use synchronized. Review: https://reviews.apache.org/r/35099
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/51fca3f7 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/51fca3f7 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/51fca3f7 Branch: refs/heads/master Commit: 51fca3f7efa0fd8abd11c22d87092b13f2ba0318 Parents: 98039c9 Author: Joris Van Remoortere <[email protected]> Authored: Sat Jun 13 07:18:56 2015 -0700 Committer: Benjamin Hindman <[email protected]> Committed: Sun Jun 14 02:43:01 2015 -0700 ---------------------------------------------------------------------- src/authentication/cram_md5/auxprop.cpp | 5 +++-- src/authentication/cram_md5/auxprop.hpp | 25 +++++++++++++------------ 2 files changed, 16 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/51fca3f7/src/authentication/cram_md5/auxprop.cpp ---------------------------------------------------------------------- diff --git a/src/authentication/cram_md5/auxprop.cpp b/src/authentication/cram_md5/auxprop.cpp index 984ed90..abf0f8d 100644 --- a/src/authentication/cram_md5/auxprop.cpp +++ b/src/authentication/cram_md5/auxprop.cpp @@ -18,6 +18,8 @@ #include "authentication/cram_md5/auxprop.hpp" +#include <mutex> + #include "logging/logging.hpp" using std::list; @@ -30,8 +32,7 @@ namespace cram_md5 { // Storage for the static members. Multimap<string, Property> InMemoryAuxiliaryPropertyPlugin::properties; sasl_auxprop_plug_t InMemoryAuxiliaryPropertyPlugin::plugin; -pthread_mutex_t InMemoryAuxiliaryPropertyPlugin::mutex = - PTHREAD_MUTEX_INITIALIZER; +std::mutex InMemoryAuxiliaryPropertyPlugin::mutex; int InMemoryAuxiliaryPropertyPlugin::initialize( http://git-wip-us.apache.org/repos/asf/mesos/blob/51fca3f7/src/authentication/cram_md5/auxprop.hpp ---------------------------------------------------------------------- diff --git a/src/authentication/cram_md5/auxprop.hpp b/src/authentication/cram_md5/auxprop.hpp index 1a054ba..0fa87f4 100644 --- a/src/authentication/cram_md5/auxprop.hpp +++ b/src/authentication/cram_md5/auxprop.hpp @@ -19,8 +19,7 @@ #ifndef __AUTHENTICATION_CRAM_MD5_AUXPROP_HPP__ #define __AUTHENTICATION_CRAM_MD5_AUXPROP_HPP__ -#include <pthread.h> - +#include <mutex> #include <string> #include <sasl/sasl.h> @@ -30,8 +29,7 @@ #include <stout/multimap.hpp> #include <stout/none.hpp> #include <stout/option.hpp> - -#include "common/lock.hpp" +#include <stout/synchronized.hpp> namespace mesos { namespace internal { @@ -51,22 +49,25 @@ public: static void load(const Multimap<std::string, Property>& _properties) { - Lock lock(&mutex); - properties = _properties; + synchronized (mutex) { + properties = _properties; + } } static Option<std::list<std::string>> lookup( const std::string& user, const std::string& name) { - Lock lock(&mutex); - if (properties.contains(user)) { - foreach (const Property& property, properties.get(user)) { - if (property.name == name) { - return property.values; + synchronized (mutex) { + if (properties.contains(user)) { + foreach (const Property& property, properties.get(user)) { + if (property.name == name) { + return property.values; + } } } } + return None(); } @@ -98,7 +99,7 @@ private: // Access to 'properties' has to be protected as multiple // authenticator instances may be active concurrently. - static pthread_mutex_t mutex; + static std::mutex mutex; }; } // namespace cram_md5 {
