|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r80171 - trunk/boost/interprocess/sync
From: igaztanaga_at_[hidden]
Date: 2012-08-24 14:11:05
Author: igaztanaga
Date: 2012-08-24 14:11:04 EDT (Fri, 24 Aug 2012)
New Revision: 80171
URL: http://svn.boost.org/trac/boost/changeset/80171
Log:
Corrected bugs in condition variable time_wait calls
Text files modified:
trunk/boost/interprocess/sync/interprocess_sharable_mutex.hpp | 50 ++++++++++++++++++++++++----------------
trunk/boost/interprocess/sync/interprocess_upgradable_mutex.hpp | 36 ++++++++++++++++++++--------
2 files changed, 56 insertions(+), 30 deletions(-)
Modified: trunk/boost/interprocess/sync/interprocess_sharable_mutex.hpp
==============================================================================
--- trunk/boost/interprocess/sync/interprocess_sharable_mutex.hpp (original)
+++ trunk/boost/interprocess/sync/interprocess_sharable_mutex.hpp 2012-08-24 14:11:04 EDT (Fri, 24 Aug 2012)
@@ -117,8 +117,8 @@
//to use atomic instructions in the future
struct control_word_t
{
- unsigned exclusive_in : 1;
- unsigned num_upr_shar : sizeof(unsigned)*CHAR_BIT-1;
+ unsigned exclusive_in : 1;
+ unsigned num_shared : sizeof(unsigned)*CHAR_BIT-1;
} m_ctrl;
interprocess_mutex m_mut;
@@ -166,7 +166,7 @@
inline interprocess_sharable_mutex::interprocess_sharable_mutex()
{
this->m_ctrl.exclusive_in = 0;
- this->m_ctrl.num_upr_shar = 0;
+ this->m_ctrl.num_shared = 0;
}
inline interprocess_sharable_mutex::~interprocess_sharable_mutex()
@@ -189,7 +189,7 @@
exclusive_rollback rollback(this->m_ctrl, this->m_first_gate);
//Now wait until all readers are gone
- while (this->m_ctrl.num_upr_shar){
+ while (this->m_ctrl.num_shared){
this->m_second_gate.wait(lock);
}
rollback.release();
@@ -203,7 +203,7 @@
//or sharable mark return false;
if(!lock.owns()
|| this->m_ctrl.exclusive_in
- || this->m_ctrl.num_upr_shar){
+ || this->m_ctrl.num_shared){
return false;
}
this->m_ctrl.exclusive_in = 1;
@@ -223,8 +223,12 @@
//The exclusive lock must block in the first gate
//if an exclusive lock has been acquired
while (this->m_ctrl.exclusive_in){
- if(!this->m_first_gate.timed_wait(lock, abs_time))
- return !this->m_ctrl.exclusive_in;
+ if(!this->m_first_gate.timed_wait(lock, abs_time)){
+ if(this->m_ctrl.exclusive_in){
+ return false;
+ }
+ break;
+ }
}
//Mark that exclusive lock has been acquired
@@ -234,9 +238,12 @@
exclusive_rollback rollback(this->m_ctrl, this->m_first_gate);
//Now wait until all readers are gone
- while (this->m_ctrl.num_upr_shar){
+ while (this->m_ctrl.num_shared){
if(!this->m_second_gate.timed_wait(lock, abs_time)){
- return !(this->m_ctrl.num_upr_shar);
+ if(this->m_ctrl.num_shared){
+ return false;
+ }
+ break;
}
}
rollback.release();
@@ -260,12 +267,12 @@
//if an exclusive lock has been acquired
//or there are too many sharable locks
while(this->m_ctrl.exclusive_in
- || this->m_ctrl.num_upr_shar == constants::max_readers){
+ || this->m_ctrl.num_shared == constants::max_readers){
this->m_first_gate.wait(lock);
}
//Increment sharable count
- ++this->m_ctrl.num_upr_shar;
+ ++this->m_ctrl.num_shared;
}
inline bool interprocess_sharable_mutex::try_lock_sharable()
@@ -277,12 +284,12 @@
//or there are too many sharable locks
if(!lock.owns()
|| this->m_ctrl.exclusive_in
- || this->m_ctrl.num_upr_shar == constants::max_readers){
+ || this->m_ctrl.num_shared == constants::max_readers){
return false;
}
//Increment sharable count
- ++this->m_ctrl.num_upr_shar;
+ ++this->m_ctrl.num_shared;
return true;
}
@@ -300,15 +307,18 @@
//if an exclusive lock has been acquired
//or there are too many sharable locks
while (this->m_ctrl.exclusive_in
- || this->m_ctrl.num_upr_shar == constants::max_readers){
+ || this->m_ctrl.num_shared == constants::max_readers){
if(!this->m_first_gate.timed_wait(lock, abs_time)){
- return!(this->m_ctrl.exclusive_in
- || this->m_ctrl.num_upr_shar == constants::max_readers);
+ if(this->m_ctrl.exclusive_in
+ || this->m_ctrl.num_shared == constants::max_readers){
+ return false;
+ }
+ break;
}
}
//Increment sharable count
- ++this->m_ctrl.num_upr_shar;
+ ++this->m_ctrl.num_shared;
return true;
}
@@ -316,13 +326,13 @@
{
scoped_lock_t lock(m_mut);
//Decrement sharable count
- --this->m_ctrl.num_upr_shar;
- if (this->m_ctrl.num_upr_shar == 0){
+ --this->m_ctrl.num_shared;
+ if (this->m_ctrl.num_shared == 0){
this->m_second_gate.notify_one();
}
//Check if there are blocked sharables because of
//there were too many sharables
- else if(this->m_ctrl.num_upr_shar == (constants::max_readers-1)){
+ else if(this->m_ctrl.num_shared == (constants::max_readers-1)){
this->m_first_gate.notify_all();
}
}
Modified: trunk/boost/interprocess/sync/interprocess_upgradable_mutex.hpp
==============================================================================
--- trunk/boost/interprocess/sync/interprocess_upgradable_mutex.hpp (original)
+++ trunk/boost/interprocess/sync/interprocess_upgradable_mutex.hpp 2012-08-24 14:11:04 EDT (Fri, 24 Aug 2012)
@@ -335,8 +335,12 @@
//The exclusive lock must block in the first gate
//if an exclusive or upgradable lock has been acquired
while (this->m_ctrl.exclusive_in || this->m_ctrl.upgradable_in){
- if(!this->m_first_gate.timed_wait(lock, abs_time))
- return !(this->m_ctrl.exclusive_in || this->m_ctrl.upgradable_in);
+ if(!this->m_first_gate.timed_wait(lock, abs_time)){
+ if(this->m_ctrl.exclusive_in || this->m_ctrl.upgradable_in){
+ return false;
+ }
+ break;
+ }
}
//Mark that exclusive lock has been acquired
@@ -348,7 +352,10 @@
//Now wait until all readers are gone
while (this->m_ctrl.num_upr_shar){
if(!this->m_second_gate.timed_wait(lock, abs_time)){
- return !(this->m_ctrl.num_upr_shar);
+ if(this->m_ctrl.num_upr_shar){
+ return false;
+ }
+ break;
}
}
rollback.release();
@@ -420,9 +427,12 @@
|| this->m_ctrl.upgradable_in
|| this->m_ctrl.num_upr_shar == constants::max_readers){
if(!this->m_first_gate.timed_wait(lock, abs_time)){
- return!(this->m_ctrl.exclusive_in
- || this->m_ctrl.upgradable_in
- || this->m_ctrl.num_upr_shar == constants::max_readers);
+ if((this->m_ctrl.exclusive_in
+ || this->m_ctrl.upgradable_in
+ || this->m_ctrl.num_upr_shar == constants::max_readers)){
+ return false;
+ }
+ break;
}
}
@@ -494,9 +504,12 @@
//or there are too many sharable locks
while (this->m_ctrl.exclusive_in
|| this->m_ctrl.num_upr_shar == constants::max_readers){
- if(!this->m_first_gate.timed_wait(lock, abs_time)){
- return!(this->m_ctrl.exclusive_in
- || this->m_ctrl.num_upr_shar == constants::max_readers);
+ if(!this->m_first_gate.timed_wait(lock, abs_time)){
+ if(this->m_ctrl.exclusive_in
+ || this->m_ctrl.num_upr_shar == constants::max_readers){
+ return false;
+ }
+ break;
}
}
@@ -613,7 +626,10 @@
while (this->m_ctrl.num_upr_shar){
if(!this->m_second_gate.timed_wait(lock, abs_time)){
- return !(this->m_ctrl.num_upr_shar);
+ if(this->m_ctrl.num_upr_shar){
+ return false;
+ }
+ break;
}
}
rollback.release();
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk