DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
ers
include
ers
internal
SingletonCreator.hpp
Go to the documentation of this file.
1
/*
2
* DUNE DAQ modification notice:
3
* This file has been modified from the original ATLAS ers source for the DUNE DAQ project.
4
* Fork baseline commit: 8267df82a4f6fe6bf02c4014923eba19eddc4614 (2020-04-14).
5
* Renamed since fork: yes (from ers/internal/SingletonCreator.h to include/ers/internal/SingletonCreator.hpp).
6
*
7
* Original copyright:
8
* Copyright (C) 2001-2020 CERN for the benefit of the ATLAS collaboration.
9
* Licensed under the Apache License, Version 2.0.
10
*/
11
12
#ifndef ERS_SINGLETON_CREATOR_H
13
#define ERS_SINGLETON_CREATOR_H
14
19
20
#include <mutex>
21
22
/*
23
* SingletonCreator.h
24
* ers
25
*
26
* Created by Serguei Kolos on 25.08.11.
27
* Copyright 2011 CERN. All rights reserved.
28
* This class creates singleton instance at the first use attempt
29
* in a threading-safe way.
30
*/
31
namespace
ers
{
32
template
<
class
T>
33
class
SingletonCreator
34
{
35
static
std::mutex
s_mutex
;
36
static
T*
s_instance
;
37
38
public
:
39
static
T*
create
()
40
{
41
// on MacOS with gcc 4.2 the s_mutex is not yet created
42
// at this moment which causes crash. This might be fixed
43
// when movining to newer gcc version
44
#if !defined(__APPLE__) && !defined(__rtems__)
45
std::scoped_lock lock(
s_mutex
);
46
#endif
47
if
(!
s_instance
) {
48
s_instance
=
new
T();
49
}
50
return
s_instance
;
51
}
52
};
53
54
template
<
class
T>
55
std::mutex
SingletonCreator<T>::s_mutex
;
56
57
template
<
class
T>
58
T*
SingletonCreator<T>::s_instance
;
59
}
60
61
#endif
ers::SingletonCreator
Definition
SingletonCreator.hpp:34
ers::SingletonCreator::s_mutex
static std::mutex s_mutex
Definition
SingletonCreator.hpp:35
ers::SingletonCreator::s_instance
static T * s_instance
Definition
SingletonCreator.hpp:36
ers::SingletonCreator::create
static T * create()
Definition
SingletonCreator.hpp:39
ers
Definition
Logger.hxx:231
Generated on
for DUNE-DAQ by
1.18.0