summaryrefslogtreecommitdiff
path: root/Kernel/FIFO.h
blob: cef704a39749eb511becb4bdd9f77b5ce6083259 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#pragma once

#include "DoubleBuffer.h"
#include <AK/Retainable.h>
#include <AK/RetainPtr.h>
#include <Kernel/UnixTypes.h>

class FIFO : public Retainable<FIFO> {
public:
    enum Direction {
        Neither, Reader, Writer
    };

    static Retained<FIFO> create();

    void open(Direction);
    void close(Direction);

    ssize_t write(const byte*, ssize_t);
    ssize_t read(byte*, ssize_t);

    bool can_read() const;
    bool can_write() const;

private:
    FIFO();

    unsigned m_writers { 0 };
    unsigned m_readers { 0 };
    DoubleBuffer m_buffer;
};