23f3361997-02-27Fredrik Hübinette (Hubbe) constant Mutex=__builtin.mutex; constant Condition=__builtin.condition;
609c0f1997-02-27Fredrik Hübinette (Hubbe)  class Fifo {
7f30a61997-02-27Fredrik Hübinette (Hubbe)  inherit Condition : r_cond; inherit Condition: w_cond; inherit Mutex: lock;
609c0f1997-02-27Fredrik Hübinette (Hubbe)  mixed *buffer;
87e3691997-02-27Fredrik Hübinette (Hubbe)  int ptr, num;
609c0f1997-02-27Fredrik Hübinette (Hubbe) 
87e3691997-02-27Fredrik Hübinette (Hubbe)  int size() { return num; }
609c0f1997-02-27Fredrik Hübinette (Hubbe)  mixed read() { mixed tmp; object key=lock::lock();
87e3691997-02-27Fredrik Hübinette (Hubbe)  while(!num) r_cond::wait(key);
b1dbcb1997-10-04Henrik Grubbström (Grubba)  tmp=buffer[ptr]; buffer[ptr++] = 0; // Throw away any references.
dff7f71997-02-27Fredrik Hübinette (Hubbe)  ptr%=sizeof(buffer);
87e3691997-02-27Fredrik Hübinette (Hubbe)  num--;
609c0f1997-02-27Fredrik Hübinette (Hubbe)  w_cond::signal(); return tmp; } void write(mixed v) { object key=lock::lock();
87e3691997-02-27Fredrik Hübinette (Hubbe)  while(num == sizeof(buffer)) w_cond::wait(key); buffer[(ptr + num++) % sizeof(buffer)]=v;
609c0f1997-02-27Fredrik Hübinette (Hubbe)  r_cond::signal(); } varargs void create(int size) { buffer=allocate(size || 128); } }; class Queue {
7f30a61997-02-27Fredrik Hübinette (Hubbe)  inherit Condition: r_cond; inherit Mutex: lock;
609c0f1997-02-27Fredrik Hübinette (Hubbe)  mixed *buffer=allocate(16); int r_ptr, w_ptr; int size() { return w_ptr - r_ptr; } mixed read() { mixed tmp; object key=lock::lock(); while(!size()) r_cond::wait(key);
b1dbcb1997-10-04Henrik Grubbström (Grubba)  tmp=buffer[r_ptr]; buffer[r_ptr++] = 0; // Throw away any references.
8e40e81997-09-01Per Hedbor  key=0;
609c0f1997-02-27Fredrik Hübinette (Hubbe)  return tmp; } void write(mixed v) { 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; } buffer[w_ptr]=v; w_ptr++;
8e40e81997-09-01Per Hedbor  key=0; // Must free this one _before_ the signal...
609c0f1997-02-27Fredrik Hübinette (Hubbe)  r_cond::signal(); } };