Loading...
Searching...
No Matches
XrdOucSid Class Reference

`#include <XrdOucSid.hh>`

Collaboration diagram for XrdOucSid:

## Classes

union | theSid
| The type to pass to Obtain(). Simply cast the char[2] to (theSid *). More...

## Public Member Functions

| XrdOucSid (int numSid=256, bool mtproof=true, XrdOucSid *glblSid=0)
| ~XrdOucSid ()
bool | Obtain (theSid *sidP)
bool | Release (theSid *sidP)
void | Reset ()

## Detailed Description

This class implements a fast bit vector based stream ID generator. When stream ID's are generated on a connection basis, each connection can allocate a local SID object sizing the bit vector to match the expected number of simultaneous stream ID's in order to save memory. In order to accomodate overflows, the local object can be initialized with a global SID object that be used to obtain stream ID's when the local object runs out. See the constructor description for the details.

Definition at line 45 of file XrdOucSid.hh.

## Class Documentation

## XrdOucSid::theSid

union XrdOucSid::theSid

The type to pass to Obtain(). Simply cast the char[2] to (theSid *).

Definition at line 53 of file XrdOucSid.hh.

Collaboration diagram for XrdOucSid::theSid:

Class Members
char | sidC[2] |
short | sidS |

## Constructor & Destructor Documentation

## XrdOucSid()

XrdOucSid::XrdOucSid | ( | int | numSid = 256,
|  | bool | mtproof = true,
|  | XrdOucSid * | glblSid = 0 )

Constructor

Parameters

  numSid | the maximum number of stream ID's that this object can allocate. The value is rounded up to the next multiple of eight. Every 8 ID's requires one byte of memory. Normally, stream ID's range from 0 to 32767, though technically can go to 64K-1 but are then represented as a negative short.
  mtproof | When true (the default) the object obtains a lock before doing any operations. When false, it does not and must be protected, if need be, by some other serialization.
  glblSid | a pointer to another SID object that can be used to obtain stream ID's should this object run out of them. Typically, this is a global pool of stream ID's.

Definition at line 37 of file XrdOucSid.cc.

{
// Set obvious values
//
sidLock = mtproof;
globalSid = glblSid;
// Calculate actual values
//
sidSize = (numSid / 8) + ((numSid % 8 ? 1 : 0) * 8);
sidMax = sidSize * 8;
sidFree = 0;
// Allocate a sid table for the number we want
//
sidVec = (unsigned char *)malloc(sidSize);
memset(sidVec, 255, sidSize);
}

References XrdOucSid().

Referenced by XrdOucSid().

Here is the call graph for this function:
Here is the caller graph for this function:

## ~XrdOucSid()

XrdOucSid::~XrdOucSid | ( |  | ) |

Destructor. Only this object is destroyed. The global object, if any, is not alteered in any way.

Definition at line 61 of file XrdOucSid.cc.

{
if (sidVec) free(sidVec);
}

## Member Function Documentation

## Obtain()

bool XrdOucSid::Obtain | ( | XrdOucSid::theSid * | sidP | ) |

Obtain a stream ID. When not needed use Release() to recycle them.

Parameters

  sidP | -> the place where the new stream ID is to be placed.

Returns
  true a stream ID was allocated.
  false no more stream ID's are available. The sidP target was not altered (i.e. does not contain a stream ID).

Definition at line 70 of file XrdOucSid.cc.

{
// 0000 0001 0010 0011 0100 0101 0110 0111
static const // 1000 1001 1010 1011 1100 1101 1110 1111
unsigned char mask[] = {0x00,0x11,0x22,0x11,0x44,0x11,0x22,0x11,
0x88,0x11,0x22,0x11,0x44,0x11,0x22,0x11};
bool aOK = true;
// Lock if need be
//
if (sidLock) sidMutex.Lock();
// Realign the vector
//
while(sidFree < sidSize && sidVec[sidFree] == 0x00) sidFree++;
// Allocate a local free sid if we actually have one free. Otherwise, try to
// allocate one from the global sid table.
//
if (sidFree < sidSize)
{int sidMask, sidNum, sidByte = sidVec[sidFree] & 0xff;
if (sidByte & 0x0f)
{sidMask = mask[sidByte & 0x0f] & 0x0f;
sidNum = (sidMask > 4 ? 3 : sidMask>>1);
} else {
sidMask = mask[sidByte >> 4] & 0xf0;
sidNum = (sidMask > 64 ? 7 : (sidMask>>5) + 4);
}
sidVec[sidFree] &= ~sidMask;
sidP->sidS = (sidFree * 8) + sidNum;
} else if (globalSid)
{aOK = globalSid->Obtain(sidP);
sidP->sidS += sidMax;
} else aOK = false;
// Unlock if locked and return result
//
if (sidLock) sidMutex.UnLock();
return aOK;
}
XrdProxy::sidP
XrdOucSid * sidP
Definition XrdPss.cc:107

Referenced by XrdPssUrlInfo::setID().

Here is the caller graph for this function:

## Release()

bool XrdOucSid::Release | ( | XrdOucSid::theSid * | sidP | ) |

Release a stream ID using the stream ID value.

Parameters

  sidP | -> to the stream ID cast as a theSid pointer.

Returns
  true the stream ID was released and may be reassigned.
  false the stream ID is invalid. No action performed.

Definition at line 115 of file XrdOucSid.cc.

{
static const // 0 1 2 3 4 5 6 7
unsigned char mask[] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
bool aOK = true;
// Lock if need be
//
if (sidLock) sidMutex.Lock();
// If this is a local sid, then handle it locally. Otherwise, try releasing
// using the global sid pool.
//
if (sidP->sidS < sidMax)
{int sidIdx = (sidP->sidS)>>3;
sidVec[sidIdx] |= mask[(sidP->sidS)%8];
if (sidIdx < sidFree) sidFree = sidIdx;
} else if (globalSid)
{short gSid = sidP->sidS - sidMax;
aOK = globalSid->Release((theSid *)&gSid);
} else aOK = false;
// Unlock if locked and return result
//
if (sidLock) sidMutex.UnLock();
return aOK;
}
XrdOucSid::Release
bool Release(theSid *sidP)
Definition XrdOucSid.cc:115
XrdOucSid::theSid
The type to pass to Obtain(). Simply cast the char[2] to (theSid *).
Definition XrdOucSid.hh:53

References Release().

Referenced by Release().

Here is the call graph for this function:
Here is the caller graph for this function:

## Reset()

void XrdOucSid::Reset | ( |  | ) |

Unassign all stream ID's as if the object were newly allocated. Any global stream ID object associated with this object is not reset.

Definition at line 147 of file XrdOucSid.cc.

{
if (sidLock) sidMutex.Lock();
if (sidVec) memset(sidVec, 0xff, sidSize);
if (sidLock) sidMutex.UnLock();
}

The documentation for this class was generated from the following files:

- XrdOucSid.hh
- XrdOucSid.cc