pike.git / lib / modules / Thread.pmod

version» Context lines:

pike.git/lib/modules/Thread.pmod:22: Inside #if constant(thread_create)
  optional 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;          - //! @[Thread.Fifo] implements a fixed length first-in, first-out queue. + //! @[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.   //!   //! @note   //! Fifos are only available on systems with threads support.   //!   //! @seealso - //! @[Thread.Queue] + //! @[Queue]   //!   optional 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.    //!    //! @seealso -  //! @[read()], @[write()] +  //! @[read()], @[write()]    //!    int size() { return num; }       //! This function retrieves a value from the fifo. Values will be    //! returned in the order they were written. If there are no values    //! present in the fifo the current thread will sleep until some other    //! thread writes a value to the fifo.    //!    //! @seealso -  //! @[write()], @[read_array()] +  //! @[write()], @[read_array()]    //!    mixed read()    {    mixed tmp;    object key=lock::lock(2);    while(!num) r_cond::wait(key);    tmp=buffer[ptr];    buffer[ptr++] = 0; // Throw away any references.    ptr%=sizeof(buffer);    if(read_tres < sizeof(buffer))
pike.git/lib/modules/Thread.pmod:82: Inside #if constant(thread_create)
   key = 0;    return tmp;    }       //! This function returns all values currently in the fifo. Values in    //! the array will be in the order they were written. If there are no    //! values present in the fifo the current thread will sleep until    //! some other thread writes a value to the fifo.    //!    //! @seealso -  //! @[write()], @[read()] +  //! @[write()], @[read()]    //!    array read_array()    {    array ret;    object key=lock::lock(2);    while(!num) r_cond::wait(key);    if(num==1)    {    ret=buffer[ptr..ptr];    buffer[ptr++] = 0; // Throw away any references.
pike.git/lib/modules/Thread.pmod:114: Inside #if constant(thread_create)
   key = 0;    w_cond::broadcast();    return ret;    }       //! Append a @[value] to the end of the fifo. If there is no more    //! room in the fifo the current thread will sleep until space is    //! available.    //!    //! @seealso -  //! @[read()] +  //! @[read()]    //!    void write(mixed value)    {    object key=lock::lock(2);    while(num == sizeof(buffer)) w_cond::wait(key);    buffer[(ptr + num) % sizeof(buffer)] = value;    if(write_tres)    {    if(num++ == write_tres)    r_cond::broadcast();
pike.git/lib/modules/Thread.pmod:157: Inside #if constant(thread_create)
   switch( f )    {    case 't':    return "Thread.Fifo";    case 'O':    return sprintf( "%t(%d / %d)", this_object(), size(), read_tres );    }    }   };    - //! @[Thread.Queue] implements a queue, or a pipeline. The main difference - //! between @[Thread.Queue] and @[Thread.Fifo] is that @[Thread.Queue] + //! @[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.   //!   //! @note   //! Queues are only available on systems with POSIX or UNIX or WIN32   //! thread support.   //!   //! @seealso - //! @[Thread.Fifo] + //! @[Fifo]   //!   optional 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()] +  //! @[read()], @[write()]    //!    int size() { return w_ptr - r_ptr; }       //! This function retrieves a value from the queue. Values will be    //! returned in the order they were written. If there are no values    //! present in the queue the current thread will sleep until some other    //! thread writes a value to the queue.    //!    //! @seealso -  //! @[write()] +  //! @[write()]    //!    mixed read()    {    mixed tmp;    object key=lock::lock();    while(!size()) r_cond::wait(key);    tmp=buffer[r_ptr];    buffer[r_ptr++] = 0; // Throw away any references.    key=0;    return tmp;    }       //! This function puts a @[value] last in the queue. If the queue is    //! too small to hold the @[value] the queue will be expanded to make    //! room for it.    //!    //! @seealso -  //! @[read()] +  //! @[read()]    //!    void write(mixed value)    {    object key=lock::lock();    if(w_ptr >= sizeof(buffer))    {    buffer=buffer[r_ptr..];    buffer+=allocate(sizeof(buffer)+1);    w_ptr-=r_ptr;    r_ptr=0;