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 <utility>
22
#include <iostream>
23
#include <mutex>
24
#include <memory>
25
#include <thread>
26
#include <chrono>
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>
class
cptr
55
{
56
protected
:
57
std::shared_ptr<M>
llock
;
58
59
T *
base
;
60
61
public
:
62
explicit
cptr
( T * p )
63
:
llock
( new M() ),
64
base
( p )
65
{
66
}
67
68
cptr_proxy<T, M>
operator->
()
69
{
70
while
( !
llock
->try_lock() )
71
{
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
{
82
std::this_thread::sleep_for ( std::chrono::nanoseconds ( N ) );
83
}
84
85
return
*
this
;
86
}
87
88
T *
get
()
89
{
90
return
base
;
91
}
92
93
T *
get
()
const
94
{
95
return
base
;
96
}
97
98
friend
class
cptr_proxy
<T, M> ;
99
};
100
//-----------------------------------------------------------------------------------------------------
101
//template<typename T, typename M, int N> M cptr<T,M,N>::llock;
102
//-----------------------------------------------------------------------------------------------------
110
template
<
typename
T,
typename
M>
111
class
cptr_proxy
112
{
113
private
:
114
T *
that
;
115
116
std::shared_ptr<M>
llock_ptr
;
117
118
public
:
119
cptr_proxy
(
cptr<T, M>
const
& cp )
120
:
that
( cp.base ),
121
llock_ptr
( cp.llock )
122
{
123
}
124
125
T *
operator->
()
126
{
127
return
that
;
128
}
129
130
~cptr_proxy
()
131
{
132
llock_ptr
->unlock();
133
}
134
};
135
//-----------------------------------------------------------------------------------------------------
136
137
#endif
/*LUTILS_CPTR_HPP*/
cptr_proxy
Definition
cptr.hpp:112
cptr_proxy::cptr_proxy
cptr_proxy(cptr< T, M > const &cp)
Definition
cptr.hpp:119
cptr_proxy::that
T * that
Definition
cptr.hpp:114
cptr_proxy::llock_ptr
std::shared_ptr< M > llock_ptr
Definition
cptr.hpp:116
cptr_proxy::~cptr_proxy
~cptr_proxy()
Definition
cptr.hpp:130
cptr_proxy::operator->
T * operator->()
Definition
cptr.hpp:125
cptr
Definition
cptr.hpp:55
cptr::operator->
cptr_proxy< T, M > operator->() const
Definition
cptr.hpp:78
cptr::cptr
cptr(T *p)
Definition
cptr.hpp:62
cptr::operator->
cptr_proxy< T, M > operator->()
Definition
cptr.hpp:68
cptr::get
T * get()
Definition
cptr.hpp:88
cptr< t_internal_changes_stack >::llock
std::shared_ptr< std::recursive_mutex > llock
Definition
cptr.hpp:57
cptr< t_internal_changes_stack >::base
t_internal_changes_stack * base
Definition
cptr.hpp:59
Generated on
for DUNE-DAQ by
1.17.0