FairMQ
1.4.14
C++ Message Queuing Library and Framework
fairmq
tools
InstanceLimit.h
1
/********************************************************************************
2
* Copyright (C) 2019 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3
* *
4
* This software is distributed under the terms of the *
5
* GNU Lesser General Public Licence (LGPL) version 3, *
6
* copied verbatim in the file "LICENSE" *
7
********************************************************************************/
8
9
#ifndef FAIR_MQ_TOOLS_INSTANCELIMIT_H
10
#define FAIR_MQ_TOOLS_INSTANCELIMIT_H
11
12
#include "Strings.h"
13
14
namespace
fair
{
15
namespace
mq {
16
namespace
tools {
17
18
template
<
typename
Tag,
int
Max>
19
struct
InstanceLimiter
20
{
21
InstanceLimiter
() { Increment(); }
22
explicit
InstanceLimiter
(
const
InstanceLimiter
&) =
delete
;
23
explicit
InstanceLimiter
(
InstanceLimiter
&&) =
delete
;
24
InstanceLimiter
& operator=(
const
InstanceLimiter
&) =
delete
;
25
InstanceLimiter
& operator=(
InstanceLimiter
&&) =
delete
;
26
~
InstanceLimiter
() { Decrement(); }
27
auto
GetCount() ->
int
{
return
fCount; }
28
29
private
:
30
auto
Increment() ->
void
31
{
32
if
(fCount < Max) {
33
++fCount;
34
}
else
{
35
throw
std::runtime_error(
36
ToString(
"More than "
, Max,
" instances of "
, Tag(),
" in parallel not supported"
));
37
}
38
}
39
40
auto
Decrement() ->
void
41
{
42
if
(fCount > 0) {
43
--fCount;
44
}
45
}
46
47
static
int
fCount;
48
};
49
50
template
<
typename
Tag,
int
Max>
51
int
InstanceLimiter<Tag, Max>::fCount
(0);
52
53
}
/* namespace tools */
54
}
/* namespace mq */
55
}
/* namespace fair */
56
57
#endif
/* FAIR_MQ_TOOLS_INSTANCELIMIT_H */
fair
Tools for interfacing containers to the transport via polymorphic allocators.
Definition:
DeviceRunner.h:23
fair::mq::tools::InstanceLimiter
Definition:
InstanceLimit.h:19
privacy