Branch: Tag:

1997-02-27

1997-02-27 14:53:21 by Fredrik Hübinette (Hubbe) <hubbe@hubbe.net>

bugfix in Fifo

Rev: lib/modules/Thread.pmod:1.6

7:    inherit Mutex: lock;       mixed *buffer; -  int r_ptr, w_ptr; +  int ptr, num;    -  int size() { return (w_ptr+sizeof(buffer) - r_ptr) % sizeof(buffer); } +  int size() { return num; }       mixed read()    {    mixed tmp;    object key=lock::lock(); -  while(!size()) r_cond::wait(key); -  tmp=buffer[r_ptr]; -  if(++r_ptr >= sizeof(buffer)) r_ptr=0; +  while(!num) r_cond::wait(key); +  tmp=buffer[ptr++]; +  r_ptr%=sizeof(buffer); +  num--;    w_cond::signal();    return tmp;    }
25:    void write(mixed v)    {    object key=lock::lock(); -  while(size() == sizeof(buffer)) w_cond::wait(key); -  buffer[w_ptr]=v; -  if(++w_ptr >= sizeof(buffer)) w_ptr=0; +  while(num == sizeof(buffer)) w_cond::wait(key); +  buffer[(ptr + num++) % sizeof(buffer)]=v;    r_cond::signal();    }