xrootd
Loading...
Searching...
No Matches
XrdSsiRRTable.hh
Go to the documentation of this file.
1#ifndef __XRDSSIRRTABLE_HH__
2#define __XRDSSIRRTABLE_HH__
3/******************************************************************************/
4/* */
5/* X r d S s i R R T a b l e . h h */
6/* */
7/* (c) 2017 by the Board of Trustees of the Leland Stanford, Jr., University */
8/* Produced by Andrew Hanushevsky for Stanford University under contract */
9/* DE-AC02-76-SFO0515 with the Department of Energy */
10/* */
11/* This file is part of the XRootD software suite. */
12/* */
13/* XRootD is free software: you can redistribute it and/or modify it under */
14/* the terms of the GNU Lesser General Public License as published by the */
15/* Free Software Foundation, either version 3 of the License, or (at your */
16/* option) any later version. */
17/* */
18/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
19/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
20/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
21/* License for more details. */
22/* */
23/* You should have received a copy of the GNU Lesser General Public License */
24/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
25/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
26/* */
27/* The copyright holder's institutional names and contributor's names may not */
28/* be used to endorse or promote products derived from this software without */
29/* specific prior written permission of the institution or contributor. */
30/******************************************************************************/
31
32#include <map>
33#include <cstdint>
34
36
37template<class T>
39{
40public:
41
42void Add(T *item, uint64_t itemID)
43 {rrtMutex.Lock();
44 if (baseItem != 0) theMap[itemID] = item;
45 else {baseKey = itemID;
46 baseItem = item;
47 }
49 }
50
51void Clear() {rrtMutex.Lock(); theMap.clear(); rrtMutex.UnLock();}
52
53void Del(uint64_t itemID, bool finit=false)
55 if (baseItem && baseKey == itemID)
56 {if (finit) baseItem->Finalize();
57 baseItem = 0;
58 } else {
59 if (!finit) theMap.erase(itemID);
60 else {typename std::map<uint64_t,T*>::iterator it = theMap.find(itemID);
61 if (it != theMap.end()) it->second->Finalize();
62 theMap.erase(it);
63 }
64 }
65 }
66
67T *LookUp(uint64_t itemID)
69 if (baseItem && baseKey == itemID) return baseItem;
70 typename std::map<uint64_t,T*>::iterator it = theMap.find(itemID);
71 return (it == theMap.end() ? 0 : it->second);
72 }
73
74int Num() {return theMap.size() + (baseItem ? 1 : 0);}
75
76void Reset()
78 typename std::map<uint64_t, T*>::iterator it = theMap.begin();
79 while(it != theMap.end())
80 {it->second->Finalize();
81 it++;
82 }
83 theMap.clear();
84 if (baseItem)
85 {baseItem->Finalize();
86 baseItem = 0;
87 }
88 }
89
91
93
94private:
97uint64_t baseKey;
98std::map<uint64_t, T*> theMap;
99};
100#endif
Definition XrdSsiAtomics.hh:149
Definition XrdSsiAtomics.hh:110
void UnLock()
Definition XrdSsiAtomics.hh:117
void Lock()
Definition XrdSsiAtomics.hh:115
Definition XrdSsiRRTable.hh:39
T * LookUp(uint64_t itemID)
Definition XrdSsiRRTable.hh:67
T * baseItem
Definition XrdSsiRRTable.hh:96
uint64_t baseKey
Definition XrdSsiRRTable.hh:97
XrdSsiRRTable()
Definition XrdSsiRRTable.hh:90
int Num()
Definition XrdSsiRRTable.hh:74
~XrdSsiRRTable()
Definition XrdSsiRRTable.hh:92
void Add(T *item, uint64_t itemID)
Definition XrdSsiRRTable.hh:42
void Clear()
Definition XrdSsiRRTable.hh:51
XrdSsiMutex rrtMutex
Definition XrdSsiRRTable.hh:95
void Reset()
Definition XrdSsiRRTable.hh:76
void Del(uint64_t itemID, bool finit=false)
Definition XrdSsiRRTable.hh:53
std::map< uint64_t, T * > theMap
Definition XrdSsiRRTable.hh:98