XRootD
XrdSsiRRTable< T > Class Template Reference

#include <XrdSsiRRTable.hh>

+ Collaboration diagram for XrdSsiRRTable< T >:

Public Member Functions

 XrdSsiRRTable ()
 
 ~XrdSsiRRTable ()
 
XrdSsiRRTableItem< T > Add (T *item, uint64_t itemID)
 
void Clear ()
 
bool DeferFinalize (T *item, uint64_t itemID)
 
void DeferredFinalizeDone (T *item, uint64_t itemID)
 
void Del (uint64_t itemID)
 
void DelFinalize (XrdSsiRRTableItem< T > &&r)
 
XrdSsiRRTableItem< T > LookUp (uint64_t itemID)
 
int Num ()
 
void Release (T *item, uint64_t itemID)
 
void Reset ()
 

Detailed Description

template<class T>
class XrdSsiRRTable< T >

Definition at line 85 of file XrdSsiRRTable.hh.

Constructor & Destructor Documentation

◆ XrdSsiRRTable()

template<class T >
XrdSsiRRTable< T >::XrdSsiRRTable ( )
inline

Definition at line 240 of file XrdSsiRRTable.hh.

240 : baseKey(0), wCond(0), nDef(0) {}

◆ ~XrdSsiRRTable()

template<class T >
XrdSsiRRTable< T >::~XrdSsiRRTable ( )
inline

Definition at line 242 of file XrdSsiRRTable.hh.

242 {Reset();}

References XrdSsiRRTable< T >::Reset().

+ Here is the call graph for this function:

Member Function Documentation

◆ Add()

template<class T >
XrdSsiRRTableItem<T> XrdSsiRRTable< T >::Add ( T *  item,
uint64_t  itemID 
)
inline

Definition at line 91 of file XrdSsiRRTable.hh.

92  {XrdSsiMutexMon lck(rrtMutex);
93  if ((baseItem.item && baseKey == itemID)
94  || theMap.count(itemID))
95  {return XrdSsiRRTableItem<T>();}
96  if (baseItem.item == 0)
97  {baseItem.Init(item, 2);
98  baseKey = itemID;
99  return XrdSsiRRTableItem(item, this, itemID);
100  }
101  theMap[itemID].Init(item, 2);
102  return XrdSsiRRTableItem(item, this, itemID);
103  }

◆ Clear()

template<class T >
void XrdSsiRRTable< T >::Clear ( )
inline

Definition at line 105 of file XrdSsiRRTable.hh.

105 {rrtMutex.Lock(); theMap.clear(); baseItem.item = 0; rrtMutex.UnLock();}

References XrdSsiMutex::Lock(), and XrdSsiMutex::UnLock().

+ Here is the call graph for this function:

◆ DeferFinalize()

template<class T >
bool XrdSsiRRTable< T >::DeferFinalize ( T *  item,
uint64_t  itemID 
)
inline

Definition at line 112 of file XrdSsiRRTable.hh.

113  {XrdSsiMutexMon lck(rrtMutex);
114  if (baseItem.item && baseKey == itemID)
115  {if (baseItem.item != item) return false;
116  baseItem.deferedFinalize = true;
117  return true;
118  }
119  typename std::map<uint64_t,ItemInfo>::iterator it = theMap.find(itemID);
120  if (it == theMap.end()) return false;
121  ItemInfo &info = it->second;
122  if (info.item != item) return false;
123  info.deferedFinalize = true;
124  return true;
125  }

Referenced by XrdSsiFileSess::DeferFinalize().

+ Here is the caller graph for this function:

◆ DeferredFinalizeDone()

template<class T >
void XrdSsiRRTable< T >::DeferredFinalizeDone ( T *  item,
uint64_t  itemID 
)
inline

Definition at line 129 of file XrdSsiRRTable.hh.

130  {XrdSsiMutexMon lck(rrtMutex);
131  wCond.Lock();
132  nDef--;
133  wCond.Broadcast();
134  wCond.UnLock();
135  if (baseItem.item && baseKey == itemID)
136  {
137  if (baseItem.item != item) return;
138  baseItem.item = 0;
139  return;
140  }
141  typename std::map<uint64_t,ItemInfo>::iterator it = theMap.find(itemID);
142  if (it == theMap.end()) return;
143  ItemInfo &info = it->second;
144  if (info.item != item) return;
145  theMap.erase(it);
146  }

References XrdSysCondVar::Broadcast(), XrdSysCondVar::Lock(), and XrdSysCondVar::UnLock().

Referenced by XrdSsiFileSess::DeferredFinalizeDone(), and XrdSsiRRTable< T >::Reset().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Del()

