xrootd
Main Page
Namespaces
Classes
Files
File List
File Members
src
Xrd
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
/* All Rights Reserved. See XrdInfo.cc for complete License Terms */
9
/*Produced by Andrew Hanushevsky for Stanford University under contract */
10
/* DE-AC03-76-SFO0515 with the Deprtment of Energy */
11
/******************************************************************************/
12
13
// $Id$
14
15
#include <string.h>
16
#include <strings.h>
17
#include <time.h>
18
#include <sys/types.h>
19
20
#include "
Xrd/XrdJob.hh
"
21
22
// The classes here are templates for singly linked list handling that allows
23
// elements to be added to either end but be removed only from the front. Most
24
// objects in this package are managed in queues of this type.
25
26
/******************************************************************************/
27
/* x r d _ O b j e c t */
28
/******************************************************************************/
29
30
template
<
class
T>
31
class
XrdObjectQ
;
32
33
template
<
class
T>
34
class
XrdObject
35
{
36
public
:
37
friend
class
XrdObjectQ
<T>;
38
39
40
// Item() supplies the item value associated with itself (used with Next()).
41
//
42
T *
objectItem
() {
return
Item
;}
43
44
// Next() supplies the next list node.
45
//
46
XrdObject<T>
*
nextObject
() {
return
Next
;}
47
48
// Set the item pointer
49
//
50
void
setItem
(T *ival) {
Item
= ival;}
51
52
XrdObject
(T *ival=0) {
Next
= 0;
Item
= ival;
QTime
= 0;}
53
~XrdObject
() {}
54
55
private
:
56
XrdObject<T>
*
Next
;
57
T *
Item
;
58
time_t
QTime
;
// Only used for time-managed objects
59
};
60
61
/******************************************************************************/
62
/* x r d _ O b j e c t Q */
63
/******************************************************************************/
64
65
// Note to properly cleanup this type of queue you must call Set() at least
66
// once to cause the time element to be sceduled.
67
68
class
XrdOucTrace
;
69
class
XrdScheduler
;
70
71
template
<
class
T>
72
class
XrdObjectQ
:
public
XrdJob
73
{
74
public
:
75
76
inline
T *
Pop
() {
XrdObject<T>
*Node;
77
QMutex
.
Lock
();
78
if
((Node =
First
)) {
First
=
First
->Next;
Count
--;}
79
QMutex
.
UnLock
();
80
if
(Node)
return
Node->
Item
;
81
return
(T *)0;
82
}
83
84
inline
void
Push
(
XrdObject<T>
*Node)
85
{Node->
QTime
=
Curage
;
86
QMutex
.
Lock
();
87
if
(
Count
>=
MaxinQ
)
delete
Node->
Item
;
88
else
{Node->
Next
=
First
;
89
First
= Node;
90
Count
++;
91
}
92
QMutex
.
UnLock
();
93
}
94
95
void
Set
(
int
inQMax, time_t agemax=1800);
96
97
void
Set
(
XrdScheduler
*sp,
XrdOucTrace
*tp,
int
TraceChk=0)
98
{
Sched
= sp;
Trace
= tp;
TraceON
= TraceChk;}
99
100
void
DoIt
();
101
102
XrdObjectQ
(
const
char
*
id
,
const
char
*desc) :
XrdJob
(desc)
103
{
Curage
=
Count
= 0;
Maxage
= 0;
TraceID
= id;
104
MaxinQ
= 32;
MininQ
= 16;
First
= 0;
105
}
106
107
~XrdObjectQ
() {}
108
109
private
:
110
111
XrdSysMutex
QMutex
;
112
XrdObject<T>
*
First
;
113
int
Count
;
114
int
Curage
;
115
int
MininQ
;
116
int
MaxinQ
;
117
time_t
Maxage
;
118
XrdScheduler
*
Sched
;
119
XrdOucTrace
*
Trace
;
120
int
TraceON
;
121
const
char
*
TraceID
;
122
};
123
124
#include "
Xrd/XrdObject.icc
"
125
#endif
Generated by
1.8.1.2