xrootd
Loading...
Searching...
No Matches
XrdClRequestSync.hh
Go to the documentation of this file.
1//------------------------------------------------------------------------------
2// Copyright (c) 2011-2014 by European Organization for Nuclear Research (CERN)
3// Author: Lukasz Janyst <ljanyst@cern.ch>
4//------------------------------------------------------------------------------
5// This file is part of the XRootD software suite.
6//
7// XRootD is free software: you can redistribute it and/or modify
8// it under the terms of the GNU Lesser General Public License as published by
9// the Free Software Foundation, either version 3 of the License, or
10// (at your option) any later version.
11//
12// XRootD is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU Lesser General Public License
18// along with XRootD. If not, see <http://www.gnu.org/licenses/>.
19//
20// In applying this licence, CERN does not waive the privileges and immunities
21// granted to it by virtue of its status as an Intergovernmental Organization
22// or submit itself to any jurisdiction.
23//------------------------------------------------------------------------------
24
25#ifndef __XRD_CL_REQUEST_SYNC_HH__
26#define __XRD_CL_REQUEST_SYNC_HH__
27
29
30namespace XrdCl
31{
32 //----------------------------------------------------------------------------
34 //----------------------------------------------------------------------------
36 {
37 public:
38 //------------------------------------------------------------------------
43 //------------------------------------------------------------------------
44 RequestSync( uint32_t reqTotal, uint32_t reqQuota ):
45 pQuotaSem( new XrdSysSemaphore( reqQuota ) ),
46 pTotalSem( new XrdSysSemaphore( 0 ) ),
47 pRequestsLeft( reqTotal ),
49 {
50 if( !reqTotal )
51 pTotalSem->Post();
52 }
53
54 //------------------------------------------------------------------------
56 //------------------------------------------------------------------------
58 {
59 delete pQuotaSem;
60 delete pTotalSem;
61 }
62
63 //------------------------------------------------------------------------
65 //------------------------------------------------------------------------
67 {
68 pQuotaSem->Wait();
69 }
70
71 //------------------------------------------------------------------------
73 //------------------------------------------------------------------------
75 {
76 pTotalSem->Wait();
77 }
78
79 //------------------------------------------------------------------------
81 //------------------------------------------------------------------------
82 void TaskDone( bool success = true )
83 {
84 XrdSysMutexHelper scopedLock( pMutex );
85 if( !success )
88 pQuotaSem->Post();
89 if( !pRequestsLeft )
90 pTotalSem->Post();
91 }
92
93 //------------------------------------------------------------------------
95 //------------------------------------------------------------------------
96 uint32_t FailureCount() const
97 {
98 return pFailureCounter;
99 }
100
101 private:
104
110 };
111}
112
113#endif // __XRD_CL_REQUEST_SYNC_HH__
A helper running a fixed number of requests at a given time.
Definition XrdClRequestSync.hh:36
XrdSysSemaphore * pTotalSem
Definition XrdClRequestSync.hh:107
void WaitForAll()
Wait for all the requests to be finished.
Definition XrdClRequestSync.hh:74
uint32_t pFailureCounter
Definition XrdClRequestSync.hh:109
RequestSync(uint32_t reqTotal, uint32_t reqQuota)
Definition XrdClRequestSync.hh:44
XrdSysSemaphore * pQuotaSem
Definition XrdClRequestSync.hh:106
void TaskDone(bool success=true)
Report the request finish.
Definition XrdClRequestSync.hh:82
uint32_t pRequestsLeft
Definition XrdClRequestSync.hh:108
uint32_t FailureCount() const
Number of tasks finishing with an error.
Definition XrdClRequestSync.hh:96
RequestSync & operator=(const RequestSync &other)
XrdSysMutex pMutex
Definition XrdClRequestSync.hh:105
void WaitForQuota()
Wait for the request quota.
Definition XrdClRequestSync.hh:66
~RequestSync()
Destructor.
Definition XrdClRequestSync.hh:57
RequestSync(const RequestSync &other)
Definition XrdSysPthread.hh:263
Definition XrdSysPthread.hh:165
Definition XrdSysPthread.hh:494
void Wait()
Definition XrdSysPthread.hh:509
void Post()
Definition XrdSysPthread.hh:505
Definition XrdClAction.hh:34