xrootd
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
30
31namespace XrdCl
32{
33 //----------------------------------------------------------------------------
35 //----------------------------------------------------------------------------
37 {
38 public:
39 //------------------------------------------------------------------------
44 //------------------------------------------------------------------------
45 RequestSync( uint32_t reqTotal, uint32_t reqQuota ):
46 pQuotaSem( new Semaphore( reqQuota ) ),
47 pTotalSem( new Semaphore( 0 ) ),
48 pRequestsLeft( reqTotal ),
50 {
51 if( !reqTotal )
52 pTotalSem->Post();
53 }
54
55 //------------------------------------------------------------------------
57 //------------------------------------------------------------------------
59 {
60 delete pQuotaSem;
61 delete pTotalSem;
62 }
63
64 //------------------------------------------------------------------------
66 //------------------------------------------------------------------------
68 {
69 pQuotaSem->Wait();
70 }
71
72 //------------------------------------------------------------------------
74 //------------------------------------------------------------------------
76 {
77 pTotalSem->Wait();
78 }
79
80 //------------------------------------------------------------------------
82 //------------------------------------------------------------------------
83 void TaskDone( bool success = true )
84 {
85 XrdSysMutexHelper scopedLock( pMutex );
86 if( !success )
89 pQuotaSem->Post();
90 if( !pRequestsLeft )
91 pTotalSem->Post();
92 }
93
94 //------------------------------------------------------------------------
96 //------------------------------------------------------------------------
97 uint32_t FailureCount() const
98 {
99 return pFailureCounter;
100 }
101
102 private:
105
111 };
112}
113
114#endif // __XRD_CL_REQUEST_SYNC_HH__
A helper running a fixed number of requests at a given time.
Definition: XrdClRequestSync.hh:37
Semaphore * pQuotaSem
Definition: XrdClRequestSync.hh:107
void WaitForAll()
Wait for all the requests to be finished.
Definition: XrdClRequestSync.hh:75
uint32_t pFailureCounter
Definition: XrdClRequestSync.hh:110
RequestSync(uint32_t reqTotal, uint32_t reqQuota)
Definition: XrdClRequestSync.hh:45
void TaskDone(bool success=true)
Report the request finish.
Definition: XrdClRequestSync.hh:83
uint32_t pRequestsLeft
Definition: XrdClRequestSync.hh:109
uint32_t FailureCount() const
Number of tasks finishing with an error.
Definition: XrdClRequestSync.hh:97
RequestSync & operator=(const RequestSync &other)
XrdSysMutex pMutex
Definition: XrdClRequestSync.hh:106
void WaitForQuota()
Wait for the request quota.
Definition: XrdClRequestSync.hh:67
Semaphore * pTotalSem
Definition: XrdClRequestSync.hh:108
~RequestSync()
Destructor.
Definition: XrdClRequestSync.hh:58
RequestSync(const RequestSync &other)
Definition: XrdSysPthread.hh:261
Definition: XrdSysPthread.hh:166
Definition: XrdSysPthread.hh:404
void Wait()
Definition: XrdSysPthread.hh:419
void Post()
Definition: XrdSysPthread.hh:415
Definition: XrdClAnyObject.hh:26