Boost logo

Boost :

From: Alexander Terekhov (terekhov_at_[hidden])
Date: 2004-07-20 14:51:24


Alexander Terekhov wrote:
[...]
> Err. m_retry_event.wait(), m_retry_event.set();

I mean

  void lock() throw() {
    if (int lock_status = m_lock_status.cas(0, 1, msync::ddacq)) {
      do if (lock_status < 0 || m_lock_status.cas(1,-1, msync::ddacq))
        m_retry_event.wait();
      while (lock_status = m_lock_status.cas(0, 1, msync::ddacq));
      m_retry_event.set();
    }
  }

  bool trylock() throw() {
    return !m_lock_status.cas(0, 1, msync::ddacq);
  }

  void unlock() throw() {
    if (m_lock_status.swap(0, msync::rel) < 0)
      m_retry_event.set();
  }

Can't currently think of something better than that.

regards,
alexander.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk