pike.git / lib / modules / Thread.pmod

version» Context lines:

pike.git/lib/modules/Thread.pmod:20: Inside #if constant(thread_create)
  optional constant thread_create = predef::thread_create;      optional constant this_thread = predef::this_thread;      optional constant all_threads = predef::all_threads;      constant THREAD_NOT_STARTED = __builtin.THREAD_NOT_STARTED;   constant THREAD_RUNNING = __builtin.THREAD_RUNNING;   constant THREAD_EXITED = __builtin.THREAD_EXITED;    + private local void unlock(MutexKey key) + { +  // NB: Work-around in case the key has been used in a function call +  // (the typical case being cond->wait()), and may have ended up +  // in a backtrace to to eg the gc having executed a broken destroy(). +  destruct(key); + }      //! @[Fifo] implements a fixed length first-in, first-out queue.   //! A fifo is a queue of values and is often used as a stream of data   //! between two threads.   //!   //! @seealso   //! @[Queue]   //!   optional class Fifo {    inherit Condition : r_cond;
pike.git/lib/modules/Thread.pmod:73: Inside #if constant(thread_create)
   //! thread writes one.    //!    //! @seealso    //! @[try_read()], @[read_array()], @[write()]    //!    mixed read()    {    object key=lock::lock();    while(!num) r_cond::wait(key);    mixed res = read_unlocked(); -  key = 0; +  unlock(key);    return res;    }       //! This function retrieves a value from the fifo if there is any    //! there. Values will be returned in the order they were written.    //! If there are no values present in the fifo then @[UNDEFINED]    //! will be returned.    //!    //! @seealso    //! @[read()]
pike.git/lib/modules/Thread.pmod:140: Inside #if constant(thread_create)
   //! sleep until some other thread writes one.    //!    //! @seealso    //! @[read()], @[try_read_array()]    //!    array read_array()    {    object key=lock::lock();    while(!num) r_cond::wait(key);    array ret = read_all_unlocked(); -  key = 0; +  unlock(key);    return ret;    }       //! This function returns all values in the fifo as an array but    //! doesn't wait if there are no values there. The values in the    //! array will be in the order they were written.    //!    //! @seealso    //! @[read_array()]    //!
pike.git/lib/modules/Thread.pmod:187: Inside #if constant(thread_create)
   //!    //! @seealso    //! @[read()]    //!    int write(mixed value)    {    object key=lock::lock();    while(num == sizeof(buffer)) w_cond::wait(key);    write_unlocked (value);    int items = num; -  key = 0; +  unlock(key);    return items;    }       //! Append a @[value] to the end of the fifo. If there is no more    //! room in the fifo then zero will be returned, otherwise the    //! number of items in the fifo after the write is returned.    //!    //! @seealso    //! @[read()]    //!
pike.git/lib/modules/Thread.pmod:268: Inside #if constant(thread_create)
   //! @seealso    //! @[try_read()], @[write()]    //!    mixed read()    {    mixed tmp;    object key=lock::lock();    while(w_ptr == r_ptr) r_cond::wait(key);    tmp=buffer[r_ptr];    buffer[r_ptr++] = 0; // Throw away any references. -  key=0; +  unlock(key);    return tmp;    }       //! This function retrieves a value from the queue if there is any    //! there. Values will be returned in the order they were written.    //! If there are no values present in the fifo then @[UNDEFINED]    //! will be returned.    //!    //! @seealso    //! @[write()]
pike.git/lib/modules/Thread.pmod:328: Inside #if constant(thread_create)
   //! sleep until some other thread writes one.    //!    //! @seealso    //! @[read()], @[try_read_array()]    //!    array read_array()    {    object key=lock::lock();    while (w_ptr == r_ptr) r_cond::wait(key);    array ret = read_all_unlocked(); -  key = 0; +  unlock(key);    return ret;    }       //! This function returns all values in the queue as an array but    //! doesn't wait if there are no values there. The values in the    //! array will be in the order they were written.    //!    //! @seealso    //! @[read_array()]    //!
pike.git/lib/modules/Thread.pmod:442: Inside #if constant(thread_create)
   mixed result()    {    return value;    }       //! Wait for completion.    mixed `()()    {    object key = mutex->lock();    while(!ready) ft_cond->wait(key); -  key = 0; +  unlock(key);    if( ready < 0 ) throw( value );    return value;    }       //! Register a callback to be called when    //! the result is available.    //!    //! @param to    //! Callback to be called. The first    //! argument to the callback will be
pike.git/lib/modules/Thread.pmod:563: Inside #if constant(thread_create)
   q = 0;    if( st > max_time )    max_time = st;    ft_cond->broadcast();    } else {    object lock = mutex->lock();    threads -= ({ this });    free_threads -= ({ this });    lock = 0;    update_thread_name(1); +  unlock(key);    destruct();    return;    }    }    }       void run( array(function|array) what, object|void resobj )    {    while(!ready) sleep(0.1);    object key = job_mutex->lock();
pike.git/lib/modules/Thread.pmod:634: Inside #if constant(thread_create)
   if( sizeof(threads) < max_num_threads )    {    threads += ({ Handler() });    free_threads += ({ threads[-1] });    } else {    ft_cond->wait(lock);    }    }    object(Handler) t = free_threads[0];    free_threads = free_threads[1..]; +  unlock(lock);    return t;    }          protected void dispatcher()    {    while( array q = [array]job_queue->read() ) {    aquire_thread()->run( q[1], q[0] );    q = 0;    }
pike.git/lib/modules/Thread.pmod:794: Inside #if constant(thread_create)
   "num_threads must be > 0\n");       max_num_threads = to;    while( sizeof( threads ) > max_num_threads )    {    object key = mutex->lock();    while( sizeof( free_threads ) )    free_threads[0]->cond->signal();    if( sizeof( threads ) > max_num_threads)    ft_cond->wait(key); +  unlock(key);    }    ft_cond->broadcast( );    return omnt;    }       //! Provide a callback function to track names of threads created by the    //! farm.    //!    //! @param cb    //! The callback function. This will get invoked with the thread as the
pike.git/lib/modules/Thread.pmod:903: Inside #if constant(thread_create)
   }       //! Blocks until the resource-counter dips to max @ref{level@}.    //!    //! @param level    //! The maximum level that is considered drained.    /*semi*/final void wait_till_drained(void|int level) {    MutexKey key = _mutex->lock();    while (_count > level) // Recheck before allowing further    _cond->wait(key); +  unlock(key);    }       //! Increments the resource-counter.    //! @returns    //! A @[ResourceCountKey] to decrement the resource-counter again.    /*semi*/final ResourceCountKey acquire() {    MutexKey key = _mutex->lock();    _count++;    return ResourceCountKey(this);    }