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
47
template
<
class
T>
48
class
XrdObjectQ
;
49
50
template
<
class
T>
51
class
XrdObject
52
{
53
public
:
54
friend
class
XrdObjectQ
<T>;
55
56
57
// Item() supplies the item value associated with itself (used with Next()).
58
//
59
T *
objectItem
() {
return
Item;}
60
61
// Next() supplies the next list node.
62
//
63
XrdObject<T>
*
nextObject
() {
return
Next;}
64
65
// Set the item pointer
66
//
67
void
setItem
(T *ival) {Item = ival;}
68
69
XrdObject
(T *ival=0) {Next = 0; Item = ival; QTime = 0;}
70
~XrdObject
() {}
71
72
private
:
73
XrdObject<T>
*Next;
74
T *Item;
75
time_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
85
class
XrdSysTrace
;
86
class
XrdScheduler
;
87
88
template
<
class
T>
89
class
XrdObjectQ
:
public
XrdJob
90
{
91
public
:
92
93
inline
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
101
inline
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
124
~XrdObjectQ
() {}
125
126
private
:
127
128
XrdSysMutex
QMutex;
129
XrdObject<T>
*First;
130
int
Count;
131
int
Curage;
132
int
MininQ;
133
int
MaxinQ;
134
time_t Maxage;
135
XrdScheduler
*Sched;
136
XrdSysTrace
*Trace;
137
int
TraceON;
138
const
char
*TraceID;
139
};
140
141
#include "
Xrd/XrdObject.icc
"
142
#endif
XrdJob.hh
XrdObject.icc
XrdJob
Definition
XrdJob.hh:43
XrdObjectQ
Definition
XrdObject.hh:90
XrdObjectQ::DoIt
void DoIt()
Definition
XrdObject.icc:38
XrdObjectQ::Set
void Set(XrdScheduler *sp, XrdSysTrace *tp, int TraceChk=0)
Definition
XrdObject.hh:114
XrdObjectQ::Push
void Push(XrdObject< T > *Node)
Definition
XrdObject.hh:101
XrdObjectQ::~XrdObjectQ
~XrdObjectQ()
Definition
XrdObject.hh:124
XrdObjectQ::Pop
T * Pop()
Definition
XrdObject.hh:93
XrdObjectQ::XrdObjectQ
XrdObjectQ(const char *id, const char *desc)
Definition
XrdObject.hh:119
XrdObject
Definition
XrdObject.hh:52
XrdObject::nextObject
XrdObject< T > * nextObject()
Definition
XrdObject.hh:63
XrdObject::objectItem
T * objectItem()
Definition
XrdObject.hh:59
XrdObject::~XrdObject
~XrdObject()
Definition
XrdObject.hh:70
XrdObject::XrdObject
XrdObject(T *ival=0)
Definition
XrdObject.hh:69
XrdObject::setItem
void setItem(T *ival)
Definition
XrdObject.hh:67
XrdScheduler
Definition
XrdScheduler.hh:47
XrdSysMutex
Definition
XrdSysPthread.hh:165
XrdSysMutex::Lock
void Lock()
Definition
XrdSysPthread.hh:222
XrdSysMutex::UnLock
void UnLock()
Definition
XrdSysPthread.hh:224
XrdSysTrace
Definition
XrdSysTrace.hh:49
Xrd
XrdObject.hh
Generated by
1.9.8