s_ring_buffer庫是一個采用MIT License協定開源的、小巧的、純C語言的、ring_buffer實作,讀寫鎖分離設計,核心實作代碼平台無關(抽出了平台相關的适配層), 可以友善的進行移植、使用。
倉庫位址:https://github.com/smallerxuan/s_ring_buffer.git
s_ring_buffer使用者接口
s_ring_buffer包含如下使用者接口:`
1、構造器接口 s_ring_buffer_constructor()
2、析構器接口 s_ring_buffer_destructor()
3、清除接口 s_ring_buffer_clear()
4、元素寫入接口s_ring_buffer_write_elements()
5、元素讀取接口 s_ring_buffer_read_elements()
6、容量擷取接口 s_ring_buffer_cap_get()
7、可讀元素數量擷取接口 s_ring_buffer_could_read_num_get()
7、可寫元素數量擷取接口 s_ring_buffer_could_write_num_get()
s_ring_buffer的移植、适配
s_ring_buffer源碼中的 s_ring_buffer_platform.h、s_ring_buffer_platform.c檔案包含了s_ring_buffer的平台相關 資料類型、宏、抽象接口,主要包括:
- 記憶體操作相關宏:
s_ring_buff_malloc、s_ring_buff_free、s_ring_buff_memcpy
2、休眠相關宏 s_ring_buff_sleep
3、鎖類型定義 s_ring_buffer_lock_t
4、鎖操作相關接口:
s_ring_buffer_lock()、s_ring_buffer_trylock()、s_ring_buffer_unlock()
使用者在移植、适配時,隻需要對上述内容進行适配、實作,便能友善的在任意平台使用。
