xrootd
XrdClXCpCtx.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // Copyright (c) 2011-2017 by European Organization for Nuclear Research (CERN)
3 // Author: Michal Simon <michal.simon@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 SRC_XRDCL_XRDCLXCPCTX_HH_
26 #define SRC_XRDCL_XRDCLXCPCTX_HH_
27 
28 #include "XrdCl/XrdClSyncQueue.hh"
30 #include "XrdSys/XrdSysPthread.hh"
31 
32 #include <stdint.h>
33 #include <iostream>
34 
35 namespace XrdCl
36 {
37 
38 class XCpSrc;
39 
40 class XCpCtx
41 {
42  public:
43 
56  XCpCtx( const std::vector<std::string> &urls, uint64_t blockSize, uint8_t parallelSrc, uint64_t chunkSize, uint64_t parallelChunks, int64_t fileSize );
57 
61  void Delete()
62  {
63  XrdSysMutexHelper lck( pMtx );
64  --pRefCount;
65  if( !pRefCount )
66  {
67  lck.UnLock();
68  delete this;
69  }
70  }
71 
78  {
79  XrdSysMutexHelper lck( pMtx );
80  ++pRefCount;
81  return this;
82  }
83 
91  bool GetNextUrl( std::string & url );
92 
100  XCpSrc* WeakestLink( XCpSrc *exclude );
101 
107  void PutChunk( ChunkInfo* chunk );
108 
114  std::pair<uint64_t, uint64_t> GetBlock();
115 
123  void SetFileSize( int64_t size );
124 
129  int64_t GetSize()
130  {
132  while( pFileSize < 0 && GetRunning() > 0 ) pFileSizeCV.Wait();
133  return pFileSize;
134  }
135 
145 
161 
167  void RemoveSrc( XCpSrc *src )
168  {
169  XrdSysMutexHelper lck( pMtx );
170  pSources.remove( src );
171  }
172 
180  void NotifyIdleSrc();
181 
190  bool AllDone();
191 
198  {
200  }
201 
202 
203  private:
204 
210  size_t GetRunning();
211 
217  virtual ~XCpCtx();
218 
223  std::queue<std::string> pUrls;
224 
228  uint64_t pBlockSize;
229 
233  uint8_t pParallelSrc;
234 
238  uint32_t pChunkSize;
239 
244 
250  uint64_t pOffset;
251 
255  int64_t pFileSize;
256 
262 
267  std::list<XCpSrc*> pSources;
268 
274 
278  uint64_t pDataReceived;
279 
284  bool pDone;
285 
291 
296 
300  size_t pRefCount;
301 };
302 
303 } /* namespace XrdCl */
304 
305 #endif /* SRC_XRDCL_XRDCLXCPCTX_HH_ */
XRootDStatus Initialize()
void Delete()
Definition: XrdClXCpCtx.hh:61
int64_t GetSize()
Definition: XrdClXCpCtx.hh:129
XrdSysCondVar pFileSizeCV
Definition: XrdClXCpCtx.hh:261
XrdSysCondVar pDoneCV
Definition: XrdClXCpCtx.hh:290
uint8_t pParallelSrc
Definition: XrdClXCpCtx.hh:233
int64_t pFileSize
Definition: XrdClXCpCtx.hh:255
virtual ~XCpCtx()
bool GetNextUrl(std::string &url)
void RemoveSrc(XCpSrc *src)
Definition: XrdClXCpCtx.hh:167
Definition: XrdClXCpSrc.hh:37
uint8_t pParallelChunks
Definition: XrdClXCpCtx.hh:243
std::pair< uint64_t, uint64_t > GetBlock()
XCpSrc * WeakestLink(XCpSrc *exclude)
void UnLock()
Definition: XrdSysPthread.hh:274
void PutChunk(ChunkInfo *chunk)
A synchronized queue.
Definition: XrdClSyncQueue.hh:32
size_t pRefCount
Definition: XrdClXCpCtx.hh:300
uint64_t pBlockSize
Definition: XrdClXCpCtx.hh:228
Definition: XrdSysPthread.hh:165
Definition: XrdClXCpCtx.hh:40
Definition: XrdSysPthread.hh:78
bool pDone
Definition: XrdClXCpCtx.hh:284
Describe a data chunk for vector read.
Definition: XrdClXRootDResponses.hh:907
XCpCtx(const std::vector< std::string > &urls, uint64_t blockSize, uint8_t parallelSrc, uint64_t chunkSize, uint64_t parallelChunks, int64_t fileSize)
std::list< XCpSrc * > pSources
Definition: XrdClXCpCtx.hh:267
Request status.
Definition: XrdClXRootDResponses.hh:218
Definition: XrdClAnyObject.hh:25
void Broadcast()
Definition: XrdSysPthread.hh:89
XrdSysMutex pMtx
Definition: XrdClXCpCtx.hh:295
Definition: XrdSysPthread.hh:129
size_t GetRunning()
XCpCtx * Self()
Definition: XrdClXCpCtx.hh:77
uint64_t pDataReceived
Definition: XrdClXCpCtx.hh:278
void NotifyIdleSrc()
void NotifyInitExpectant()
Definition: XrdClXCpCtx.hh:197
uint32_t pChunkSize
Definition: XrdClXCpCtx.hh:238
void SetFileSize(int64_t size)
SyncQueue< ChunkInfo * > pSink
Definition: XrdClXCpCtx.hh:273
XRootDStatus GetChunk(XrdCl::ChunkInfo &ci)
uint64_t pOffset
Definition: XrdClXCpCtx.hh:250
Definition: XrdSysPthread.hh:262
std::queue< std::string > pUrls
Definition: XrdClXCpCtx.hh:223