virtual void run(void) { int i; { locker bb(outmut); fprintf(stderr,"PROD: starting up\n"); } for (i=1; i<max; i++) { { locker bb(outmut); fprintf(stderr,"PROD: starting loop\n"); } thread::sleep(500); { locker cc(dmut); { locker bb(outmut); fprintf(stderr,"PROD: %d\n", i); } data = i*10; dsem.notify(); // notify one } } { locker bb(outmut); fprintf(stderr,"PROD: shuttin down\n"); } }
bool take( value_type & va, chrono::system_clock::time_point const& abs_time) { mutex::scoped_lock lk( head_mtx_); bool empty = empty_(); if ( ! active_() && empty) return false; if ( empty) { try { while ( active_() && empty_() ) { if ( ! not_empty_cond_.timed_wait( lk, abs_time) ) return false; } } catch ( fiber_interrupted const&) { return false; } } if ( ! active_() && empty_() ) return false; swap( va, head_->va); pop_head_(); return va; }
void put( T const& t) { typename node_type::ptr new_node( new node_type() ); { mutex::scoped_lock lk( tail_mtx_); if ( ! active_() ) throw std::runtime_error("queue is not active"); tail_->va = t; tail_->next = new_node; tail_ = new_node; } not_empty_cond_.notify_one(); }
//must be the last call from the runtime_node void remove_node( runtime_node* n ) { typename mutex::scoped_lock g(m_); typename nodes::iterator it; for( it = n_.begin(); it != n_.end(); ++it ) { if( it->second.get() == n ) { del_[n] = it->second; n_.erase(it); c_.notify_all(); return; } } assert( 0 ); //node not found }
virtual void run(void) { int i, v; for (i=0; i<max; i++) { { locker kk(dmut); dsem.wait(dmut); v = data; } { locker l(outmut); fprintf(stderr, "Got data %s: %d\n", name, v); } thread::sleep(1000); } }
bool take( value_type & va) { mutex::scoped_lock lk( head_mtx_); bool empty = empty_(); if ( ! active_() && empty) return false; if ( empty) { try { while ( active_() && empty_() ) not_empty_cond_.wait( lk); } catch ( fiber_interrupted const&) { return false; } } if ( ! active_() && empty_() ) return false; swap( va, head_->va); pop_head_(); return va; }
void deactivate() { mutex::scoped_lock lk( head_mtx_); deactivate_(); not_empty_cond_.notify_all(); }
void mark_ready_and_notify_() { ready_ = true; waiters_.notify_all(); }
condition::condition(const condition &cond) : rightSide(cond.getRightSide()), dataType(cond.getDataType()), leftSide(cond.getLeftSide()), logicRelation(cond.getLogicRelation()) { }