xrootd
Main Page
Namespaces
Classes
Files
File List
File Members
src
XrdCl
XrdClRequestSync.hh
Go to the documentation of this file.
1
//------------------------------------------------------------------------------
2
// Copyright (c) 2011-2012 by European Organization for Nuclear Research (CERN)
3
// Author: Lukasz Janyst <ljanyst@cern.ch>
4
//------------------------------------------------------------------------------
5
// XRootD is free software: you can redistribute it and/or modify
6
// it under the terms of the GNU Lesser General Public License as published by
7
// the Free Software Foundation, either version 3 of the License, or
8
// (at your option) any later version.
9
//
10
// XRootD is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
// GNU General Public License for more details.
14
//
15
// You should have received a copy of the GNU Lesser General Public License
16
// along with XRootD. If not, see <http://www.gnu.org/licenses/>.
17
//------------------------------------------------------------------------------
18
19
#ifndef __XRD_CL_REQUEST_SYNC_HH__
20
#define __XRD_CL_REQUEST_SYNC_HH__
21
22
#include "
XrdSys/XrdSysPthread.hh
"
23
24
namespace
XrdCl
25
{
26
//----------------------------------------------------------------------------
28
//----------------------------------------------------------------------------
29
class
RequestSync
30
{
31
public
:
32
//------------------------------------------------------------------------
37
//------------------------------------------------------------------------
38
RequestSync
( uint32_t reqTotal, uint32_t reqQuota ):
39
pQuotaSem
( new
XrdSysSemaphore
( reqQuota ) ),
40
pTotalSem
( new
XrdSysSemaphore
( 0 ) ),
41
pRequestsLeft
( reqTotal ),
42
pFailureCounter
( 0 )
43
{
44
if
( !reqTotal )
45
pTotalSem
->
Post
();
46
}
47
48
//------------------------------------------------------------------------
50
//------------------------------------------------------------------------
51
~RequestSync
()
52
{
53
delete
pQuotaSem
;
54
delete
pTotalSem
;
55
}
56
57
//------------------------------------------------------------------------
59
//------------------------------------------------------------------------
60
void
WaitForQuota
()
61
{
62
pQuotaSem
->
Wait
();
63
}
64
65
//------------------------------------------------------------------------
67
//------------------------------------------------------------------------
68
void
WaitForAll
()
69
{
70
pTotalSem
->
Wait
();
71
}
72
73
//------------------------------------------------------------------------
75
//------------------------------------------------------------------------
76
void
TaskDone
(
bool
success =
true
)
77
{
78
XrdSysMutexHelper
scopedLock(
pMutex
);
79
if
( !success )
80
++
pFailureCounter
;
81
--
pRequestsLeft
;
82
pQuotaSem
->
Post
();
83
if
( !
pRequestsLeft
)
84
pTotalSem
->
Post
();
85
}
86
87
//------------------------------------------------------------------------
89
//------------------------------------------------------------------------
90
uint32_t
FailureCount
()
const
91
{
92
return
pFailureCounter
;
93
}
94
95
private
:
96
XrdSysMutex
pMutex
;
97
XrdSysSemaphore
*
pQuotaSem
;
98
XrdSysSemaphore
*
pTotalSem
;
99
uint32_t
pRequestsLeft
;
100
uint32_t
pFailureCounter
;
101
};
102
}
103
104
#endif // __XRD_CL_REQUEST_SYNC_HH__
Generated by
1.8.3.1