pike.git / lib / modules / Thread.pmod

version» Context lines:

pike.git/lib/modules/Thread.pmod:27: Inside #if constant(thread_create)
  // Using Thread as a type name for thread objects is strongly   // discouraged. I.e. use "Thread.Thread t = Thread.Thread()" and _not_   // "Thread t = Thread()". It's likely that this abomination is cleaned   // up eventually.   //   // /mast      inherit Thread;      // We don't want to create a thread of the module... - static void create(mixed ... args) + protected void create(mixed ... args)   {   }      optional Thread `()( mixed f, mixed ... args )   {    return thread_create( f, @args );   }      optional constant MutexKey=__builtin.mutex_key;   optional constant Mutex=__builtin.mutex;
pike.git/lib/modules/Thread.pmod:76: Inside #if constant(thread_create)
   int ptr, num;    int read_tres, write_tres;       //! This function returns the number of elements currently in the fifo.    //!    //! @seealso    //! @[read()], @[write()]    //!    int size() { return num; }    -  static final mixed read_unlocked() +  protected final mixed read_unlocked()    {    mixed tmp=buffer[ptr];    buffer[ptr++] = 0; // Throw away any references.    ptr%=sizeof(buffer);    if(read_tres < sizeof(buffer))    {    if(num-- == read_tres)    w_cond::broadcast();    }else{    num--;
