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 
28 #include "XrdSys/XrdSysPthread.hh"
29 
30 namespace 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 ),
48  pFailureCounter( 0 )
49  {
50  if( !reqTotal )
51  pTotalSem->Post();
52  }
53 
54  //------------------------------------------------------------------------
56  //------------------------------------------------------------------------
58  {
59  delete pQuotaSem;
60  delete pTotalSem;
61  }
62 
63  //------------------------------------------------------------------------
65  //------------------------------------------------------------------------
66  void WaitForQuota()
67  {
68  pQuotaSem->Wait();
69  }
70 
71  //------------------------------------------------------------------------
73  //------------------------------------------------------------------------
74  void WaitForAll()
75  {
76  pTotalSem->Wait();
77  }
78 
79  //------------------------------------------------------------------------
81  //------------------------------------------------------------------------
82  void TaskDone( bool success = true )
83  {
84  XrdSysMutexHelper scopedLock( pMutex );
85  if( !success )
87  --pRequestsLeft;
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:
102  RequestSync(const RequestSync &other);
103  RequestSync &operator = (const RequestSync &other);
104 
108  uint32_t pRequestsLeft;
109  uint32_t pFailureCounter;
110  };
111 }
112 
113 #endif // __XRD_CL_REQUEST_SYNC_HH__
RequestSync(uint32_t reqTotal, uint32_t reqQuota)
Definition: XrdClRequestSync.hh:44
void TaskDone(bool success=true)
Report the request finish.
Definition: XrdClRequestSync.hh:82
uint32_t pFailureCounter
Definition: XrdClRequestSync.hh:109
XrdSysSemaphore * pQuotaSem
Definition: XrdClRequestSync.hh:106
void Wait()
Definition: XrdSysPthread.hh:421
XrdSysMutex pMutex
Definition: XrdClRequestSync.hh:105
Definition: XrdSysPthread.hh:165
void Post()
Definition: XrdSysPthread.hh:417
Definition: XrdSysPthread.hh:405
~RequestSync()
Destructor.
Definition: XrdClRequestSync.hh:57
Definition: XrdClAnyObject.hh:25
uint32_t FailureCount() const
Number of tasks finishing with an error.
Definition: XrdClRequestSync.hh:96
A helper running a fixed number of requests at a given time.
Definition: XrdClRequestSync.hh:35
RequestSync & operator=(const RequestSync &other)
void WaitForAll()
Wait for all the requests to be finished.
Definition: XrdClRequestSync.hh:74
void WaitForQuota()
Wait for the request quota.
Definition: XrdClRequestSync.hh:66
XrdSysSemaphore * pTotalSem
Definition: XrdClRequestSync.hh:107
Definition: XrdSysPthread.hh:262
uint32_t pRequestsLeft
Definition: XrdClRequestSync.hh:108