From 61a62e2cdc053cf902570bfa59d18451b17a8d42 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fredrik=20H=C3=BCbinette=20=28Hubbe=29?= <hubbe@hubbe.net>
Date: Sat, 5 Oct 1996 05:16:35 +0200
Subject: [PATCH] Fifo for threads implemented in Pike

Rev: lib/include/fifo.h:1.1
Rev: lib/include/fifo.pre.pike:1.1
---
 lib/include/fifo.h        |  1 +
 lib/include/fifo.pre.pike | 36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+)
 create mode 100644 lib/include/fifo.h
 create mode 100644 lib/include/fifo.pre.pike

diff --git a/lib/include/fifo.h b/lib/include/fifo.h
new file mode 100644
index 0000000000..8b13789179
--- /dev/null
+++ b/lib/include/fifo.h
@@ -0,0 +1 @@
+
diff --git a/lib/include/fifo.pre.pike b/lib/include/fifo.pre.pike
new file mode 100644
index 0000000000..9cb4f0a82a
--- /dev/null
+++ b/lib/include/fifo.pre.pike
@@ -0,0 +1,36 @@
+void create()
+{
+  master()->add_precompiled_program("/precompiled/fifo", class {
+    inherit "/precompiled/condition": r_cond;
+    inherit "/precompiled/condition": w_cond;
+    inherit "/precompiled/mutex": lock;
+
+    mixed *buffer;
+    int r_ptr, w_ptr;
+
+    int query_messages()    {  return w_ptr - r_ptr;  }
+    
+    mixed read()
+    {
+      mixed tmp;
+      object key=lock::lock();
+      while(!query_messages()) r_cond::wait(key);
+      tmp=buffer[r_ptr++ % sizeof(buffer)];
+      w_cond::signal();
+      return tmp;
+    }
+
+    void write(mixed v)
+    {
+      object key=lock::lock();
+      while(query_messages() == sizeof(buffer)) w_cond::wait(key);
+      buffer[w_ptr++ % sizeof(buffer)]=v;
+      r_cond::signal();
+    }
+
+    varargs void create(int size)
+    {
+      buffer=allocate(size || 128);
+    }
+  });
+}
-- 
GitLab