ROOT
v6-32
Reference Guide
Loading...
Searching...
No Matches
TAtomicCountPthread.h
Go to the documentation of this file.
1
// @(#)root/thread:$Id$
2
// Author: Fons Rademakers 14/11/06
3
4
/*************************************************************************
5
* Copyright (C) 1995-2006, Rene Brun and Fons Rademakers. *
6
* All rights reserved. *
7
* *
8
* For the licensing terms see $ROOTSYS/LICENSE. *
9
* For the list of contributors see $ROOTSYS/README/CREDITS. *
10
*************************************************************************/
11
12
#ifndef ROOT_TAtomicCountPthread
13
#define ROOT_TAtomicCountPthread
14
15
#ifndef ROOT_TAtomicCount
16
# error This should be #included only by TAtomicCount.h. Please #include TAtomicCount.h.
17
#endif
//ROOT_TAtomicCount
18
19
//////////////////////////////////////////////////////////////////////////
20
// //
21
// TAtomicCountPthread //
22
// //
23
// Class providing atomic operations on a long. Setting, getting, //
24
// incrementing and decrementing are atomic, thread safe, operations. //
25
// //
26
// This implementation uses pthread mutexes for locking. This clearly //
27
// is less efficient than the version using asm locking instructions //
28
// as in TAtomicCountGcc.h, but better than nothing. //
29
// //
30
// ATTENTION: Don't use this file directly, it is included by //
31
// TAtomicCount.h. //
32
// //
33
//////////////////////////////////////////////////////////////////////////
34
35
#include <pthread.h>
36
37
class
TAtomicCount
{
38
private
:
39
Long_t
fCnt
;
// counter
40
mutable
pthread_mutex_t
fMutex
;
// mutex used to lock counter
41
42
TAtomicCount
(
const
TAtomicCount
&) =
delete
;
43
TAtomicCount
&
operator=
(
const
TAtomicCount
&) =
delete
;
44
45
class
LockGuard
{
46
private
:
47
pthread_mutex_t &
fM
;
// mutex to be guarded
48
public
:
49
LockGuard
(pthread_mutex_t &
m
):
fM
(
m
) {
pthread_mutex_lock
(&
fM
); }
50
~LockGuard
() {
pthread_mutex_unlock
(&
fM
); }
51
};
52
53
public
:
54
explicit
TAtomicCount
(
Long_t
v
):
fCnt
(
v
) {
55
pthread_mutex_init
(&
fMutex
, 0);
56
}
57
58
~TAtomicCount
() {
pthread_mutex_destroy
(&
fMutex
); }
59
60
void
operator++
() {
61
LockGuard
lock(
fMutex
);
62
++
fCnt
;
63
}
64
65
Long_t
operator--
() {
66
LockGuard
lock(
fMutex
);
67
return
--
fCnt
;
68
}
69
70
operator
long()
const
{
71
LockGuard
lock(
fMutex
);
72
return
fCnt
;
73
}
74
75
void
Set
(
Long_t
v
) {
76
LockGuard
lock(
fMutex
);
77
fCnt
=
v
;
78
}
79
80
Long_t
Get
()
const
{
81
LockGuard
lock(
fMutex
);
82
return
fCnt
;
83
}
84
};
85
86
#endif
Long_t
long Long_t
Definition
RtypesCore.h:54
TRangeDynCast
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Definition
TCollection.h:358
TAtomicCount::LockGuard
Definition
TAtomicCountPthread.h:45
TAtomicCount::LockGuard::LockGuard
LockGuard(pthread_mutex_t &m)
Definition
TAtomicCountPthread.h:49
TAtomicCount::LockGuard::fM
pthread_mutex_t & fM
Definition
TAtomicCountPthread.h:47
TAtomicCount::LockGuard::~LockGuard
~LockGuard()
Definition
TAtomicCountPthread.h:50
TAtomicCount
Definition
TAtomicCount.h:67
TAtomicCount::fMutex
pthread_mutex_t fMutex
Definition
TAtomicCountPthread.h:40
TAtomicCount::Get
Long_t Get() const
Definition
TAtomicCountPthread.h:80
TAtomicCount::operator++
void operator++()
Definition
TAtomicCountPthread.h:60
TAtomicCount::TAtomicCount
TAtomicCount(const TAtomicCount &)=delete
TAtomicCount::fCnt
Long_t fCnt
Definition
TAtomicCount.h:69
TAtomicCount::TAtomicCount
TAtomicCount(Long_t v)
Definition
TAtomicCountPthread.h:54
TAtomicCount::~TAtomicCount
~TAtomicCount()
Definition
TAtomicCountPthread.h:58
TAtomicCount::operator--
Long_t operator--()
Definition
TAtomicCountPthread.h:65
TAtomicCount::operator=
TAtomicCount & operator=(const TAtomicCount &)=delete
TAtomicCount::Set
void Set(Long_t v)
Definition
TAtomicCountPthread.h:75
v
@ v
Definition
rootcling_impl.cxx:3687
m
TMarker m
Definition
textangle.C:8
core
thread
inc
TAtomicCountPthread.h
ROOT v6-32 - Reference Guide Generated on Sat Jan 25 2025 14:33:11 (GVA Time) using Doxygen 1.10.0