template<class T >
void XrdSsiRRTable< T >::Del ( uint64_t  itemID)
inline

Definition at line 151 of file XrdSsiRRTable.hh.

151 {Decr(itemID, true);}

◆ DelFinalize()

template<class T >
void XrdSsiRRTable< T >::DelFinalize ( XrdSsiRRTableItem< T > &&  r)
inline

Definition at line 155 of file XrdSsiRRTable.hh.

156  {if (!r) return;
157  uint64_t itemID = r.reqID();
158  T* item = r.release();
159  Decr(itemID, true, item, true, 1);
160  XrdSsiMutexMon lck(rrtMutex);
161  while((baseItem.item && baseKey == itemID) ||
162  theMap.count(itemID))
163  {wCond.Lock();
164  lck.UnLock();
165  do { wCond.Wait(); } while(nDef>0);
166  wCond.UnLock();
167  lck.Lock(&rrtMutex);
168  }
169  }
uint64_t reqID() const

References XrdSysCondVar::Lock(), XrdSsiMutexMon::Lock(), XrdSsiMutexMon::UnLock(), XrdSysCondVar::UnLock(), and XrdSysCondVar::Wait().

+ Here is the call graph for this function:

◆ LookUp()

template<class T >
XrdSsiRRTableItem<T> XrdSsiRRTable< T >::LookUp ( uint64_t  itemID)
inline

Definition at line 177 of file XrdSsiRRTable.hh.

178  {XrdSsiMutexMon lck(rrtMutex);
179  if (baseItem.item && baseKey == itemID)
180  {if (baseItem.deleted) return XrdSsiRRTableItem<T>();
181  baseItem.refcount++;
182  return XrdSsiRRTableItem(baseItem.item, this, itemID);
183  }
184  typename std::map<uint64_t,ItemInfo>::iterator it = theMap.find(itemID);
185  if (it == theMap.end()) return XrdSsiRRTableItem<T>();
186  ItemInfo &info = it->second;
187  if (info.deleted) return XrdSsiRRTableItem<T>();
188  info.refcount++;
189  return XrdSsiRRTableItem(info.item, this, itemID);
190  }

◆ Num()

template<class T >
int XrdSsiRRTable< T >::Num ( )
inline

Definition at line 192 of file XrdSsiRRTable.hh.

192 {return theMap.size() + (baseItem.item ? 1 : 0);}

◆ Release()

template<class T >
void XrdSsiRRTable< T >::Release ( T *  item,
uint64_t  itemID 
)
inline

Definition at line 171 of file XrdSsiRRTable.hh.

171 {Decr(itemID, false, item, false, 1);}

◆ Reset()

template<class T >
void XrdSsiRRTable< T >::Reset ( )
inline

Definition at line 197 of file XrdSsiRRTable.hh.

198  {XrdSsiMutexMon lck(rrtMutex);
199  std::vector<std::pair<T*,uint64_t>> tofin;
200  if (baseItem.item && baseItem.refcount > 0)
201  {if (!baseItem.deleted)
202  {baseItem.deleted = true;
203  baseItem.refcount--;
204  baseItem.deferedFinalize = true;
205  }
206  if (baseItem.refcount <= 0)
207  {tofin.push_back(std::make_pair(baseItem.item,baseKey));}
208  }
209  for(auto it=theMap.begin(); it!=theMap.end(); ++it)
210  {ItemInfo &info = it->second;
211  if (info.refcount <= 0) continue;
212  if (!info.deleted)
213  {info.deleted = true;
214  info.refcount--;
215  info.deferedFinalize=true;
216  }
217  if (info.refcount <= 0) tofin.push_back(std::make_pair(info.item,it->first));
218  }
219  lck.UnLock();
220  for(auto &fpair : tofin)
221  {T* f=fpair.first;
222  uint64_t itemID=fpair.second;
223  wCond.Lock();
224  nDef++;
225  wCond.UnLock();
226  f->Finalize();
227  DeferredFinalizeDone(f, itemID);
228  }
229 
230  lck.Lock(&rrtMutex);
231  while(baseItem.item || theMap.size() != 0)
232  {wCond.Lock();
233  lck.UnLock();
234  do { wCond.Wait(); } while(nDef>0);
235  wCond.UnLock();
236  lck.Lock(&rrtMutex);
237  }
238  }
void DeferredFinalizeDone(T *item, uint64_t itemID)

References XrdSsiRRTable< T >::DeferredFinalizeDone(), XrdSysCondVar::Lock(), XrdSsiMutexMon::Lock(), XrdSsiMutexMon::UnLock(), XrdSysCondVar::UnLock(), and XrdSysCondVar::Wait().

Referenced by XrdSsiRRTable< T >::~XrdSsiRRTable().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: