XRootD
Loading...
Searching...
No Matches
XrdCmsRTable.cc
Go to the documentation of this file.
1
/******************************************************************************/
2
/* */
3
/* X r d C m s R T a b l e . c c */
4
/* */
5
/* (c) 2007 by the Board of Trustees of the Leland Stanford, Jr., University */
6
/* All Rights Reserved */
7
/* Produced by Andrew Hanushevsky for Stanford University under contract */
8
/* DE-AC02-76-SFO0515 with the Department of Energy */
9
/* */
10
/* This file is part of the XRootD software suite. */
11
/* */
12
/* XRootD is free software: you can redistribute it and/or modify it under */
13
/* the terms of the GNU Lesser General Public License as published by the */
14
/* Free Software Foundation, either version 3 of the License, or (at your */
15
/* option) any later version. */
16
/* */
17
/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
18
/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
19
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
20
/* License for more details. */
21
/* */
22
/* You should have received a copy of the GNU Lesser General Public License */
23
/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
24
/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
25
/* */
26
/* The copyright holder's institutional names and contributor's names may not */
27
/* be used to endorse or promote products derived from this software without */
28
/* specific prior written permission of the institution or contributor. */
29
/******************************************************************************/
30
31
#include "
XrdCms/XrdCmsRTable.hh
"
32
#include "
XrdCms/XrdCmsTrace.hh
"
33
34
using namespace
XrdCms
;
35
36
/******************************************************************************/
37
/* G l o b a l s */
38
/******************************************************************************/
39
40
XrdCmsRTable
XrdCms::RTable
;
41
42
/******************************************************************************/
43
/* A d d */
44
/******************************************************************************/
45
46
short
XrdCmsRTable::Add
(
XrdCmsNode
*nP)
47
{
48
int
i;
49
50
// Find a free slot for this node.
51
//
52
myMutex.Lock();
53
for
(i = 1; i <
maxRD
; i++)
if
(!Rtable[i])
break
;
54
55
// Insert the node if found
56
//
57
if
(i >=
maxRD
) i = 0;
58
else
{Rtable[i] = nP;
59
if
(i > Hwm) Hwm = i;
60
}
61
62
// All done
63
//
64
myMutex.UnLock();
65
return
static_cast<
short
>
(i);
66
}
67
68
/******************************************************************************/
69
/* D e l */
70
/******************************************************************************/
71
72
void
XrdCmsRTable::Del
(
XrdCmsNode
*nP)
73
{
74
int
i;
75
76
// Find the slot for this node.
77
//
78
myMutex.Lock();
79
for
(i = 1; i <= Hwm; i++)
if
(Rtable[i] == nP)
break
;
80
81
// Remove the node if found
82
//
83
if
(i <= Hwm)
84
{Rtable[i] = 0;
85
if
(i == Hwm) {
while
(--i)
if
(Rtable[i])
break
; Hwm = i;}
86
}
87
88
// All done
89
//
90
myMutex.UnLock();
91
}
92
93
/******************************************************************************/
94
/* F i n d */
95
/******************************************************************************/
96
97
// Note that the caller *must* call Lock() prior to calling find. We do this
98
// because this is the only way we can interlock the use of the node object
99
// with deletion of that object as it must be removed prior to deletion.
100
101
XrdCmsNode
*
XrdCmsRTable::Find
(
short
Num,
int
Inst)
102
{
103
104
// Find the instance of the node in the indicated slot
105
//
106
if
(Num <= Hwm && Rtable[Num] && Rtable[Num]->Inst() == Inst)
107
return
Rtable[Num];
108
return
(
XrdCmsNode
*)0;
109
}
110
111
/******************************************************************************/
112
/* S e n d */
113
/******************************************************************************/
114
115
void
XrdCmsRTable::Send
(
const
char
*What,
const
char
*data,
int
dlen)
116
{
117
EPNAME
(
"Send"
);
118
int
i;
119
120
// Send the data to all nodes in this table
121
//
122
myMutex.Lock();
123
for
(i = 1; i <= Hwm; i++)
124
if
(Rtable[i])
125
{
DEBUG
(What <<
" to "
<<Rtable[i]->Ident);
126
Rtable[i]->Send(data, dlen);
127
}
128
myMutex.UnLock();
129
}
DEBUG
#define DEBUG(x)
Definition
XrdBwmTrace.hh:54
EPNAME
#define EPNAME(x)
Definition
XrdBwmTrace.hh:56
XrdCmsRTable.hh
XrdCmsTrace.hh
maxRD
#define maxRD
Definition
XrdCmsTypes.hh:44
XrdCmsNode
Definition
XrdCmsNode.hh:58
XrdCmsRTable
Definition
XrdCmsRTable.hh:40
XrdCmsRTable::Add
short Add(XrdCmsNode *nP)
Definition
XrdCmsRTable.cc:46
XrdCmsRTable::Del
void Del(XrdCmsNode *nP)
Definition
XrdCmsRTable.cc:72
XrdCmsRTable::Find
XrdCmsNode * Find(short Num, int Inst)
Definition
XrdCmsRTable.cc:101
XrdCmsRTable::Send
void Send(const char *What, const char *data, int dlen)
Definition
XrdCmsRTable.cc:115
XrdCms
Definition
YProtocol.hh:78
XrdCms::RTable
XrdCmsRTable RTable
Definition
XrdCmsRTable.cc:40
XrdCms
XrdCmsRTable.cc
Generated by
1.13.2