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 
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_ */
XrdCl::ChunkInfo
Describe a data chunk for vector read.
Definition: XrdClXRootDResponses.hh:889
XrdCl::XCpCtx::pSources
std::list< XCpSrc * > pSources
Definition: XrdClXCpCtx.hh:267
XrdClXRootDResponses.hh
XrdCl::XCpCtx::pFileSizeCV
XrdSysCondVar pFileSizeCV
Definition: XrdClXCpCtx.hh:261
XrdCl::XCpCtx::pBlockSize
uint64_t pBlockSize
Definition: XrdClXCpCtx.hh:228
XrdSysMutex
Definition: XrdSysPthread.hh:166
XrdSysCondVarHelper
Definition: XrdSysPthread.hh:130
XrdSysPthread.hh
XrdCl::XCpCtx::Initialize
XRootDStatus Initialize()
XrdCl::XCpCtx::PutChunk
void PutChunk(ChunkInfo *chunk)
XrdCl::XCpSrc
Definition: XrdClXCpSrc.hh:38
XrdCl::XCpCtx::RemoveSrc
void RemoveSrc(XCpSrc *src)
Definition: XrdClXCpCtx.hh:167
XrdCl::XCpCtx::pFileSize
int64_t pFileSize
Definition: XrdClXCpCtx.hh:255
XrdCl::XCpCtx::XCpCtx
XCpCtx(const std::vector< std::string > &urls, uint64_t blockSize, uint8_t parallelSrc, uint64_t chunkSize, uint64_t parallelChunks, int64_t fileSize)
XrdCl::XCpCtx::pChunkSize
uint32_t pChunkSize
Definition: XrdClXCpCtx.hh:238
XrdCl::XCpCtx::pMtx
XrdSysMutex pMtx
Definition: XrdClXCpCtx.hh:295
XrdCl::XCpCtx::SetFileSize
void SetFileSize(int64_t size)
XrdSysMutexHelper::UnLock
void UnLock()
Definition: XrdSysPthread.hh:272
XrdSysCondVar::Broadcast
void Broadcast()
Definition: XrdSysPthread.hh:89
XrdCl::XCpCtx::WeakestLink
XCpSrc * WeakestLink(XCpSrc *exclude)
XrdCl::XCpCtx::Self
XCpCtx * Self()
Definition: XrdClXCpCtx.hh:77
XrdCl::XRootDStatus
Request status.
Definition: XrdClXRootDResponses.hh:215
XrdCl::XCpCtx
Definition: XrdClXCpCtx.hh:41
XrdCl::XCpCtx::pDone
bool pDone
Definition: XrdClXCpCtx.hh:284
XrdSysCondVar
Definition: XrdSysPthread.hh:79
XrdCl::XCpCtx::Delete
void Delete()
Definition: XrdClXCpCtx.hh:61
XrdCl::XCpCtx::~XCpCtx
virtual ~XCpCtx()
XrdCl::XCpCtx::pParallelChunks
uint8_t pParallelChunks
Definition: XrdClXCpCtx.hh:243
XrdCl::XCpCtx::GetNextUrl
bool GetNextUrl(std::string &url)
XrdCl::XCpCtx::pDoneCV
XrdSysCondVar pDoneCV
Definition: XrdClXCpCtx.hh:290
XrdCl::XCpCtx::pParallelSrc
uint8_t pParallelSrc
Definition: XrdClXCpCtx.hh:233
XrdCl::XCpCtx::pDataReceived
uint64_t pDataReceived
Definition: XrdClXCpCtx.hh:278
XrdSysCondVar::Wait
int Wait()
XrdCl::XCpCtx::NotifyIdleSrc
void NotifyIdleSrc()
XrdCl
Definition: XrdClAnyObject.hh:26
XrdCl::XCpCtx::GetSize
int64_t GetSize()
Definition: XrdClXCpCtx.hh:129
XrdCl::XCpCtx::GetBlock
std::pair< uint64_t, uint64_t > GetBlock()
XrdCl::XCpCtx::pRefCount
size_t pRefCount
Definition: XrdClXCpCtx.hh:300
XrdCl::XCpCtx::NotifyInitExpectant
void NotifyInitExpectant()
Definition: XrdClXCpCtx.hh:197
XrdSysMutexHelper
Definition: XrdSysPthread.hh:261
XrdClSyncQueue.hh
XrdCl::XCpCtx::GetChunk
XRootDStatus GetChunk(XrdCl::ChunkInfo &ci)
XrdCl::XCpCtx::AllDone
bool AllDone()
XrdCl::XCpCtx::pSink
SyncQueue< ChunkInfo * > pSink
Definition: XrdClXCpCtx.hh:273
XrdCl::SyncQueue
A synchronized queue.
Definition: XrdClSyncQueue.hh:34
XrdCl::XCpCtx::pOffset
uint64_t pOffset
Definition: XrdClXCpCtx.hh:250
XrdCl::XCpCtx::pUrls
std::queue< std::string > pUrls
Definition: XrdClXCpCtx.hh:223
XrdCl::XCpCtx::GetRunning
size_t GetRunning()