xrootd
XrdClSIDManager.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // Copyright (c) 2011-2012 by European Organization for Nuclear Research (CERN)
3 // Author: Lukasz Janyst <ljanyst@cern.ch>
4 //------------------------------------------------------------------------------
5 // XRootD is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // XRootD is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with XRootD. If not, see <http://www.gnu.org/licenses/>.
17 //------------------------------------------------------------------------------
18 
19 #ifndef __XRD_CL_SID_MANAGER_HH__
20 #define __XRD_CL_SID_MANAGER_HH__
21 
22 #include <list>
23 #include <set>
24 #include <memory>
25 #include <unordered_map>
26 #include <string>
27 #include <stdint.h>
28 #include "XrdSys/XrdSysPthread.hh"
29 #include "XrdCl/XrdClStatus.hh"
30 #include "XrdCl/XrdClURL.hh"
31 
32 namespace XrdCl
33 {
34  //----------------------------------------------------------------------------
35  // We need the forward declaration for the friendship to work properly
36  //----------------------------------------------------------------------------
37  class SIDMgrPool;
38 
39  //----------------------------------------------------------------------------
41  //----------------------------------------------------------------------------
42  class SIDManager
43  {
44  friend class SIDMgrPool;
45 
46  private:
47 
48  //------------------------------------------------------------------------
50  //------------------------------------------------------------------------
52 
53 #if __cplusplus < 201103L
54  //------------------------------------------------------------------------
55  // For older complilers we have to make the destructor public, although
56  // the shared_pointer is using a custom deleter. It will go away once
57  // we drop SLC6 support.
58  //------------------------------------------------------------------------
59  public:
60 #endif
61  //------------------------------------------------------------------------
63  //------------------------------------------------------------------------
65 
66  public:
67 
68  //------------------------------------------------------------------------
73  //------------------------------------------------------------------------
74  Status AllocateSID( uint8_t sid[2] );
75 
76  //------------------------------------------------------------------------
78  //------------------------------------------------------------------------
79  void ReleaseSID( uint8_t sid[2] );
80 
81  //------------------------------------------------------------------------
83  //------------------------------------------------------------------------
84  void TimeOutSID( uint8_t sid[2] );
85 
86  //------------------------------------------------------------------------
88  //------------------------------------------------------------------------
89  bool IsTimedOut( uint8_t sid[2] );
90 
91  //------------------------------------------------------------------------
93  //------------------------------------------------------------------------
94  void ReleaseTimedOut( uint8_t sid[2] );
95 
96  //------------------------------------------------------------------------
98  //------------------------------------------------------------------------
99  void ReleaseAllTimedOut();
100 
101  //------------------------------------------------------------------------
103  //------------------------------------------------------------------------
104  uint32_t NumberOfTimedOutSIDs() const
105  {
106  XrdSysMutexHelper scopedLock( pMutex );
107  return pTimeOutSIDs.size();
108  }
109 
110  //------------------------------------------------------------------------
112  //------------------------------------------------------------------------
113  uint16_t GetNumberOfAllocatedSIDs() const;
114 
115  private:
116  std::list<uint16_t> pFreeSIDs;
117  std::set<uint16_t> pTimeOutSIDs;
118  uint16_t pSIDCeiling;
120  mutable size_t pRefCount;
121  };
122 
123  //----------------------------------------------------------------------------
125  //----------------------------------------------------------------------------
127  {
128  public:
129 
130  //------------------------------------------------------------------------
132  //------------------------------------------------------------------------
134  {
135  //----------------------------------------------------------------------
136  // We could also use a nifty counter but this is simpler and will do!
137  //----------------------------------------------------------------------
138  static SIDMgrPool *instance = new SIDMgrPool();
139  return *instance;
140  }
141 
142  //------------------------------------------------------------------------
144  //------------------------------------------------------------------------
146 
147  //------------------------------------------------------------------------
150  // a custom deleter that will return the object to the pool
151  //------------------------------------------------------------------------
152  std::shared_ptr<SIDManager> GetSIDMgr( const URL &url );
153 
154  //------------------------------------------------------------------------
156  //------------------------------------------------------------------------
157  void Recycle( SIDManager *mgr );
158 
159  private:
160 
161  //------------------------------------------------------------------------
163  //------------------------------------------------------------------------
165  {
166  inline void operator()( SIDManager *mgr )
167  {
169  pool.Recycle( mgr );
170  }
171  };
172 
173  //------------------------------------------------------------------------
175  //------------------------------------------------------------------------
177 
178  //------------------------------------------------------------------------
180  //------------------------------------------------------------------------
181  SIDMgrPool( const SIDMgrPool& ) = delete;
182  SIDMgrPool( SIDMgrPool&& ) = delete;
183 
184  //------------------------------------------------------------------------
186  //------------------------------------------------------------------------
187  SIDMgrPool& operator=( const SIDMgrPool& ) = delete;
188  SIDMgrPool& operator=( SIDMgrPool&& ) = delete;
189 
191  std::unordered_map<std::string, SIDManager*> pool;
192  };
193 }
194 
195 #endif // __XRD_CL_SID_MANAGER_HH__
bool IsTimedOut(uint8_t sid[2])
Check if a SID is timed out.
XrdSysMutex pMutex
Definition: XrdClSIDManager.hh:119
void TimeOutSID(uint8_t sid[2])
Register a SID of a request that timed out.
void ReleaseAllTimedOut()
Release all timed out SIDs.
uint32_t NumberOfTimedOutSIDs() const
Number of timeout sids.
Definition: XrdClSIDManager.hh:104
~SIDManager()
Destructor.
Definition: XrdClSIDManager.hh:64
~SIDMgrPool()
Destructor.
Definition: XrdClSIDManager.hh:145
void Recycle(SIDManager *mgr)
Status AllocateSID(uint8_t sid[2])
static SIDMgrPool & Instance()
Definition: XrdClSIDManager.hh:133
A functional object for handling the deletion of SIDManager objects.
Definition: XrdClSIDManager.hh:164
Procedure execution status.
Definition: XrdClStatus.hh:112
XrdSysMutex mtx
Definition: XrdClSIDManager.hh:190
Definition: XrdSysPthread.hh:165
size_t pRefCount
Definition: XrdClSIDManager.hh:120
Pool of SID manager objects.
Definition: XrdClSIDManager.hh:126
Definition: XrdClAnyObject.hh:25
void ReleaseSID(uint8_t sid[2])
Release the SID that is no longer needed.
Handle XRootD stream IDs.
Definition: XrdClSIDManager.hh:42
SIDMgrPool()
Constructor.
Definition: XrdClSIDManager.hh:176
std::shared_ptr< SIDManager > GetSIDMgr(const URL &url)
std::set< uint16_t > pTimeOutSIDs
Definition: XrdClSIDManager.hh:117
URL representation.
Definition: XrdClURL.hh:30
SIDMgrPool & operator=(const SIDMgrPool &)=delete
Deleted assigment operators.
void operator()(SIDManager *mgr)
Definition: XrdClSIDManager.hh:166
std::list< uint16_t > pFreeSIDs
Definition: XrdClSIDManager.hh:116
uint16_t pSIDCeiling
Definition: XrdClSIDManager.hh:118
std::unordered_map< std::string, SIDManager * > pool
Definition: XrdClSIDManager.hh:191
uint16_t GetNumberOfAllocatedSIDs() const
Number of allocated streams.
void ReleaseTimedOut(uint8_t sid[2])
Release a timed out SID.
Definition: XrdSysPthread.hh:262
SIDManager()
Constructor.
Definition: XrdClSIDManager.hh:51