From 8934213a6a780fcdafc2ce64bce8410e268baa88 Mon Sep 17 00:00:00 2001 From: Alja Mrak-Tadel Date: Wed, 17 Aug 2016 13:54:12 -0700 Subject: [PATCH] Protect against spurious wakeups in SyncResponseHandler. --- src/XrdCl/XrdClMessageUtils.hh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/XrdCl/XrdClMessageUtils.hh b/src/XrdCl/XrdClMessageUtils.hh index f71bdad5174..34be84b4f64 100644 --- a/src/XrdCl/XrdClMessageUtils.hh +++ b/src/XrdCl/XrdClMessageUtils.hh @@ -44,14 +44,13 @@ namespace XrdCl SyncResponseHandler(): pStatus(0), pResponse(0), - pSem( new Semaphore(0) ) {} + pCondVar(0) {} //------------------------------------------------------------------------ //! Destructor //------------------------------------------------------------------------ virtual ~SyncResponseHandler() { - delete pSem; } @@ -61,9 +60,10 @@ namespace XrdCl virtual void HandleResponse( XRootDStatus *status, AnyObject *response ) { + XrdSysCondVarHelper scopedLock(pCondVar); pStatus = status; pResponse = response; - pSem->Post(); + pCondVar.Broadcast(); } //------------------------------------------------------------------------ @@ -87,7 +87,10 @@ namespace XrdCl //------------------------------------------------------------------------ void WaitForResponse() { - pSem->Wait(); + XrdSysCondVarHelper scopedLock(pCondVar); + while (pStatus == 0) { + pCondVar.Wait(); + } } private: @@ -96,9 +99,10 @@ namespace XrdCl XRootDStatus *pStatus; AnyObject *pResponse; - Semaphore *pSem; + XrdSysCondVar pCondVar; }; + //---------------------------------------------------------------------------- // We're not interested in the response just commit suicide //----------------------------------------------------------------------------