# m_ring_fifo **Repository Path**: wei513723/m_ring_fifo ## Basic Information - **Project Name**: m_ring_fifo - **Description**: 无锁环形队列。 - **Primary Language**: C - **License**: AGPL-3.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-09-08 - **Last Updated**: 2023-07-24 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 介绍 适合用于非抢占式调度操作系统的环形缓冲区 # 说明 代码中多生产者多消费者的函数使用了`gcc`的原子锁功能,所以需要确保gcc版本不小于`4.1.2`,也可以通过改写源码中的`atomic_cmp_and_swap32`函数实现。 # 测试 ## 编译 make ## 运行 ./build/m_ring_fifo ## 对比 cmp tmpfile/read_file tmpfile/write_file 测试多线程的读写时应按照如下格式在源码中添加测试代码: ```c uint32_t m_ring_fifo_write_mp(struct m_ring_fifo_t *ring, const void *buf, uint32_t len) { /* ... */ while(ring->prod_tail != prod_head)thread_yield(); extern void write_wr_file(const void *buf, uint32_t len); write_wr_file(buf, wlen); ring->prod_tail = prod_next; /* ... */ } ``` ```c uint32_t m_ring_fifo_read_mc(struct m_ring_fifo_t *ring, void *buf, uint32_t len) { /* ... */ while(ring->cons_tail != cons_head)thread_yield(); extern void write_rd_file(void *buf, uint32_t len); write_rd_file(buf, rlen); ring->cons_tail = cons_next; /* ... */ } ```