Loading...
Searching...
No Matches
XrdSysXSLock Class Reference

`#include <XrdSysXSLock.hh>`

Collaboration diagram for XrdSysXSLock:

## Public Member Functions

| XrdSysXSLock ()
| ~XrdSysXSLock ()
void | Lock (const XrdSysXS_Type usage)
void | UnLock (const XrdSysXS_Type usage=xs_None)

## Detailed Description

Definition at line 44 of file XrdSysXSLock.hh.

## Constructor & Destructor Documentation

## XrdSysXSLock()

XrdSysXSLock::XrdSysXSLock | ( |  | ) |

inline

Definition at line 52 of file XrdSysXSLock.hh.

: cur_usage(xs_None), cur_count(0), exc_wait(0),
shr_wait(0), toggle(0), WantShr(0), WantExc(0) {}
xs_None
@ xs_None
Definition XrdSysXSLock.hh:38

References xs_None.

## ~XrdSysXSLock()

XrdSysXSLock::~XrdSysXSLock | ( |  | ) |

Definition at line 38 of file XrdSysXSLock.cc.

{
// Prevent usage while destroying object but make sure no one else is using it
//
LockContext.Lock();
if (cur_count || shr_wait || exc_wait)
{LockContext.UnLock();
abort();
}
LockContext.UnLock();
}

## Member Function Documentation

## Lock()

void XrdSysXSLock::Lock | ( | const XrdSysXS_Type | usage | ) |

Definition at line 55 of file XrdSysXSLock.cc.

{
// Serialize access to this object
//
LockContext.Lock();
// This loop continues until we can acquire the resource. We are gauranteed
// to eventually acquire it regardless of the unblocking order.
//
while(cur_count)
{
// If usage is compatible with current usage get the lock right away
//
if (usage == xs_Shared && cur_usage == xs_Shared && !exc_wait) break;
// Indicate that we are waiting
//
if (usage == xs_Shared) shr_wait++;
else exc_wait++;
// Usage is not compatible. We must wait for current lock mode to end
//
LockContext.UnLock();
if (usage == xs_Shared) WantShr.Wait();
else WantExc.Wait();
LockContext.Lock();
}
// We obtained the right to use this object
//
cur_usage = usage;
cur_count++;
LockContext.UnLock();
}
usage
void usage()
Definition XrdClReplay.cc:1072
xs_Shared
@ xs_Shared
Definition XrdSysXSLock.hh:38

References usage(), and xs_Shared.

Here is the call graph for this function:

## UnLock()

void XrdSysXSLock::UnLock | ( | const XrdSysXS_Type | usage = xs_None | ) |

Definition at line 95 of file XrdSysXSLock.cc.

{
// Serialize access to our data
//
LockContext.Lock();
// Make sure that the lock is currently being used
//
if (!cur_count)
{LockContext.UnLock();
std::cerr << "XSLock: Attempt to unlock inactive lock." <<std::endl;
throw "XSLock: unlocking inactive lock.";
}
// Verify that usage is correct
//
if (usage && cur_usage != usage)
{LockContext.UnLock();
std::cerr << "XSLock: Incorrect unlock usage - "
<< (cur_usage == xs_Shared ? "shr" : "exc") << "!="
<< ( usage == xs_Shared ? "shr" : "exc") << std::endl;
throw "XSLock: invalid unlock usage specified.";
}
// Unlock the current object. If no locks exist then check if we can let another
// thread use this object. The logic is tricky but we are trying to avoid
// starvation in an environment that has no thread ordering.
//
cur_count--;
if (!cur_count)
if (exc_wait && (toggle || !shr_wait))
{toggle = 0; WantExc.Post(); exc_wait--;}
else {while(shr_wait) {WantShr.Post(); shr_wait--;}
toggle = 1;}
else if (!toggle) {while(shr_wait) {WantShr.Post(); shr_wait--;}
toggle = 1;}
LockContext.UnLock();
}

References usage(), and xs_Shared.

Here is the call graph for this function:

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

- XrdSysXSLock.hh
- XrdSysXSLock.cc