2014-12-03 08:39:06 +00:00
|
|
|
/* Copyright (c) 2013-2014 Jeffrey Pfau
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2013-10-02 06:56:10 +00:00
|
|
|
#ifndef CIRCLE_BUFFER_H
|
|
|
|
#define CIRCLE_BUFFER_H
|
|
|
|
|
2016-12-31 01:00:22 +00:00
|
|
|
#include <mgba-util/common.h>
|
2013-10-02 06:56:10 +00:00
|
|
|
|
2016-12-27 05:01:55 +00:00
|
|
|
CXX_GUARD_START
|
|
|
|
|
2013-10-02 06:56:10 +00:00
|
|
|
struct CircleBuffer {
|
|
|
|
void* data;
|
2014-07-21 06:56:12 +00:00
|
|
|
size_t capacity;
|
|
|
|
size_t size;
|
2013-10-02 06:56:10 +00:00
|
|
|
void* readPtr;
|
|
|
|
void* writePtr;
|
|
|
|
};
|
|
|
|
|
|
|
|
void CircleBufferInit(struct CircleBuffer* buffer, unsigned capacity);
|
|
|
|
void CircleBufferDeinit(struct CircleBuffer* buffer);
|
2014-07-21 06:56:12 +00:00
|
|
|
size_t CircleBufferSize(const struct CircleBuffer* buffer);
|
|
|
|
size_t CircleBufferCapacity(const struct CircleBuffer* buffer);
|
2014-07-08 07:02:39 +00:00
|
|
|
void CircleBufferClear(struct CircleBuffer* buffer);
|
2013-10-03 08:25:51 +00:00
|
|
|
int CircleBufferWrite8(struct CircleBuffer* buffer, int8_t value);
|
2014-12-21 09:14:30 +00:00
|
|
|
int CircleBufferWrite16(struct CircleBuffer* buffer, int16_t value);
|
2013-10-02 06:56:10 +00:00
|
|
|
int CircleBufferWrite32(struct CircleBuffer* buffer, int32_t value);
|
2013-10-02 09:45:41 +00:00
|
|
|
int CircleBufferRead8(struct CircleBuffer* buffer, int8_t* value);
|
2014-12-21 09:14:30 +00:00
|
|
|
int CircleBufferRead16(struct CircleBuffer* buffer, int16_t* value);
|
2013-10-02 06:56:10 +00:00
|
|
|
int CircleBufferRead32(struct CircleBuffer* buffer, int32_t* value);
|
2017-03-22 05:30:30 +00:00
|
|
|
size_t CircleBufferWrite(struct CircleBuffer* buffer, const void* input, size_t length);
|
2014-07-21 06:56:12 +00:00
|
|
|
size_t CircleBufferRead(struct CircleBuffer* buffer, void* output, size_t length);
|
|
|
|
size_t CircleBufferDump(const struct CircleBuffer* buffer, void* output, size_t length);
|
2013-10-02 06:56:10 +00:00
|
|
|
|
2016-12-27 05:01:55 +00:00
|
|
|
CXX_GUARD_END
|
|
|
|
|
2013-10-02 06:56:10 +00:00
|
|
|
#endif
|