===== ring_buffer.h =====
#ifndef __RING_BUFFER_H__
#define __RING_BUFFER_H__
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <assert.h>
#include <string.h>
#include <inttypes.h>
#include <pthread.h>
typedef struct ringbuffer_s
{
int64_t mBufferSize;
char *mBuffer;
char *mBuffer_end;
char *wp;
char *rp;
pthread_mutex_t *mLock;
} ringbuffer_t;
ringbuffer_t* init_ringbuffer(int buff_size);
void free_ringbuffer(ringbuffer_t *rb);
int write_ringbuffer(ringbuffer_t *rb, uint8_t *buf, int size);
int read_ringbuffer(ringbuffer_t *rb, uint8_t *buf, int size);
int64_t space_ringbuffer(ringbuffer_t *rb);
void reset_ringbuffer(ringbuffer_t *rb);
#endif
===== ring_buffer.c
#include "ring_buffer.h"
//#define min(x, y) ({

这是一个自定义的环形缓冲队列(RingBuffer)的实现,包含初始化、释放、写入、读取和计算剩余空间等功能。代码使用C语言编写,并包含了互斥锁以保证线程安全。
最低0.47元/天 解锁文章
824

被折叠的 条评论
为什么被折叠?



