XRootD
Loading...
Searching...
No Matches
XrdObject.icc
Go to the documentation of this file.
1/******************************************************************************/
2/* */
3/* X r d O b j e c t . i c c */
4/* */
5/* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */
6/* Produced by Andrew Hanushevsky for Stanford University under contract */
7/* DE-AC02-76-SFO0515 with the Department of Energy */
8/* */
9/* This file is part of the XRootD software suite. */
10/* */
11/* XRootD is free software: you can redistribute it and/or modify it under */
12/* the terms of the GNU Lesser General Public License as published by the */
13/* Free Software Foundation, either version 3 of the License, or (at your */
14/* option) any later version. */
15/* */
16/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
17/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
18/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
19/* License for more details. */
20/* */
21/* You should have received a copy of the GNU Lesser General Public License */
22/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
23/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
24/* */
25/* The copyright holder's institutional names and contributor's names may not */
26/* be used to endorse or promote products derived from this software without */
27/* specific prior written permission of the institution or contributor. */
28/******************************************************************************/
29
30#include "Xrd/XrdScheduler.hh"
31#include "XrdSys/XrdSysTrace.hh"
32
33/******************************************************************************/
34/* D o I t */
35/******************************************************************************/
36
37template <class T>
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 }
84
85/******************************************************************************/
86/* S e t */
87/******************************************************************************/
88
89template <class T>
90void XrdObjectQ<T>::Set(int inQMax, time_t agemax)
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}
#define SYSTRACE(obj, usr, epn, txt, dbg)
XrdJob(const char *desc="")
Definition XrdJob.hh:51
const char * Comment
Definition XrdJob.hh:47
void Set(int inQMax, time_t agemax=1800)
Definition XrdObject.icc:90
void DoIt()
Definition XrdObject.icc:38