pike.git/lib/modules/Thread.pmod:127: Inside #if constant(thread_create)
   mixed try_read()    {    if (!num) return UNDEFINED;    object key=lock::lock();    if (!num) return UNDEFINED;    mixed res = read_unlocked();    key = 0;    return res;    }    -  static final array read_all_unlocked() +  protected final array read_all_unlocked()    {    array ret;       switch (num) {    case 0:    ret = ({});    break;       case 1:    ret=buffer[ptr..ptr];
pike.git/lib/modules/Thread.pmod:192: Inside #if constant(thread_create)
   //!    array try_read_array()    {    if (!num) return ({});    object key=lock::lock();    array ret = read_all_unlocked();    key = 0;    return ret;    }    -  static final void write_unlocked (mixed value) +  protected final void write_unlocked (mixed value)    {    buffer[(ptr + num) % sizeof(buffer)] = value;    if(write_tres)    {    if(num++ == write_tres)    r_cond::broadcast();    }else{    num++;    r_cond::broadcast();    }
pike.git/lib/modules/Thread.pmod:248: Inside #if constant(thread_create)
   return items;    }       //! @decl void create()    //! @decl void create(int size)    //!    //! Create a fifo. If the optional @[size] argument is present it    //! sets how many values can be written to the fifo without blocking.    //! The default @[size] is 128.    //! -  static void create(int|void size) +  protected void create(int|void size)    {    write_tres=0;    buffer=allocate(read_tres=size || 128);    }    -  static string _sprintf( int f ) +  protected string _sprintf( int f )    {    return f=='O' && sprintf( "%O(%d / %d)", this_program,    size(), read_tres );    }   }      //! @[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.   //!
pike.git/lib/modules/Thread.pmod:320: Inside #if constant(thread_create)
   {    if (w_ptr == r_ptr) return UNDEFINED;    object key=lock::lock();    if (w_ptr == r_ptr) return UNDEFINED;    mixed tmp=buffer[r_ptr];    buffer[r_ptr++] = 0; // Throw away any references.    key=0;    return tmp;    }    -  static final array read_all_unlocked() +  protected final array read_all_unlocked()    {    array ret;       switch (w_ptr - r_ptr) {    case 0:    ret = ({});    break;       case 1:    ret=buffer[r_ptr..r_ptr];
pike.git/lib/modules/Thread.pmod:402: Inside #if constant(thread_create)
   r_ptr=0;    }    buffer[w_ptr] = value;    w_ptr++;    int items = w_ptr - r_ptr;    r_cond::signal();    key=0;    return items;    }    -  static string _sprintf( int f ) +  protected string _sprintf( int f )    {    return f=='O' && sprintf( "%O(%d)", this_program, size() );    }   }            optional class Farm   { -  static Mutex mutex = Mutex(); -  static Condition ft_cond = Condition(); -  static Queue job_queue = Queue(); +  protected Mutex mutex = Mutex(); +  protected Condition ft_cond = Condition(); +  protected Queue job_queue = Queue();       class Result    {    int ready;    mixed value;    function done_cb;       int status()    {    return ready;
pike.git/lib/modules/Thread.pmod:466: Inside #if constant(thread_create)
      void provide( mixed what )    {    ready = 1;    value = what;    if( done_cb )    done_cb( what, 0 );    }       -  static string _sprintf( int f ) +  protected string _sprintf( int f )    {    switch( f )    {    case 't':    return "Thread.Farm().Result";    case 'O':    return sprintf( "%t(%d %O)", this, ready, value );    }    }    }    -  static class Handler +  protected class Handler    {    Mutex job_mutex = Mutex();    Condition cond = Condition();    array(object|array(function|array)) job;    object thread;       float total_time;    int handled, max_time;    -  static int ready; +  protected int ready;       void handler()    {    array(object|array(function|array)) q;    object key = job_mutex->lock();    ready = 1;    while( 1 )    {    cond->wait(key);    if( q = job )
pike.git/lib/modules/Thread.pmod:552: Inside #if constant(thread_create)
   " Max time: "+sprintf("%2.2fms\n", max_time/1000.0):"")+    " Status: "+(job?"Working":"Idle" )+"\n"+    (job?    (" "+    replace( describe_backtrace(thread->backtrace()),    "\n",    "\n ")):"")    +"\n\n");    }    -  static void create() +  protected void create()    {    thread = thread_create( handler );    }       -  static string _sprintf( int f ) +  protected string _sprintf( int f )    {    switch( f )    {    case 't':    return "Thread.Farm().Handler";    case 'O':    return sprintf( "%t(%f / %d, %d)", this,    total_time, max_time, handled );    }    }    }    -  static array(Handler) threads = ({}); -  static array(Handler) free_threads = ({}); -  static int max_num_threads = 20; +  protected array(Handler) threads = ({}); +  protected array(Handler) free_threads = ({}); +  protected int max_num_threads = 20;    -  static Handler aquire_thread() +  protected Handler aquire_thread()    {    object lock = mutex->lock();    while( !sizeof(free_threads) )    {    if( sizeof(threads) < max_num_threads )    {    threads += ({ Handler() });    free_threads += ({ threads[-1] });    } else {    ft_cond->wait(mutex);    }    }    object(Handler) t = free_threads[0];    free_threads = free_threads[1..];    return t;    }       -  static void dispatcher() +  protected void dispatcher()    {    while( array q = [array]job_queue->read() )    aquire_thread()->run( q[1], q[0] );    }    -  static class ValueAdjuster( object r, object r2, int i, mapping v ) +  protected class ValueAdjuster( object r, object r2, int i, mapping v )    {    void go(mixed vn, int err)    {    ([array]r->value)[ i ] = vn;    if( err )    r->provide_error( err );    if( !--v->num_left )    r->provide( r->value );    destruct();    }
pike.git/lib/modules/Thread.pmod:683: Inside #if constant(thread_create)
   " Jobs in queue = %d\n\n",    max_num_threads, sizeof(threads),    (sizeof(threads)-sizeof(free_threads)),    job_queue->size() );       foreach( threads, Handler t )    res += t->debug_status();    return res;    }    -  static string _sprintf( int f ) +  protected string _sprintf( int f )    {    return f=='O' && sprintf( "%O(/* %s */)", this_program, debug_status() );    }    -  static void create() +  protected void create()    {    thread_create( dispatcher );    }   }      #else /* !constant(thread_create) */      // Simulations of some of the classes for nonthreaded use.      /* Fallback implementation of Thread.Local */   optional class Local   { -  static mixed data; +  protected mixed data;    mixed get() {return data;}    mixed set (mixed val) {return data = val;}   }      /* Fallback implementation of Thread.MutexKey */ - optional class MutexKey (static function(:void) dec_locks) + optional class MutexKey (protected function(:void) dec_locks)   {    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;    }    -  static void destroy() +  protected void destroy()    {    if (dec_locks) dec_locks();    }   }      /* Fallback implementation of Thread.Mutex */   optional class Mutex   { -  static int locks = 0; -  static void dec_locks() {locks--;} +  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:    if (locks) error ("Recursive mutex locks.\n");    break;    case 1:
pike.git/lib/modules/Thread.pmod:840:    buffer[(ptr + num) % sizeof(buffer)] = value;    return ++num;    }       int write(mixed value)    {    if (!try_write(value)) error("Deadlock detected - fifo full.\n");    return num;    }    -  static void create(int|void size) +  protected void create(int|void size)    {    write_tres=0;    buffer=allocate(read_tres=size || 128);    }    -  static string _sprintf( int f ) +  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   {    array buffer=allocate(16);
pike.git/lib/modules/Thread.pmod:918:    buffer=buffer[r_ptr..];    buffer+=allocate(sizeof(buffer)+1);    w_ptr-=r_ptr;    r_ptr=0;    }    buffer[w_ptr] = value;    w_ptr++;    return w_ptr - r_ptr;    }    -  static string _sprintf( int f ) +  protected string _sprintf( int f )    {    return f=='O' && sprintf( "%O(%d)", this_program, size() );    }   }      #endif /* !constant(thread_create) */ -  +