Skip to content

Commit

Permalink
Protect against spurious wakeups in SyncResponseHandler.
Browse files Browse the repository at this point in the history
  • Loading branch information
alja committed Oct 31, 2016
1 parent 224ebcc commit 8934213
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/XrdCl/XrdClMessageUtils.hh
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,13 @@ namespace XrdCl
SyncResponseHandler():
pStatus(0),
pResponse(0),
pSem( new Semaphore(0) ) {}
pCondVar(0) {}

//------------------------------------------------------------------------
//! Destructor
//------------------------------------------------------------------------
virtual ~SyncResponseHandler()
{
delete pSem;
}


Expand All @@ -61,9 +60,10 @@ namespace XrdCl
virtual void HandleResponse( XRootDStatus *status,
AnyObject *response )
{
XrdSysCondVarHelper scopedLock(pCondVar);
pStatus = status;
pResponse = response;
pSem->Post();
pCondVar.Broadcast();
}

//------------------------------------------------------------------------
Expand All @@ -87,7 +87,10 @@ namespace XrdCl
//------------------------------------------------------------------------
void WaitForResponse()
{
pSem->Wait();
XrdSysCondVarHelper scopedLock(pCondVar);
while (pStatus == 0) {
pCondVar.Wait();
}
}

private:
Expand All @@ -96,9 +99,10 @@ namespace XrdCl

XRootDStatus *pStatus;
AnyObject *pResponse;
Semaphore *pSem;
XrdSysCondVar pCondVar;
};


//----------------------------------------------------------------------------
// We're not interested in the response just commit suicide
//----------------------------------------------------------------------------
Expand Down

0 comments on commit 8934213

Please sign in to comment.