pike.git / lib / modules / Thread.pmod

version» Context lines:

pike.git/lib/modules/Thread.pmod:857: Inside #if constant(thread_create)
  //!   optional class ResourceCountKey {    /*semi*/private ResourceCount parent;       /*semi*/private void create(ResourceCount _parent) {    parent = _parent;    }       /*semi*/private void destroy() {    --parent->_count; +  MutexKey lock = parent->_mutex->lock();    parent->_cond->signal();    }   }      //! Implements an inverted-semaphore-like resource   //! counter. A thread can poll or perform a blocking wait for the   //! resource-count to drop below a certain @ref{level@}.   //!   //! @seealso   //! @[ResourceCountKey], @[Condition], @[Mutex]   optional class ResourceCount {    /*semi*/final int _count;    /*semi*/final Condition _cond = Condition(); -  +  /*semi*/final Mutex _mutex = Mutex();       //! @param level    //! The maximum level that is considered drained.    //!    //! @returns    //! True if the resource counter drops to equal or below @ref{level@}.    /*semi*/final int(0..1) drained(void|int level) {    return level >= _count;    }       //! Blocks until the resource-counter dips to max @ref{level@}.    //! -  //! @param lock -  //! A previously acquired @[MutexKey]. -  //! +     //! @param level    //! The maximum level that is considered drained. -  /*semi*/final void wait_till_drained(MutexKey lock, void|int level) { +  variant /*semi*/final void wait_till_drained(void|int level) {    while (_count > level) // Recheck before allowing further -  _cond->wait(lock); -  lock = 0; // Eliminate references +  _cond->wait(_mutex->lock());    }    -  +  // FIXME deprecated +  variant final /*__deprecated__*/ void wait_till_drained(MutexKey lock, void|int level) { +  wait_till_drained(level); +  } +     //! Increments the resource-counter.    //! @returns    //! A @[ResourceCountKey] to decrement the resource-counter again.    /*semi*/final ResourceCountKey acquire() {    _count++;    return ResourceCountKey(this);    }       /*semi*/private string _sprintf(int type) {    string res = UNDEFINED;