summaryrefslogtreecommitdiff
path: root/Kernel/FIFO.h
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2018-11-12 01:28:46 +0100
committerAndreas Kling <awesomekling@gmail.com>2018-11-12 01:28:46 +0100
commitf1404aa9484e1a38b0924f74ac8b5796faf5c77a (patch)
treebe571507f54f885aca4eddd0a8bc03f2ada4ee04 /Kernel/FIFO.h
parent18e3ddf6058d86f22df9fd90f6ad7f3a3833909f (diff)
downloadserenity-f1404aa9484e1a38b0924f74ac8b5796faf5c77a.zip
Add primitive FIFO and hook it up to sys$pipe().
It's now possible to do this in bash: cat kernel.map | fgrep List This is very cool! :^)
Diffstat (limited to 'Kernel/FIFO.h')
-rw-r--r--Kernel/FIFO.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/Kernel/FIFO.h b/Kernel/FIFO.h
new file mode 100644
index 0000000000..2cb65c4e03
--- /dev/null
+++ b/Kernel/FIFO.h
@@ -0,0 +1,31 @@
+#pragma once
+
+#include <AK/CircularQueue.h>
+#include <AK/Retainable.h>
+#include <AK/RetainPtr.h>
+#include <VirtualFileSystem/UnixTypes.h>
+
+class FIFO : public Retainable<FIFO> {
+public:
+ enum Direction {
+ Neither, Reader, Writer
+ };
+
+ static RetainPtr<FIFO> create();
+
+ void open(Direction);
+ void close(Direction);
+
+ Unix::ssize_t write(const byte*, Unix::size_t);
+ Unix::ssize_t read(byte*, Unix::size_t);
+
+ bool can_read() const;
+ bool can_write() const;
+
+private:
+ FIFO();
+
+ unsigned m_writers { 0 };
+ unsigned m_readers { 0 };
+ CircularQueue<byte, 16> m_queue;
+};