xrootd
Loading...
Searching...
No Matches
XrdObject.hh
Go to the documentation of this file.
1#ifndef __XRD_OBJECT_H__
2#define __XRD_OBJECT_H__
3/******************************************************************************/
4/* */
5/* X r d O b j e c t . h h */
6/* */
7/*(c) 2004 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 Deprtment 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 <cstring>
33#include <strings.h>
34#include <ctime>
35#include <sys/types.h>
36
37#include "Xrd/XrdJob.hh"
38
39// The classes here are templates for singly linked list handling that allows
40// elements to be added to either end but be removed only from the front. Most
41// objects in this package are managed in queues of this type.
42
43/******************************************************************************/
44/* x r d _ O b j e c t */
45/******************************************************************************/
46
47template <class T>
48class XrdObjectQ;
49
50template <class T>
52{
53public:
54friend class XrdObjectQ<T>;
55
56
57// Item() supplies the item value associated with itself (used with Next()).
58//
59T *objectItem() {return Item;}
60
61// Next() supplies the next list node.
62//
64
65// Set the item pointer
66//
67void setItem(T *ival) {Item = ival;}
68
69 XrdObject(T *ival=0) {Next = 0; Item = ival; QTime = 0;}
71
72private:
75time_t QTime; // Only used for time-managed objects
76};
77
78/******************************************************************************/
79/* x r d _ O b j e c t Q */
80/******************************************************************************/
81
82// Note to properly cleanup this type of queue you must call Set() at least
83// once to cause the time element to be sceduled.
84
85class XrdSysTrace;
86class XrdScheduler;
87
88template <class T>
89class XrdObjectQ : public XrdJob
90{
91public:
92
93inline T *Pop() {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 }
100
101inline void Push(XrdObject<T> *Node)
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 }
111
112 void Set(int inQMax, time_t agemax=1800);
113
114 void Set(XrdScheduler *sp, XrdSysTrace *tp, int TraceChk=0)
115 {Sched = sp; Trace = tp; TraceON = TraceChk;}
116
117 void DoIt();
118
119 XrdObjectQ(const char *id, const char *desc) : XrdJob(desc)
120 {Curage = Count = 0; Maxage = 0; TraceID = id;
121 MaxinQ = 32; MininQ = 16; First = 0;
122 }
123
125
126private:
127
134time_t Maxage;
138const char *TraceID;
139};
140
141#include "Xrd/XrdObject.icc"
142#endif
Definition XrdJob.hh:43
Definition XrdObject.hh:90
int MininQ
Definition XrdObject.hh:132
void Set(int inQMax, time_t agemax=1800)
int TraceON
Definition XrdObject.hh:137
int Count
Definition XrdObject.hh:130
void DoIt()
XrdSysTrace * Trace
Definition XrdObject.hh:136
XrdSysMutex QMutex
Definition XrdObject.hh:128
void Set(XrdScheduler *sp, XrdSysTrace *tp, int TraceChk=0)
Definition XrdObject.hh:114
const char * TraceID
Definition XrdObject.hh:138
int Curage
Definition XrdObject.hh:131
void Push(XrdObject< T > *Node)
Definition XrdObject.hh:101
~XrdObjectQ()
Definition XrdObject.hh:124
int MaxinQ
Definition XrdObject.hh:133
T * Pop()
Definition XrdObject.hh:93
XrdScheduler * Sched
Definition XrdObject.hh:135
XrdObjectQ(const char *id, const char *desc)
Definition XrdObject.hh:119
time_t Maxage
Definition XrdObject.hh:134
XrdObject< T > * First
Definition XrdObject.hh:129
Definition XrdObject.hh:52
XrdObject< T > * nextObject()
Definition XrdObject.hh:63
time_t QTime
Definition XrdObject.hh:75
T * Item
Definition XrdObject.hh:74
T * objectItem()
Definition XrdObject.hh:59
~XrdObject()
Definition XrdObject.hh:70
XrdObject(T *ival=0)
Definition XrdObject.hh:69
void setItem(T *ival)
Definition XrdObject.hh:67
XrdObject< T > * Next
Definition XrdObject.hh:73
Definition XrdScheduler.hh:46
Definition XrdSysPthread.hh:165
void Lock()
Definition XrdSysPthread.hh:222
void UnLock()
Definition XrdSysPthread.hh:224
Definition XrdSysTrace.hh:49