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

Made LockService thread safe #1219

Merged
merged 1 commit into from Oct 30, 2013
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
52 changes: 16 additions & 36 deletions FWCore/Services/src/LockService.cc
Expand Up @@ -2,6 +2,9 @@
#include "DataFormats/Provenance/interface/ModuleDescription.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"
#include "FWCore/ServiceRegistry/interface/ModuleCallingContext.h"
#include "FWCore/Utilities/interface/DebugMacros.h"
#include "FWCore/Utilities/interface/GlobalMutex.h"

Expand All @@ -13,22 +16,16 @@ using namespace edm::rootfix;
LockService::LockService(ParameterSet const& iPS,
ActivityRegistry& reg):
lock_(*getGlobalMutex()),
locker_(),
labels_(iPS.getUntrackedParameter<Labels>("labels")),
lockSources_(iPS.getUntrackedParameter<bool>("lockSources")) {
reg.watchPreSourceConstruction(this,&LockService::preSourceConstruction);
reg.watchPostSourceConstruction(this,&LockService::postSourceConstruction);

// reg.watchPostBeginJob(this,&LockService::postBeginJob);
// reg.watchPostEndJob(this,&LockService::postEndJob);

// reg.watchPreProcessEvent(this,&LockService::preEventProcessing);
// reg.watchPostProcessEvent(this,&LockService::postEventProcessing);
reg.watchPreSource(this,&LockService::preSource);
reg.watchPostSource(this,&LockService::postSource);

reg.watchPreModule(this,&LockService::preModule);
reg.watchPostModule(this,&LockService::postModule);
reg.watchPreModuleEvent(this,&LockService::preModule);
reg.watchPostModuleEvent(this,&LockService::postModule);

FDEBUG(4) << "In LockServices" << std::endl;
}
Expand All @@ -48,50 +45,33 @@ void LockService::preSourceConstruction(ModuleDescription const& desc) {
if(!labels_.empty() &&
find(labels_.begin(), labels_.end(), desc.moduleLabel()) != labels_.end()) {
//search_all(labels_, desc.moduleLabel()))
FDEBUG(4) << "made a new locked in LockService" << std::endl;
locker_.reset(new boost::mutex::scoped_lock(lock_));
lock_.lock();
}
}

void LockService::postSourceConstruction(ModuleDescription const&) {
FDEBUG(4) << "destroyed a locked in LockService" << std::endl;
locker_.reset();
}

void LockService::postBeginJob() {
}

void LockService::postEndJob() {
}

void LockService::preEventProcessing(edm::EventID const&, edm::Timestamp const&) {
}

void LockService::postEventProcessing(Event const&, EventSetup const&) {
lock_.unlock();
}

void LockService::preSource() {
if(lockSources_) {
FDEBUG(4) << "made a new locked in LockService" << std::endl;
locker_.reset(new boost::mutex::scoped_lock(lock_));
lock_.lock();
}
}

void LockService::postSource() {
FDEBUG(4) << "destroyed a locked in LockService" << std::endl;
locker_.reset();
lock_.unlock();
}

void LockService::preModule(ModuleDescription const& desc) {
if(!labels_.empty() && find(labels_.begin(), labels_.end(), desc.moduleLabel()) != labels_.end()) {
//search_all(labels_, desc.moduleLabel()))
FDEBUG(4) << "made a new locked in LockService" << std::endl;
locker_.reset(new boost::mutex::scoped_lock(lock_));
void LockService::preModule(StreamContext const&, ModuleCallingContext const& iContext) {
if(!labels_.empty() && find(labels_.begin(), labels_.end(), iContext.moduleDescription()->moduleLabel()) != labels_.end()) {
lock_.lock();
}
}

void LockService::postModule(ModuleDescription const&) {
FDEBUG(4) << "destroyed a locked in LockService" << std::endl;
locker_.reset();
void LockService::postModule(StreamContext const&, ModuleCallingContext const& iContext) {
if(!labels_.empty() && find(labels_.begin(), labels_.end(), iContext.moduleDescription()->moduleLabel()) != labels_.end()) {
lock_.unlock();
}
}

20 changes: 7 additions & 13 deletions FWCore/Services/src/LockService.h
Expand Up @@ -16,15 +16,16 @@
any two threads running event processors.
*/

#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"

#include <string>
#include <vector>
#include "boost/shared_ptr.hpp"
#include "boost/thread/mutex.hpp"
namespace edm {
class ConfigurationDescriptions;
class ParameterSet;
class ActivityRegistry;
class ModuleDescription;
class StreamContext;
class ModuleCallingContext;

namespace rootfix {

Expand All @@ -38,25 +39,18 @@ namespace edm {

boost::mutex& getLock() { return lock_; }

void postBeginJob();
void postEndJob();

void preSourceConstruction(const edm::ModuleDescription&);
void postSourceConstruction(const edm::ModuleDescription&);

void preEventProcessing(const edm::EventID&, const edm::Timestamp&);
void postEventProcessing(const edm::Event&, const edm::EventSetup&);

void preSource();
void postSource();


void preModule(const edm::ModuleDescription&);
void postModule(const edm::ModuleDescription&);
void preModule(StreamContext const&, ModuleCallingContext const&);
void postModule(StreamContext const&, ModuleCallingContext const&);

private:
boost::mutex& lock_;
boost::shared_ptr<boost::mutex::scoped_lock> locker_; // what a hack!
typedef std::vector<std::string> Labels;
Labels labels_;
bool lockSources_;
Expand Down