Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace use of boost::mutex #6411

Merged
merged 1 commit into from Nov 17, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 2 additions & 4 deletions CondFormats/PhysicsToolsObjects/src/MVAComputer.cc
Expand Up @@ -21,7 +21,7 @@
#include <cstring>
#include <cstddef>

#include <boost/thread.hpp>
#include <atomic>

#include <Reflex/Reflex.h>

Expand Down Expand Up @@ -129,10 +129,8 @@ std::string ProcExternal::getInstanceName() const

static MVAComputer::CacheId getNextMVAComputerCacheId()
{
static boost::mutex mutex;
static MVAComputer::CacheId nextCacheId = 0;
static std::atomic<MVAComputer::CacheId> nextCacheId{0};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An atomic is much more performant.


boost::mutex::scoped_lock scoped_lock(mutex);
return ++nextCacheId;
}

Expand Down
8 changes: 4 additions & 4 deletions PhysicsTools/MVAComputer/src/AtomicId.cc
Expand Up @@ -4,7 +4,7 @@
#include <cstring>
#include <set>

#include <boost/thread.hpp>
#include <mutex>

#include "PhysicsTools/MVAComputer/interface/AtomicId.h"

Expand All @@ -25,7 +25,7 @@ namespace { // anonymous

IdSet idSet;
static std::allocator<char> stringAllocator;
mutable boost::mutex mutex;
mutable std::mutex mutex;
};
} // anonymous namespace

Expand All @@ -41,7 +41,7 @@ IdCache::~IdCache()

const char *IdCache::findOrInsert(const char *string) throw()
{
boost::mutex::scoped_lock scoped_lock(mutex);
std::lock_guard<std::mutex> scoped_lock(mutex);

IdSet::iterator pos = idSet.lower_bound(string);
if (pos != idSet.end() && std::strcmp(*pos, string) == 0)
Expand All @@ -60,7 +60,7 @@ namespace PhysicsTools {

static IdCache &getAtomicIdCache()
{
static IdCache atomicIdCache;
[[cms::thread_safe]] static IdCache atomicIdCache;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This just tells the static analyzer that this variable has been checked by hand and was declared thread safe. The regular compiler will just ignore these new C++11 annotations.

return atomicIdCache;
}

Expand Down