From 2fbd8b690fee9505fbede2bbbf3599f29fd6acbd Mon Sep 17 00:00:00 2001 From: kevin Date: Wed, 20 Jan 2021 13:07:36 -0500 Subject: [PATCH] cwmutex.h : Added signalCondVar(). --- cwMutex.cpp | 20 ++++++++++++++++++-- cwMutex.h | 5 +++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/cwMutex.cpp b/cwMutex.cpp index 96c3aa4..6981df6 100644 --- a/cwMutex.cpp +++ b/cwMutex.cpp @@ -27,10 +27,10 @@ namespace cw int sysRC; if((sysRC = pthread_cond_destroy(&p->cvar)) != 0) - cwLogSysError(kObjFreeFailRC,sysRC,"Thread condition var. destroy failed."); + rc = cwLogSysError(kObjFreeFailRC,sysRC,"Thread condition var. destroy failed."); else if((sysRC = pthread_mutex_destroy(&p->mutex)) != 0) - cwLogSysError(kObjFreeFailRC,sysRC,"Thread mutex destroy failed."); + rc = cwLogSysError(kObjFreeFailRC,sysRC,"Thread mutex destroy failed."); else mem::release(p); @@ -53,6 +53,8 @@ cw::rc_t cw::mutex::create( handle_t& h ) else if((sysRC = pthread_cond_init(&p->cvar,NULL)) != 0 ) cwLogSysError(kObjAllocFailRC,sysRC,"Thread Condition var. create failed."); + + h.set(p); return rc; } @@ -155,3 +157,17 @@ cw::rc_t cw::mutex::waitOnCondVar( handle_t h, bool lockThenWaitFl, unsigned tim } + +cw::rc_t cw::mutex::signalCondVar( handle_t h) +{ + + rc_t rc = kOkRC; + mutex_t* p = _handleToPtr(h); + + int sysRC; + if((sysRC = pthread_cond_signal(&p->cvar)) != 0 ) + rc = cwLogSysError(kOpFailRC,sysRC,"Thread cond var. signaling failed."); + + return rc; +} + diff --git a/cwMutex.h b/cwMutex.h index f1cdf76..26dc58b 100644 --- a/cwMutex.h +++ b/cwMutex.h @@ -14,8 +14,13 @@ namespace cw rc_t lock( handle_t h ); rc_t unlock( handle_t h ); + // Set 'lockThenWaitFl' if the function should lock the mutex prior to waiting. + // If 'lockThenWaitFl' is false then the function assumes the mutex is already locked + // and directly waits. If 'lockThenWaitFl' is set and the mutex is not already locked + // then the result is undefined. rc_t waitOnCondVar( handle_t h, bool lockThenWaitFl, unsigned timeOutMs ); + rc_t signalCondVar( handle_t h); } }