//! Dequeues log record from the queue, blocks if no log records are ready to be processed bool dequeue_ready(record_view& rec) { unique_lock< mutex_type > lock(m_mutex); while (!m_interruption_requested) { if (!m_queue.empty()) { const boost::log::aux::timestamp now = boost::log::aux::get_timestamp(); enqueued_record const& elem = m_queue.top(); const uint64_t difference = (now - elem.m_timestamp).milliseconds(); if (difference >= m_ordering_window) { // We got a new element rec = elem.m_record; m_queue.pop(); return true; } else { // Wait until the element becomes ready to be processed m_cond.timed_wait(lock, posix_time::milliseconds(m_ordering_window - difference)); } } else { // Wait for an element to come m_cond.wait(lock); } } m_interruption_requested = false; return false; }
typename meta::enable_if< is_time_interval< T >, bool >::type timed_acquire_read( const T& ttl ) const { mutex::guard g( mutex_ ); while ( has_writer_ || writer_waiting_ ) { if ( !reader_cv_.timed_wait( mutex_, ttl ) ) { return false; } } ++reader_count_; return true; }
typename meta::enable_if< is_time_interval< T >, bool >::type timed_acquire_write( const T& ttl ) const { mutex::guard g( mutex_ ); while ( reader_count_ || has_writer_ ) { writer_waiting_ = true; if ( !writer_cv_.timed_wait( mutex_, ttl ) ) { if ( reader_count_ || has_writer_ ) { writer_waiting_ = false; writer_cv_.notify_one(); return false; } has_writer_ = true; return true; } } has_writer_ = true; return true; }