PageRenderTime 24ms CodeModel.GetById 17ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/src/rt/circular_buffer.h

http://github.com/jruderman/rust
C Header | 57 lines | 28 code | 11 blank | 18 comment | 0 complexity | d9edaf46db027d603e863185de8dcc33 MD5 | raw file
 1/*
 2 *
 3 */
 4
 5#ifndef CIRCULAR_BUFFER_H
 6#define CIRCULAR_BUFFER_H
 7
 8#include "rust_globals.h"
 9#include "rust_kernel.h"
10
11class
12circular_buffer : public kernel_owned<circular_buffer> {
13    static const size_t INITIAL_CIRCULAR_BUFFER_SIZE_IN_UNITS = 8;
14
15public:
16    rust_kernel *kernel;
17    // Size of the data unit in bytes.
18    const size_t unit_sz;
19    circular_buffer(rust_kernel *kernel, size_t unit_sz);
20    ~circular_buffer();
21    void transfer(void *dst);
22    void enqueue(void *src);
23    void dequeue(void *dst);
24    uint8_t *peek();
25    bool is_empty();
26    size_t size();
27
28private:
29    size_t initial_size();
30    void grow();
31    void shrink();
32
33    // Size of the buffer in bytes.
34    size_t _buffer_sz;
35
36    // Byte offset within the buffer where to read the next unit of data.
37    size_t _next;
38
39    // Number of bytes that have not been read from the buffer.
40    size_t _unread;
41
42    // The buffer itself.
43    uint8_t *_buffer;
44};
45
46//
47// Local Variables:
48// mode: C++
49// fill-column: 78;
50// indent-tabs-mode: nil
51// c-basic-offset: 4
52// buffer-file-coding-system: utf-8-unix
53// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
54// End:
55//
56
57#endif /* CIRCULAR_BUFFER_H */