FWCore
SharedMemory
src
ControllerChannel.cc
Go to the documentation of this file.
1
// -*- C++ -*-
2
//
3
// Package: FWCore/SharedMemory
4
// Class : ControllerChannel
5
//
6
// Implementation:
7
// [Notes on implementation]
8
//
9
// Original Author: Chris Jones
10
// Created: 21/01/2020
11
//
12
13
// system include files
14
#include <cassert>
15
16
// user include files
17
#include "
FWCore/SharedMemory/interface/ControllerChannel.h
"
18
#include "
FWCore/SharedMemory/interface/channel_names.h
"
19
20
//
21
// constants, enums and typedefs
22
//
23
using namespace
edm::shared_memory
;
24
using namespace
boost::interprocess;
25
26
//
27
// static data member definitions
28
//
29
30
//
31
// constructors and destructor
32
//
33
34
ControllerChannel::ControllerChannel
(
std::string
const
& iName,
int
id
)
35
: id_{
id
},
36
smName_{uniqueName(iName)},
37
managed_sm_{open_or_create, smName_.c_str(), 1024},
38
toWorkerBufferInfo_{bufferInfo(
channel_names::kToWorkerBufferInfo
, managed_sm_)},
39
fromWorkerBufferInfo_{bufferInfo(
channel_names::kFromWorkerBufferInfo
, managed_sm_)},
40
mutex_{open_or_create, uniqueName(
channel_names::kMutex
).c_str()},
41
cndFromMain_{open_or_create, uniqueName(
channel_names::kConditionFromMain
).c_str()},
42
cndToMain_{open_or_create, uniqueName(
channel_names::kConditionToMain
).c_str()} {
43
managed_sm_.destroy<
bool
>(
channel_names::kStop
);
44
stop_ = managed_sm_.construct<
bool
>(
channel_names::kStop
)(
false
);
45
assert
(stop_);
46
keepEvent_ = managed_sm_.construct<
bool
>(
channel_names::kKeepEvent
)(
true
);
47
assert
(keepEvent_);
48
49
managed_sm_.destroy<
edm::Transition
>(
channel_names::kTransitionType
);
50
transitionType_ =
51
managed_sm_.construct<
edm::Transition
>(
channel_names::kTransitionType
)(
edm::Transition::NumberOfTransitions
);
52
assert
(transitionType_);
53
54
managed_sm_.destroy<
unsigned
long
long
>(
channel_names::kTransitionID
);
55
transitionID_ = managed_sm_.construct<
unsigned
long
long
>(
channel_names::kTransitionID
)(0);
56
assert
(transitionID_);
57
}
58
59
ControllerChannel::~ControllerChannel
() {
60
managed_sm_
.destroy<
bool
>(
channel_names::kKeepEvent
);
61
managed_sm_
.destroy<
bool
>(
channel_names::kStop
);
62
managed_sm_
.destroy<
unsigned
int
>(
channel_names::kTransitionType
);
63
managed_sm_
.destroy<
unsigned
long
long
>(
channel_names::kTransitionID
);
64
managed_sm_
.destroy<
BufferInfo
>(
channel_names::kToWorkerBufferInfo
);
65
managed_sm_
.destroy<
BufferInfo
>(
channel_names::kFromWorkerBufferInfo
);
66
67
named_mutex::remove
(
uniqueName
(
channel_names::kMutex
).c_str());
68
named_condition::remove
(
uniqueName
(
channel_names::kConditionFromMain
).c_str());
69
named_condition::remove
(
uniqueName
(
channel_names::kConditionToMain
).c_str());
70
}
71
72
//
73
// member functions
74
//
75
std::string
ControllerChannel::uniqueName
(
std::string
iBase)
const
{
76
auto
pid = getpid();
77
iBase += std::to_string(pid);
78
iBase +=
"_"
;
79
iBase += std::to_string(
id_
);
80
81
return
iBase;
82
}
83
84
bool
ControllerChannel::wait
(scoped_lock<named_mutex>&
lock
,
edm::Transition
iTrans,
unsigned
long
long
iTransID) {
85
*
transitionType_
= iTrans;
86
*
transitionID_
= iTransID;
87
//std::cout << id_ << " notifying" << std::endl;
88
cndFromMain_
.notify_all();
89
90
//std::cout << id_ << " waiting" << std::endl;
91
using namespace
boost::posix_time;
92
if
(not
cndToMain_
.timed_wait(
lock
, microsec_clock::universal_time() +
seconds
(60))) {
93
//std::cout << id_ << " waiting FAILED" << std::endl;
94
return
false
;
95
}
96
return
true
;
97
}
98
99
//
100
// const member functions
101
//
102
103
//
104
// static member functions
105
//
106
BufferInfo
*
ControllerChannel::bufferInfo
(
const
char
* iWhich, managed_shared_memory&
mem
) {
107
mem
.destroy<
BufferInfo
>(iWhich);
108
BufferInfo
*
v
=
mem
.construct<
BufferInfo
>(iWhich)();
109
return
v
;
110
}
edm::shared_memory::ControllerChannel::cndToMain_
boost::interprocess::named_condition cndToMain_
Definition:
ControllerChannel.h:126
edm::shared_memory::ControllerChannel::transitionType_
edm::Transition * transitionType_
Definition:
ControllerChannel.h:128
edm::shared_memory::ControllerChannel::managed_sm_
boost::interprocess::managed_shared_memory managed_sm_
Definition:
ControllerChannel.h:119
edm::shared_memory::channel_names::kToWorkerBufferInfo
constexpr char const *const kToWorkerBufferInfo
Definition:
channel_names.h:29
edm::shared_memory::channel_names::kFromWorkerBufferInfo
constexpr char const *const kFromWorkerBufferInfo
Definition:
channel_names.h:30
channel_names.h
edm::shared_memory::ControllerChannel::uniqueName
std::string uniqueName(std::string iBase) const
Definition:
ControllerChannel.cc:75
cms::cuda::assert
assert(be >=bs)
findQualityFiles.v
v
Definition:
findQualityFiles.py:179
edm::shared_memory::channel_names::kKeepEvent
constexpr char const *const kKeepEvent
Definition:
channel_names.h:35
mem
uint16_t mem[nChs][nEvts]
Definition:
recycleTccEmu.cc:13
edm::shared_memory::channel_names::kConditionToMain
constexpr char const *const kConditionToMain
Definition:
channel_names.h:33
edm::shared_memory::ControllerChannel::transitionID_
unsigned long long * transitionID_
Definition:
ControllerChannel.h:129
seconds
double seconds()
edm::shared_memory::BufferInfo
Definition:
BufferInfo.h:27
edm::shared_memory::ControllerChannel::cndFromMain_
boost::interprocess::named_condition cndFromMain_
Definition:
ControllerChannel.h:124
edm::Transition::NumberOfTransitions
edm::shared_memory::ControllerChannel::wait
bool wait(boost::interprocess::scoped_lock< boost::interprocess::named_mutex > &lock, edm::Transition iTrans, unsigned long long iTransID)
Definition:
ControllerChannel.cc:84
edm::shared_memory::channel_names::kTransitionID
constexpr char const *const kTransitionID
Definition:
channel_names.h:37
edm::shared_memory::ControllerChannel::bufferInfo
static BufferInfo * bufferInfo(const char *iWhich, boost::interprocess::managed_shared_memory &mem)
Definition:
ControllerChannel.cc:106
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition:
AlCaHLTBitMon_QueryRunRegistry.py:256
edm::shared_memory::ControllerChannel::id_
int id_
Definition:
ControllerChannel.h:117
edm::shared_memory::channel_names::kStop
constexpr char const *const kStop
Definition:
channel_names.h:34
ControllerChannel.h
edm::shared_memory::ControllerChannel::~ControllerChannel
~ControllerChannel()
Definition:
ControllerChannel.cc:59
edm::Transition
Transition
Definition:
Transition.h:12
CommonMethods.lock
def lock()
Definition:
CommonMethods.py:82
edm::shared_memory
Definition:
buffer_names.h:27
edm::shared_memory::channel_names::kConditionFromMain
constexpr char const *const kConditionFromMain
Definition:
channel_names.h:32
edm::shared_memory::channel_names::kMutex
constexpr char const *const kMutex
Definition:
channel_names.h:31
MatrixUtil.remove
def remove(d, key, TELL=False)
Definition:
MatrixUtil.py:212
edm::shared_memory::channel_names::kTransitionType
constexpr char const *const kTransitionType
Definition:
channel_names.h:36
edm::shared_memory::ControllerChannel::ControllerChannel
ControllerChannel(std::string const &iName, int iID)
Definition:
ControllerChannel.cc:34
Generated for CMSSW Reference Manual by
1.8.16