//! Add an element to the blocking queue inline void enqueue_to_head(const T& elem) { m_mutex.lock(); m_queue.push_front(elem); // Signal threads waiting on the queue if (sleeping) m_conditional.signal(); m_mutex.unlock(); }
void receive(procid_t source, blob b) { mut.lock(); val = b; valready = true; cond.signal(); mut.unlock(); }
inline void enqueue_conditional_signal(const T& elem, size_t signal_at_size) { m_mutex.lock(); m_queue.push_back(elem); // Signal threads waiting on the queue if (sleeping && m_queue.size() >= signal_at_size) m_conditional.signal(); m_mutex.unlock(); }
void swap(queue_type &q) { m_mutex.lock(); q.swap(m_queue); if (m_queue.empty() && sleeping_on_empty) { m_empty_conditional.signal(); } m_mutex.unlock(); }
inline void post() const { mut.lock(); if (waitercount > 0) { cond.signal(); } semvalue++; mut.unlock(); }
inline void decrement_running_counter() { // now, a bit of care is needed here size_t r = threads_running.dec(); if (r == 0) { join_lock.lock(); if (join_waiting) { join_cond.signal(); } join_lock.unlock(); } }
void run (void) { ::printf ("counting till %i\n", cnt); for (int i=0; i<cnt; ++i) { DB.get() = DB.get().ival() + 1; ::printf ("DB.get() -> %i\n", DB.get().ival()); } *out = DB.get(); value ev = waitevent (); threadStopped.signal (); }
void stop_log_rotation() { // if no log rotation active, quit. if (!thread_running) return; // join the log rotation thread. lock.lock(); thread_running = false; cond.signal(); lock.unlock(); log_rotate_thread.join(); // we will continue logging to the same location, but we will // delete the symlink unlink(symlink_name.c_str()); }
inline std::pair<T, bool> try_dequeue_in_critical_section() { T elem = T(); // Wait while the queue is empty and this queue is alive if (m_queue.empty() || m_alive == false) { return std::make_pair(elem, false); } else { elem = m_queue.front(); m_queue.pop_front(); if (m_queue.empty() && sleeping_on_empty) { m_empty_conditional.signal(); } return std::make_pair(elem, true); } }
void zk_callback(zookeeper_util::server_list* slist, std::string name_space, std::vector<std::string> servers, std::vector<std::string>& result, size_t num_to_watch_for, mutex& result_lock, conditional& result_cond) { if (servers.size() == num_to_watch_for) { result_lock.lock(); result = servers; slist->stop_watching("graphlab"); result_cond.signal(); result_lock.unlock(); } }
/** * Returns an element if the queue has an entry. * returns [item, false] otherwise. */ inline std::pair<T, bool> try_dequeue() { if (m_queue.empty() || m_alive == false) return std::make_pair(T(), false); m_mutex.lock(); T elem = T(); // Wait while the queue is empty and this queue is alive if (m_queue.empty() || m_alive == false) { m_mutex.unlock(); return std::make_pair(elem, false); } else { elem = m_queue.front(); m_queue.pop_front(); if (m_queue.empty() && sleeping_on_empty) { m_empty_conditional.signal(); } } m_mutex.unlock(); return std::make_pair(elem, true); }
inline std::pair<T, bool> dequeue_and_begin_critical_section_on_success() { m_mutex.lock(); T elem = T(); bool success = false; // Wait while the queue is empty and this queue is alive while(m_queue.empty() && m_alive) { sleeping++; m_conditional.wait(m_mutex); sleeping--; } // An element has been added or a signal was raised if(!m_queue.empty()) { success = true; elem = m_queue.front(); m_queue.pop_front(); if (m_queue.empty() && sleeping_on_empty) { m_empty_conditional.signal(); } } if (!success) m_mutex.unlock(); return std::make_pair(elem, success); }