2018-11-12 03:28:46 +03:00
|
|
|
#pragma once
|
|
|
|
|
2018-12-03 04:24:11 +03:00
|
|
|
#include "DoubleBuffer.h"
|
2018-11-12 03:28:46 +03:00
|
|
|
#include <AK/Retainable.h>
|
|
|
|
#include <AK/RetainPtr.h>
|
2019-01-23 07:13:17 +03:00
|
|
|
#include <Kernel/UnixTypes.h>
|
2018-11-12 03:28:46 +03:00
|
|
|
|
|
|
|
class FIFO : public Retainable<FIFO> {
|
|
|
|
public:
|
|
|
|
enum Direction {
|
|
|
|
Neither, Reader, Writer
|
|
|
|
};
|
|
|
|
|
2019-04-25 14:52:07 +03:00
|
|
|
static RetainPtr<FIFO> from_fifo_id(dword);
|
|
|
|
|
|
|
|
static Retained<FIFO> create(uid_t);
|
|
|
|
~FIFO();
|
|
|
|
|
|
|
|
uid_t uid() const { return m_uid; }
|
2018-11-12 03:28:46 +03:00
|
|
|
|
|
|
|
void open(Direction);
|
|
|
|
void close(Direction);
|
|
|
|
|
2019-02-25 23:19:57 +03:00
|
|
|
ssize_t write(const byte*, ssize_t);
|
|
|
|
ssize_t read(byte*, ssize_t);
|
2018-11-12 03:28:46 +03:00
|
|
|
|
|
|
|
bool can_read() const;
|
|
|
|
bool can_write() const;
|
|
|
|
|
|
|
|
private:
|
2019-04-25 14:52:07 +03:00
|
|
|
explicit FIFO(uid_t);
|
2018-11-12 03:28:46 +03:00
|
|
|
|
|
|
|
unsigned m_writers { 0 };
|
|
|
|
unsigned m_readers { 0 };
|
2018-12-03 04:24:11 +03:00
|
|
|
DoubleBuffer m_buffer;
|
2019-04-25 14:52:07 +03:00
|
|
|
|
|
|
|
uid_t m_uid { 0 };
|
2018-11-12 03:28:46 +03:00
|
|
|
};
|