DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
dbe
include
dbe
cptr.hpp
Go to the documentation of this file.
1
// DUNE DAQ modification notice:
2
// This file has been modified from the original ATLAS dbe source for the DUNE DAQ project.
3
// Fork baseline commit: dbe-02-12-17 (2022-05-12).
4
// Renamed since fork: yes (from dbe/cptr.hpp to include/dbe/cptr.hpp).
5
6
/************************************************************
7
* cptr.hpp *
8
* *
9
* Created on: Sep 14, 2014 *
10
* Author: Leonidas Georgopoulos *
11
*
12
* Copyright (C) 2014 Leonidas Georgopoulos
13
* Distributed under the Boost Software License, Version 1.0.
14
* (See accompanying file LICENSE_1_0.txt or
15
* copy at http://www.boost.org/LICENSE_1_0.txt)
16
*
17
************************************************************/
18
#ifndef LUTILS_CPTR_HPP
19
#define LUTILS_CPTR_HPP
20
21
#include <chrono>
22
#include <iostream>
23
#include <memory>
24
#include <mutex>
25
#include <thread>
26
#include <utility>
27
28
template
<
typename
T,
typename
M>
29
class
cptr_proxy
;
30
31
//-----------------------------------------------------------------------------------------------------
54
template
<
typename
T,
typename
M = std::recursive_mutex,
int
N = 100>
55
class
cptr
56
{
57
protected
:
58
std::shared_ptr<M>
llock
;
59
60
T*
base
;
61
62
public
:
63
explicit
cptr
(T* p)
64
:
llock
(new M())
65
,
base
(p)
66
{
67
}
68
69
cptr_proxy<T, M>
operator->
()
70
{
71
while
(!
llock
->try_lock()) {
72
std::this_thread::sleep_for(std::chrono::nanoseconds(N));
73
}
74
75
return
*
this
;
76
}
77
78
cptr_proxy<T, M>
operator->
()
const
79
{
80
while
(!
llock
->try_lock()) {
81
std::this_thread::sleep_for(std::chrono::nanoseconds(N));
82
}
83
84
return
*
this
;
85
}
86
87
T*
get
() {
return
base
; }
88
89
T*
get
()
const
{
return
base
; }
90
91
friend
class
cptr_proxy
<T, M>;
92
};
93
//-----------------------------------------------------------------------------------------------------
94
// template<typename T, typename M, int N> M cptr<T,M,N>::llock;
95
//-----------------------------------------------------------------------------------------------------
103
template
<
typename
T,
typename
M>
104
class
cptr_proxy
105
{
106
private
:
107
T*
that
;
108
109
std::shared_ptr<M>
llock_ptr
;
110
111
public
:
112
cptr_proxy
(
cptr<T, M>
const
& cp)
113
:
that
(cp.base)
114
,
llock_ptr
(cp.llock)
115
{
116
}
117
118
T*
operator->
() {
return
that
; }
119
120
~cptr_proxy
() {
llock_ptr
->unlock(); }
121
};
122
//-----------------------------------------------------------------------------------------------------
123
124
#endif
/*LUTILS_CPTR_HPP*/
cptr_proxy
Definition
cptr.hpp:105
cptr_proxy::cptr_proxy
cptr_proxy(cptr< T, M > const &cp)
Definition
cptr.hpp:112
cptr_proxy::that
T * that
Definition
cptr.hpp:107
cptr_proxy::llock_ptr
std::shared_ptr< M > llock_ptr
Definition
cptr.hpp:109
cptr_proxy::~cptr_proxy
~cptr_proxy()
Definition
cptr.hpp:120
cptr_proxy::operator->
T * operator->()
Definition
cptr.hpp:118
cptr
Definition
cptr.hpp:56
cptr::operator->
cptr_proxy< T, M > operator->() const
Definition
cptr.hpp:78
cptr::cptr
cptr(T *p)
Definition
cptr.hpp:63
cptr::operator->
cptr_proxy< T, M > operator->()
Definition
cptr.hpp:69
cptr::get
T * get()
Definition
cptr.hpp:87
cptr< t_internal_changes_stack >::llock
std::shared_ptr< std::recursive_mutex > llock
Definition
cptr.hpp:58
cptr< t_internal_changes_stack >::base
t_internal_changes_stack * base
Definition
cptr.hpp:60
Generated on
for DUNE-DAQ by
1.18.0