Ticket #9055: interprocess.patch

File interprocess.patch, 3.5 KB (added by stepan.seycek@…, 9 years ago)

patch providing notify methods with timeout

  • include/boost/interprocess/sync/interprocess_condition.hpp

    diff -r bd29b3e4c72d -r abf2ee553b11 include/boost/interprocess/sync/interprocess_condition.hpp
    a b  
    7272
    7373   //!If there is a thread waiting on *this, change that
    7474   //!thread's state to ready. Otherwise there is no effect.
    75    void notify_one()
    76    {  m_condition.notify_one();  }
     75   bool notify_one(const boost::posix_time::ptime &abs_time)
     76   {  return m_condition.notify_one(abs_time);  }
    7777
    7878   //!Change the state of all threads waiting on *this to ready.
    7979   //!If there are no waiting threads, notify_all() has no effect.
    80    void notify_all()
    81    {  m_condition.notify_all();  }
     80   bool notify_all(const boost::posix_time::ptime &abs_time)
     81   {  return m_condition.notify_all(abs_time);  }
    8282
    8383   //!Releases the lock on the interprocess_mutex object associated with lock, blocks
    8484   //!the current thread of execution until readied by a call to
  • include/boost/interprocess/sync/spin/condition.hpp

    diff -r bd29b3e4c72d -r abf2ee553b11 include/boost/interprocess/sync/spin/condition.hpp
    a b  
    3434   spin_condition();
    3535   ~spin_condition();
    3636
    37    void notify_one();
    38    void notify_all();
     37   bool notify_one(const boost::posix_time::ptime &abs_time);
     38   bool notify_all(const boost::posix_time::ptime &abs_time);
    3939
    4040   template <typename L>
    4141   bool timed_wait(L& lock, const boost::posix_time::ptime &abs_time)
     
    9797   spin_mutex  m_enter_mut;
    9898   volatile boost::uint32_t    m_command;
    9999   volatile boost::uint32_t    m_num_waiters;
    100    void notify(boost::uint32_t command);
     100   bool notify(boost::uint32_t command, const boost::posix_time::ptime &abs_time);
    101101};
    102102
    103103inline spin_condition::spin_condition()
     
    114114   //Trivial destructor
    115115}
    116116
    117 inline void spin_condition::notify_one()
     117inline bool spin_condition::notify_one(const boost::posix_time::ptime &abs_time)
    118118{
    119    this->notify(NOTIFY_ONE);
     119   return this->notify(NOTIFY_ONE, abs_time);
    120120}
    121121
    122 inline void spin_condition::notify_all()
     122inline bool spin_condition::notify_all(const boost::posix_time::ptime &abs_time)
    123123{
    124    this->notify(NOTIFY_ALL);
     124   return this->notify(NOTIFY_ALL, abs_time);
    125125}
    126126
    127 inline void spin_condition::notify(boost::uint32_t command)
     127inline bool spin_condition::notify(boost::uint32_t command,
     128                                       const boost::posix_time::ptime &abs_time)
    128129{
    129130   //This mutex guarantees that no other thread can enter to the
    130131   //do_timed_wait method logic, so that thread count will be
    131132   //constant until the function writes a NOTIFY_ALL command.
    132133   //It also guarantees that no other notification can be signaled
    133134   //on this spin_condition before this one ends
    134    m_enter_mut.lock();
     135
     136   //Fix the situation where one process dies while having m_enter_mut locked
     137   //by providing a timeout on the lock call
     138   if(!m_enter_mut.timed_lock(abs_time)){
     139          return false;
     140   }
    135141
    136142   //Return if there are no waiters
    137143   if(!atomic_read32(&m_num_waiters)) {
    138144      m_enter_mut.unlock();
    139       return;
     145      return true;
    140146   }
    141147
    142148   //Notify that all threads should execute wait logic
     
    150156   }
    151157*/
    152158   //The enter mutex will rest locked until the last waiting thread unlocks it
     159   return true;
    153160}
    154161
    155162template<class InterprocessMutex>