Ticket #13278: patch.diff

File patch.diff, 1.7 KB (added by arnaud, 5 years ago)
  • include/boost/interprocess/sync/interprocess_sharable_mutex.hpp

    From 0bcdbbe6822cae556927f9ae7a7d391214732c62 Mon Sep 17 00:00:00 2001
    From: Arnaud Gody <arnaud.gody@cae.com>
    Date: Mon, 18 Sep 2017 11:51:59 -0400
    Subject: [PATCH] Fix sharable counter wraparound when unlock_sharable function
     is called and counter is already equal to 0
    
    ---
     .../sync/interprocess_sharable_mutex.hpp           | 22 +++++++++++++---------
     1 file changed, 13 insertions(+), 9 deletions(-)
    
    diff --git a/include/boost/interprocess/sync/interprocess_sharable_mutex.hpp b/include/boost/interprocess/sync/interprocess_sharable_mutex.hpp
    index 59823b0..57713c5 100644
    a b inline bool interprocess_sharable_mutex::timed_lock_sharable  
    327327inline void interprocess_sharable_mutex::unlock_sharable()
    328328{
    329329   scoped_lock_t lck(m_mut);
    330    //Decrement sharable count
    331    --this->m_ctrl.num_shared;
    332    if (this->m_ctrl.num_shared == 0){
    333       this->m_second_gate.notify_one();
    334    }
    335    //Check if there are blocked sharables because of
    336    //there were too many sharables
    337    else if(this->m_ctrl.num_shared == (constants::max_readers-1)){
    338       this->m_first_gate.notify_all();
     330
     331   if(this->m_ctrl.num_shared != 0){
     332      //Decrement sharable count
     333      --this->m_ctrl.num_shared;
     334
     335      if(this->m_ctrl.num_shared == 0){
     336         this->m_second_gate.notify_one();
     337      }
     338      //Check if there are blocked sharables because of
     339      //there were too many sharables
     340      else if(this->m_ctrl.num_shared == (constants::max_readers-1)){
     341         this->m_first_gate.notify_all();
     342      }
    339343   }
    340344}
    341345