{"id":26804376,"url":"https://github.com/eagletrt/libring-buffer-sw","last_synced_at":"2026-05-19T10:39:51.674Z","repository":{"id":285084682,"uuid":"952576618","full_name":"eagletrt/libring-buffer-sw","owner":"eagletrt","description":"Simple circular buffer data structure implementation suited for all embedded devices","archived":false,"fork":false,"pushed_at":"2025-04-03T10:13:12.000Z","size":53,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-06-08T23:36:35.531Z","etag":null,"topics":["circular-buffer","data-structures","embedded","library","platformio","platformio-library","ring-buffer","sw"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eagletrt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-21T14:09:16.000Z","updated_at":"2025-04-03T10:13:09.000Z","dependencies_parsed_at":"2025-03-29T12:35:07.818Z","dependency_job_id":null,"html_url":"https://github.com/eagletrt/libring-buffer-sw","commit_stats":null,"previous_names":["eagletrt/libring-buffer-sw"],"tags_count":0,"template":false,"template_full_name":"eagletrt/libstm32-sw-template","purl":"pkg:github/eagletrt/libring-buffer-sw","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eagletrt%2Flibring-buffer-sw","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eagletrt%2Flibring-buffer-sw/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eagletrt%2Flibring-buffer-sw/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eagletrt%2Flibring-buffer-sw/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eagletrt","download_url":"https://codeload.github.com/eagletrt/libring-buffer-sw/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eagletrt%2Flibring-buffer-sw/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265233753,"owners_count":23731825,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["circular-buffer","data-structures","embedded","library","platformio","platformio-library","ring-buffer","sw"],"created_at":"2025-03-29T22:16:30.485Z","updated_at":"2026-05-19T10:39:51.669Z","avatar_url":"https://github.com/eagletrt.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RING-BUFFER\n\nA [ring buffer](https://en.wikipedia.org/wiki/Circular_buffer) (also called a *circular buffer*, or *cyclic buffer*) \nis a [FIFO](https://en.wikipedia.org/wiki/FIFO_(computing_and_electronics)) based data structure\n(like a [queue](https://en.wikipedia.org/wiki/Queue_(abstract_data_type)) for example),\nwhere the data can be pushed and pulled as if it is a data stream.\n\nThis library provide a simple enough implementation of a ring buffer with dynamic allocation using an arena allocator.\n\n\u003e [!NOTE]\n\u003e The buffer can be thought as an array starting from the left and ending to the right\n\u003e where the items can be pushed or popped from the *front* or the *back*, if pushed from the\n\u003e front the buffer grows to the left, otherwise if pushed to the back it grows to the right\n\n## Dependencies\n\nThis library uses [ArenaAllocator](https://github.com/eagletrt/libarena-allocator-sw.git) for memory management. Make sure to initialize the allocator handler before the buffer initialization step.\n\n## Usage\n\nTo create a ring buffer, first declare a variable using `struct RingBufferHandler`. In order to initialize it, an arena allocator is needed.\n\nFor example:\n```c\nstruct RingBufferHandler int_buf;\nstruct ArenaAllocatorHandler arena;\n\narena_allocator_api_init(\u0026arena);\nring_buffer_init(\u0026int_buf, sizeof(int), 10, NULL, NULL, \u0026arena);\n```\n\nTo remove any trace of the buffer, the solely `ring_buffer_clear` function is not sufficient as it doesn't deallocate the data buffer.\nTo do so, `arena_allocator_api_free` will be used as follows:\n\n```c\nring_buffer_clear(\u0026int_buf);\narena_allocator_api_free(\u0026arena);\n```\n\nThe `cs_enter` and `cs_exit` function have to be implemented by the user\nand should define the start and the end of a critical section respectively. \\\nWith critical section it is intended a block of code in which an interrupt can happen\ncausing undefined behaviour with the data modified inside the block.\n\n\u003e [!NOTE]\n\u003e `NULL` can be passed in place of the `cs_enter` and `cs_exit` functions, in that case\n\u003e the ring buffer is not guaranteed to always work in case of interrupts\n\nHere is an example of an implementation to disable, enable and recover interrupts on a\nSTM32 microcontroller:\n```c\nuint32_t primask = 0;\nvoid cs_enter(void) {\n    primask = __get_PRIMASK();\n    __disable_irq();\n}\nvoid cs_exit(void) {\n    if (!primask)\n        __enable_irq();\n}\n```\n\n\u003e [!WARNING]\n\u003e The example above works by disabling **ALL** the interrupts and by recovering\n\u003e the previous state afterwards, this should be used carefully\n\nThe `enum RingBufferReturnCode` is returned by most of the functions of this library\nand **should always be checked** before attempting other operations with the data structure.\n\n## Examples\n\nFor more info check the [examples](./examples/) folder.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feagletrt%2Flibring-buffer-sw","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feagletrt%2Flibring-buffer-sw","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feagletrt%2Flibring-buffer-sw/lists"}