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 <cstdint>
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( PageInfo* chunk );
108 
114  std::pair<uint64_t, uint64_t> GetBlock();
115 
123  void SetFileSize( int64_t size );
124 
129  int64_t GetSize()
130  {
131  XrdSysCondVarHelper lck( pFileSizeCV );
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  {
199  pFileSizeCV.Broadcast();
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 
243  uint8_t pParallelChunks;
244 
250  uint64_t pOffset;
251 
255  int64_t pFileSize;
256 
261  XrdSysCondVar pFileSizeCV;
262 
267  std::list<XCpSrc*> pSources;
268 
273  SyncQueue<PageInfo*> pSink;
274 
278  uint64_t pDataReceived;
279 
284  bool pDone;
285 
290  XrdSysCondVar pDoneCV;
291 
295  XrdSysMutex pMtx;
296 
300  size_t pRefCount;
301 };
302 
303 } /* namespace XrdCl */
304 
305 #endif /* SRC_XRDCL_XRDCLXCPCTX_HH_ */
A synchronized queue.
void NotifyInitExpectant()
Definition: XrdClXCpCtx.hh:197
void NotifyIdleSrc()
Definition: XrdClXCpCtx.cc:172
bool GetNextUrl(std::string &url)
Definition: XrdClXCpCtx.cc:57
void RemoveSrc(XCpSrc *src)
Definition: XrdClXCpCtx.hh:167
XCpSrc * WeakestLink(XCpSrc *exclude)
Definition: XrdClXCpCtx.cc:66
XCpCtx * Self()
Definition: XrdClXCpCtx.hh:77
void PutChunk(PageInfo *chunk)
Definition: XrdClXCpCtx.cc:87
XCpCtx(const std::vector< std::string > &urls, uint64_t blockSize, uint8_t parallelSrc, uint64_t chunkSize, uint64_t parallelChunks, int64_t fileSize)
Definition: XrdClXCpCtx.cc:36
int64_t GetSize()
Definition: XrdClXCpCtx.hh:129
void SetFileSize(int64_t size)
Definition: XrdClXCpCtx.cc:104
std::pair< uint64_t, uint64_t > GetBlock()
Definition: XrdClXCpCtx.cc:92
XRootDStatus Initialize()
Definition: XrdClXCpCtx.cc:121
XRootDStatus GetChunk(XrdCl::PageInfo &ci)
Definition: XrdClXCpCtx.cc:140