ROOT
v6-22
Reference Guide
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
//////////////////////////////////////////////////////////////////////////
16
// //
17
// TAtomicCountPthread //
18
// //
19
// Class providing atomic operations on a long. Setting, getting, //
20
// incrementing and decrementing are atomic, thread safe, operations. //
21
// //
22
// This implementation uses pthread mutexes for locking. This clearly //
23
// is less efficient than the version using asm locking instructions //
24
// as in TAtomicCountGcc.h, but better than nothing. //
25
// //
26
// ATTENTION: Don't use this file directly, it is included by //
27
// TAtomicCount.h. //
28
// //
29
//////////////////////////////////////////////////////////////////////////
30
31
#include <pthread.h>
32
33
#include "
RtypesCore.h
"
34
35
class
TAtomicCount
{
36
private
:
37
Long_t
fCnt
;
// counter
38
mutable
pthread_mutex_t
fMutex
;
// mutex used to lock counter
39
40
TAtomicCount
(
const
TAtomicCount
&);
// not implemented
41
TAtomicCount
&
operator=
(
const
TAtomicCount
&);
// not implemented
42
43
class
LockGuard
{
44
private
:
45
pthread_mutex_t &
fM
;
// mutex to be guarded
46
public
:
47
LockGuard
(pthread_mutex_t &
m
):
fM
(
m
) { pthread_mutex_lock(&
fM
); }
48
~LockGuard
() { pthread_mutex_unlock(&
fM
); }
49
};
50
51
public
:
52
explicit
TAtomicCount
(
Long_t
v
):
fCnt
(
v
) {
53
pthread_mutex_init(&
fMutex
, 0);
54
}
55
56
~TAtomicCount
() { pthread_mutex_destroy(&
fMutex
); }
57
58
void
operator++
() {
59
LockGuard
lock(
fMutex
);
60
++
fCnt
;
61
}
62
63
Long_t
operator--
() {
64
LockGuard
lock(
fMutex
);
65
return
--
fCnt
;
66
}
67
68
operator
long
()
const
{
69
LockGuard
lock(
fMutex
);
70
return
fCnt
;
71
}
72
73
void
Set
(
Long_t
v
) {
74
LockGuard
lock(
fMutex
);
75
fCnt
=
v
;
76
}
77
78
Long_t
Get
()
const
{
79
LockGuard
lock(
fMutex
);
80
return
fCnt
;
81
}
82
};
83
84
#endif
long
long
Definition:
Converters.cxx:858
RtypesCore.h
Long_t
long Long_t
Definition:
RtypesCore.h:52
TAtomicCount::LockGuard
Definition:
TAtomicCountPthread.h:43
TAtomicCount::LockGuard::LockGuard
LockGuard(pthread_mutex_t &m)
Definition:
TAtomicCountPthread.h:47
TAtomicCount::LockGuard::fM
pthread_mutex_t & fM
Definition:
TAtomicCountPthread.h:45
TAtomicCount::LockGuard::~LockGuard
~LockGuard()
Definition:
TAtomicCountPthread.h:48
TAtomicCount
Definition:
TAtomicCount.h:67
TAtomicCount::fMutex
pthread_mutex_t fMutex
Definition:
TAtomicCountPthread.h:38
TAtomicCount::TAtomicCount
TAtomicCount(const TAtomicCount &)
TAtomicCount::Get
Long_t Get() const
Definition:
TAtomicCountPthread.h:78
TAtomicCount::operator=
TAtomicCount & operator=(const TAtomicCount &)
TAtomicCount::operator++
void operator++()
Definition:
TAtomicCountPthread.h:58
TAtomicCount::fCnt
Long_t fCnt
Definition:
TAtomicCount.h:69
TAtomicCount::TAtomicCount
TAtomicCount(Long_t v)
Definition:
TAtomicCountPthread.h:52
TAtomicCount::~TAtomicCount
~TAtomicCount()
Definition:
TAtomicCountPthread.h:56
TAtomicCount::operator--
Long_t operator--()
Definition:
TAtomicCountPthread.h:63
TAtomicCount::Set
void Set(Long_t v)
Definition:
TAtomicCountPthread.h:73
v
@ v
Definition:
rootcling_impl.cxx:3624
m
auto * m
Definition:
textangle.C:8
core
thread
inc
TAtomicCountPthread.h
ROOT v6-22 - Reference Guide Generated on Fri Apr 1 2022 11:50:38 (GVA Time) using Doxygen 1.9.4