pike.git / lib / modules / Thread.pmod

version» Context lines:

pike.git/lib/modules/Thread.pmod:1:   #pike __REAL_VERSION__      #if constant(__builtin.thread_id)   constant Thread=__builtin.thread_id;    - optional constant MutexKey=__builtin.mutex_key; - optional constant Mutex=__builtin.mutex; - optional constant Condition=__builtin.condition; - optional constant _Disabled=__builtin.threads_disabled; - optional constant Local=__builtin.thread_local; + constant MutexKey=__builtin.mutex_key; + constant Mutex=__builtin.mutex; + constant Condition=__builtin.condition; + constant _Disabled=__builtin.threads_disabled; + constant Local=__builtin.thread_local;    - optional constant thread_create = predef::thread_create; - optional constant this_thread = predef::this_thread; - optional constant all_threads = predef::all_threads; - optional constant get_thread_quanta = predef::get_thread_quanta; - optional constant set_thread_quatna = predef::set_thread_quanta; + constant thread_create = predef::thread_create; + constant this_thread = predef::this_thread; + constant all_threads = predef::all_threads; + constant get_thread_quanta = predef::get_thread_quanta; + constant set_thread_quatna = predef::set_thread_quanta;      constant THREAD_NOT_STARTED = __builtin.THREAD_NOT_STARTED;   constant THREAD_RUNNING = __builtin.THREAD_RUNNING;   constant THREAD_EXITED = __builtin.THREAD_EXITED;         //! @[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 { + class Fifo {    inherit Condition : r_cond;    inherit Condition : w_cond;    inherit Mutex : lock;       array buffer;    int ptr, num;    int read_tres, write_tres;       //! This function returns the number of elements currently in the fifo.    //!
pike.git/lib/modules/Thread.pmod:231: Inside #if constant(__builtin.thread_id)
  //! @[Queue] implements a queue, or a pipeline. The main difference   //! between @[Queue] and @[Fifo] is that @[Queue]   //! will never block in write(), only allocate more memory.   //!   //! @fixme   //! Ought to be made API-compatible with @[ADT.Queue].   //!   //! @seealso   //! @[Fifo], @[ADT.Queue]   //! - optional class Queue { + class Queue {    inherit Condition : r_cond;    inherit Mutex : lock;       array buffer=allocate(16);    int r_ptr, w_ptr;       //! This function returns the number of elements currently in the queue.    //!    //! @seealso    //! @[read()], @[write()]
pike.git/lib/modules/Thread.pmod:390: Inside #if constant(__builtin.thread_id)
   }       protected string _sprintf( int f )    {    return f=='O' && sprintf( "%O(%d)", this_program, size() );    }   }         //! A thread farm. - optional class Farm + class Farm   {    protected Mutex mutex = Mutex();    protected Condition ft_cond = Condition();    protected Queue job_queue = Queue();    protected object dispatcher_thread;    protected function(object, string:void) thread_name_cb;    protected string thread_name_prefix;       //! An asynchronous result.    class Result
pike.git/lib/modules/Thread.pmod:853: Inside #if constant(__builtin.thread_id)
   dispatcher_thread = thread_create( dispatcher );    }   }      //! When this key is destroyed, the corresponding resource counter   //! will be decremented.   //!   //! @seealso   //! @[ResourceCount], @[MutexKey]   //! - optional class ResourceCountKey { + class ResourceCountKey {       private inherit __builtin.DestructImmediate;       /*semi*/private ResourceCount parent;       /*semi*/private void create(ResourceCount _parent) {    parent = _parent;    }       /*semi*/private void _destruct() {
pike.git/lib/modules/Thread.pmod:876: Inside #if constant(__builtin.thread_id)
   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 { + 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) {
pike.git/lib/modules/Thread.pmod:928: Inside #if constant(__builtin.thread_id)
   }    return res;    }   }      #else /* !constant(thread_create) */      // Simulations of some of the classes for nonthreaded use.      /* Fallback implementation of Thread.Local */ - optional class Local + class Local   {    protected mixed data;    mixed get() {return data;}    mixed set (mixed val) {return data = val;}   }      /* Fallback implementation of Thread.MutexKey */ - optional class MutexKey (protected function(:void) dec_locks) + class MutexKey (protected function(:void) dec_locks)   {    inherit Builtin.DestructImmediate;       int `!()    {    // Should be destructed when the mutex is, but we can't pull that    // off. Try to simulate it as well as possible.    if (dec_locks) return 0;    destruct (this);    return 1;    }       protected void _destruct()    {    if (dec_locks) dec_locks();    }   }      /* Fallback implementation of Thread.Mutex */ - optional class Mutex + class Mutex   {    protected int locks = 0;    protected void dec_locks() {locks--;}       MutexKey lock (int|void type)    {    switch (type) {    default:    error ("Unknown mutex locking style: %d\n", type);    case 0:
pike.git/lib/modules/Thread.pmod:1000:    case 1:    case 2:    }    if (locks) return 0;    locks++;    return MutexKey (dec_locks);    }   }      // Fallback implementation of Thread.Fifo. - optional class Fifo + class Fifo   {    array buffer;    int ptr, num;    int read_tres, write_tres;       int size() { return num; }       mixed read()    {    if (!num) error ("Deadlock detected - fifo empty.\n");
pike.git/lib/modules/Thread.pmod:1085:    }       protected string _sprintf( int f )    {    return f=='O' && sprintf( "%O(%d / %d)", this_program,    size(), read_tres );    }   }      // Fallback implementation of Thread.Queue. - optional class Queue + class Queue   {    array buffer=allocate(16);    int r_ptr, w_ptr;       int size() { return w_ptr - r_ptr; }       mixed read()    {    if (w_ptr == r_ptr) error ("Deadlock detected - queue empty.\n");    return try_read();