00001 //------------------------------------------------------------------------------ 00002 // Copyright (c) 2011-2012 by European Organization for Nuclear Research (CERN) 00003 // Author: Lukasz Janyst <ljanyst@cern.ch> 00004 //------------------------------------------------------------------------------ 00005 // XRootD is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU Lesser General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // XRootD is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU Lesser General Public License 00016 // along with XRootD. If not, see <http://www.gnu.org/licenses/>. 00017 //------------------------------------------------------------------------------ 00018 00019 #ifndef __XRD_CL_SID_MANAGER_HH__ 00020 #define __XRD_CL_SID_MANAGER_HH__ 00021 00022 #include <list> 00023 #include <set> 00024 #include <stdint.h> 00025 #include "XrdSys/XrdSysPthread.hh" 00026 #include "XrdCl/XrdClStatus.hh" 00027 00028 namespace XrdCl 00029 { 00030 //---------------------------------------------------------------------------- 00032 //---------------------------------------------------------------------------- 00033 class SIDManager 00034 { 00035 public: 00036 00037 //------------------------------------------------------------------------ 00039 //------------------------------------------------------------------------ 00040 SIDManager(): pSIDCeiling(1) {} 00041 00042 //------------------------------------------------------------------------ 00047 //------------------------------------------------------------------------ 00048 Status AllocateSID( uint8_t sid[2] ); 00049 00050 //------------------------------------------------------------------------ 00052 //------------------------------------------------------------------------ 00053 void ReleaseSID( uint8_t sid[2] ); 00054 00055 //------------------------------------------------------------------------ 00057 //------------------------------------------------------------------------ 00058 void TimeOutSID( uint8_t sid[2] ); 00059 00060 //------------------------------------------------------------------------ 00062 //------------------------------------------------------------------------ 00063 bool IsTimedOut( uint8_t sid[2] ); 00064 00065 //------------------------------------------------------------------------ 00067 //------------------------------------------------------------------------ 00068 void ReleaseTimedOut( uint8_t sid[2] ); 00069 00070 //------------------------------------------------------------------------ 00072 //------------------------------------------------------------------------ 00073 void ReleaseAllTimedOut(); 00074 00075 //------------------------------------------------------------------------ 00077 //------------------------------------------------------------------------ 00078 uint32_t NumberOfTimedOutSIDs() const 00079 { 00080 XrdSysMutexHelper scopedLock( pMutex ); 00081 return pTimeOutSIDs.size(); 00082 } 00083 00084 //------------------------------------------------------------------------ 00086 //------------------------------------------------------------------------ 00087 uint16_t GetNumberOfAllocatedSIDs() const; 00088 00089 private: 00090 std::list<uint16_t> pFreeSIDs; 00091 std::set<uint16_t> pTimeOutSIDs; 00092 uint16_t pSIDCeiling; 00093 mutable XrdSysMutex pMutex; 00094 }; 00095 } 00096 00097 #endif // __XRD_CL_SID_MANAGER_HH__