pike.git / lib / modules / Thread.pmod

version» Context lines:

pike.git/lib/modules/Thread.pmod:14: Inside #if constant(thread_create)
      array buffer;    int ptr, num;    int read_tres, write_tres;       int size() { return num; }       mixed read()    {    mixed tmp; -  object key=lock::lock(); +  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))    {    if(num-- == read_tres)    w_cond::broadcast();    }else{    num--;    w_cond::signal();    }    return tmp;    }       array read_array()    {    array ret; -  object key=lock::lock(); +  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.    ptr%=sizeof(buffer);    num--;    }else{    ret=buffer[ptr..]+buffer[..num-sizeof(ret)-1];    ptr=num=0;    buffer=allocate(sizeof(buffer)); // Throw away any references.    }    w_cond::broadcast();    return ret;    }       void write(mixed v)    { -  object key=lock::lock(); +  object key=lock::lock(2);    while(num == sizeof(buffer)) w_cond::wait(key);    buffer[(ptr + num) % sizeof(buffer)]=v;    if(write_tres)    {    if(num++ == write_tres)    r_cond::broadcast();    }else{    num++;    r_cond::signal();    }
pike.git/lib/modules/Thread.pmod:84: Inside #if constant(thread_create)
   inherit Mutex : lock;       mixed *buffer=allocate(16);    int r_ptr, w_ptr;       int size() { return w_ptr - r_ptr; }       mixed read()    {    mixed tmp; -  object key=lock::lock(); +  object key=lock::lock(2);    while(!size()) r_cond::wait(key);    tmp=buffer[r_ptr];    buffer[r_ptr++] = 0; // Throw away any references.    key=0;    return tmp;    }       void write(mixed v)    { -  object key=lock::lock(); +  object key=lock::lock(2);    if(w_ptr >= sizeof(buffer))    {    buffer=buffer[r_ptr..];    buffer+=allocate(sizeof(buffer)+1);    w_ptr-=r_ptr;    r_ptr=0;    }    buffer[w_ptr]=v;    w_ptr++;    key=0; // Must free this one _before_ the signal...
pike.git/lib/modules/Thread.pmod:164: Inside #if constant(thread_create)
   ready = 1;    value = what;    if( done_cb )    done_cb( what, 0 );    }    }       static class Handler    {    Condition cond = Condition(); -  array job; +  array(object|array(function|array)) job;    object thread;       float total_time;    int handled, max_time;       static int ready;       void handler()    { -  array q; +  array(object|array(function|array)) q;    while( 1 )    {    ready = 1;    cond->wait();    if( q = job )    {    mixed res, err;    int st = gethrtime();    if( err = catch(res = q[1][0]( @q[1][1] )) && q[0]) -  q[0]->provide_error( err ); +  ([object]q[0])->provide_error( err );    else if( q[0] ) -  q[0]->provide( res ); +  ([object]q[0])->provide( res );    object lock = mutex->lock();    free_threads += ({ this_object() });    lock = 0;    st = gethrtime()-st;    total_time += st/1000.0;    handled++;    job = 0;    if( st > max_time )    max_time = st;    ft_cond->broadcast();
pike.git/lib/modules/Thread.pmod:208: Inside #if constant(thread_create)
   object lock = mutex->lock();    threads -= ({ this_object() });    free_threads -= ({ this_object() });    lock = 0;    destruct();    return;    }    }    }    -  void run( array what, object|void resobj ) +  void run( array(function|array) what, object|void resobj )    {    while(!ready) sleep(0.1);    job = ({ resobj, what });    cond->signal();    }       string debug_status()    {    return ("Thread:\n"    " Handled works: "+handled+"\n"+
pike.git/lib/modules/Thread.pmod:260: Inside #if constant(thread_create)
   if( sizeof(threads) < max_num_threads )    {    threads += ({ Handler() });    free_threads += ({ threads[-1] });    } else {    lock = 0;    ft_cond->wait( );    mutex->lock();    }    } -  object t = free_threads[0]; +  object(Handler) t = free_threads[0];    free_threads = free_threads[1..];    return t;    }          static void dispatcher()    { -  while( array q = job_queue->read() ) +  while( array q = [array]job_queue->read() )    aquire_thread()->run( q[1], q[0] );    }       static class ValueAdjuster    {    object r, r2;    mapping v;    int i;       void go(mixed vn, int err)    { -  r->value[ i ] = vn; +  ([array]r->value)[ i ] = vn;    if( err )    r->provide_error( err );    if( !--v->num_left )    r->provide( r->value );    destruct();    }    void create( object _1,object _2,int _3,mapping _4 )    {    r = _1; r2 = _2; i=_3; v=_4;    }