DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dunedaq
sourcecode
ers
include
ers
internal
SingletonCreator.hpp
Go to the documentation of this file.
1
#ifndef ERS_SINGLETON_CREATOR_H
2
#define ERS_SINGLETON_CREATOR_H
3
9
#include <mutex>
10
11
/*
12
* SingletonCreator.h
13
* ers
14
*
15
* Created by Serguei Kolos on 25.08.11.
16
* Copyright 2011 CERN. All rights reserved.
17
* This class creates singleton instance at the first use attempt
18
* in a threading-safe way.
19
*/
20
namespace
ers
21
{
22
template
<
class
T>
23
class
SingletonCreator
24
{
25
static
std::mutex
s_mutex
;
26
static
T *
s_instance
;
27
28
public
:
29
static
T *
create
( )
30
{
31
// on MacOS with gcc 4.2 the s_mutex is not yet created
32
// at this moment which causes crash. This might be fixed
33
// when movining to newer gcc version
34
#if !defined( __APPLE__) && !defined(__rtems__)
35
std::scoped_lock lock(
s_mutex
);
36
#endif
37
if
( !
s_instance
)
38
{
39
s_instance
=
new
T();
40
}
41
return
s_instance
;
42
}
43
};
44
45
template
<
class
T>
46
std::mutex
SingletonCreator<T>::s_mutex
;
47
48
template
<
class
T>
49
T *
SingletonCreator<T>::s_instance
;
50
}
51
52
#endif
ers::SingletonCreator::s_mutex
static std::mutex s_mutex
Definition
SingletonCreator.hpp:25
ers::SingletonCreator::s_instance
static T * s_instance
Definition
SingletonCreator.hpp:26
ers::SingletonCreator::create
static T * create()
Definition
SingletonCreator.hpp:29
ers
Definition
AnyIssue.hpp:20
Generated on Sat Jun 28 2025 for DUNE-DAQ by
1.12.0