XRootD
XrdObjectQ< T > Class Template Reference

#include <XrdObject.hh>

+ Inheritance diagram for XrdObjectQ< T >:
+ Collaboration diagram for XrdObjectQ< T >:

Public Member Functions

 XrdObjectQ (const char *id, const char *desc)
 
 ~XrdObjectQ ()
 
void DoIt ()
 
T * Pop ()
 
void Push (XrdObject< T > *Node)
 
void Set (int inQMax, time_t agemax=1800)
 
void Set (XrdScheduler *sp, XrdSysTrace *tp, int TraceChk=0)
 
- Public Member Functions inherited from XrdJob
 XrdJob (const char *desc="")
 
virtual ~XrdJob ()
 

Additional Inherited Members

- Public Attributes inherited from XrdJob
const char * Comment
 
XrdJobNextJob
 

Detailed Description

template<class T>
class XrdObjectQ< T >

Definition at line 89 of file XrdObject.hh.

Constructor & Destructor Documentation

◆ XrdObjectQ()

template<class T >
XrdObjectQ< T >::XrdObjectQ ( const char *  id,
const char *  desc 
)
inline

Definition at line 119 of file XrdObject.hh.

119  : XrdJob(desc)
120  {Curage = Count = 0; Maxage = 0; TraceID = id;
121  MaxinQ = 32; MininQ = 16; First = 0;
122  }
XrdJob(const char *desc="")
Definition: XrdJob.hh:51

◆ ~XrdObjectQ()

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

Definition at line 124 of file XrdObject.hh.

124 {}

Member Function Documentation

◆ DoIt()

template<class T >
void XrdObjectQ< T >::DoIt
virtual

Implements XrdJob.

Definition at line 38 of file XrdObject.icc.

39 {
40  XrdObject<T> *pp, *p;
41  int oldcnt, agemax;
42 
43 // Lock the anchor and see if we met the threshold for deletion
44 //
45  QMutex.Lock();
46  agemax = Maxage;
47  if ((oldcnt = Count) > MininQ)
48  {
49  // Prepare to scan down the queue.
50  //
51  if ((pp = First)) p = pp->Next;
52  else p = 0;
53 
54  // Find the first object that's been idle for too long
55  //
56  while(p && (p->QTime >= Curage)) {pp = p; p = p->Next;}
57 
58  // Now delete half of the idle objects. The object queue element must be
59  // part of the actual object being deleted for this to properly work.
60  //
61  if (pp) while(p)
62  {pp->Next = p->Next; delete p->Item;
63  Count--;
64  p = ((pp = pp->Next) ? pp->Next : 0);
65  }
66  }
67 
68 // Increase the age and unlock the queue
69 //
70  Curage++;
71  QMutex.UnLock();
72 
73 // Trace as needed
74 //
75  if (TraceON && Trace->Tracing(TraceON))
76  {SYSTRACE(Trace->, 0, TraceID, 0,
77  Comment <<" trim done; " <<Count <<" of " <<oldcnt <<" kept");
78  }
79 
80 // Reschedule ourselves if we must do so
81 //
82  if (agemax > 0) Sched->Schedule((XrdJob *)this, agemax+time(0));
83  }
#define SYSTRACE(obj, usr, epn, txt, dbg)
Definition: XrdSysTrace.hh:45
Definition: XrdJob.hh:43
const char * Comment
Definition: XrdJob.hh:47
void Schedule(XrdJob *jp)
bool Tracing(int mask)
Definition: XrdSysTrace.hh:62

References XrdGlobal::Sched, XrdScheduler::Schedule(), SYSTRACE, XrdCms::Trace, and XrdSysTrace::Tracing().

+ Here is the call graph for this function:

◆ Pop()

template<class T >
T* XrdObjectQ< T >::Pop ( )
inline

Definition at line 93 of file XrdObject.hh.

93  {XrdObject<T> *Node;
94  QMutex.Lock();
95  if ((Node = First)) {First = First->Next; Count--;}
96  QMutex.UnLock();
97  if (Node) return Node->Item;
98  return (T *)0;
99  }

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

Referenced by XrdXrootdTransit::Alloc(), XrdHttpProtocol::Match(), and XrdXrootdProtocol::Match().

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

◆ Push()

template<class T >
void XrdObjectQ< T >::Push ( XrdObject< T > *  Node)
inline

Definition at line 101 of file XrdObject.hh.

102  {Node->QTime = Curage;
103  QMutex.Lock();
104  if (Count >= MaxinQ) delete Node->Item;
105  else {Node->Next = First;
106  First = Node;
107  Count++;
108  }
109  QMutex.UnLock();
110  }

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

Referenced by XrdXrootdTransit::Disc(), XrdHttpProtocol::Recycle(), XrdXrootdTransit::Recycle(), and XrdXrootdProtocol::Recycle().

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

◆ Set() [1/2]

template<class T >
void XrdObjectQ< T >::Set ( int  inQMax,
time_t  agemax = 1800 
)

Definition at line 90 of file XrdObject.icc.

91 {
92 
93 // Lock the data area and set the values
94 //
95  QMutex.Lock();
96  MaxinQ = inQMax; Maxage = agemax;
97  if (!(MininQ = inQMax/2)) MininQ = 1;
98  QMutex.UnLock();
99 
100 // Schedule ourselves using the new values
101 //
102  if (agemax > 0) Sched->Schedule((XrdJob *)this, agemax+time(0));
103 }

References XrdGlobal::Sched, and XrdScheduler::Schedule().

Referenced by XrdHttpProtocol::Configure(), XrdXrootdProtocol::Configure(), and XrdXrootdTransit::Init().

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

◆ Set() [2/2]

template<class T >
void XrdObjectQ< T >::Set ( XrdScheduler sp,
XrdSysTrace tp,
int  TraceChk = 0 
)
inline

Definition at line 114 of file XrdObject.hh.

115  {Sched = sp; Trace = tp; TraceON = TraceChk;}

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