Skip to content

cheng-zhongliang/kfifo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

kfifo

kfifo is a ring queue inspired by linux kernel. It is simple and efficient that can be used in embedded systems.

Features

  • Ultra Fast
  • Lock Free
  • Thread Safe (Single Producer With Single Consumer)
  • Supports C99 And UP

Usage

kfifo.h should be dropped into an existing project and compiled along with it. The library provides some macros for using. Talking is cheap, show you a sample following:

#include <assert.h>
#include <stdlib.h>

#include "kfifo.h"

int main(void) {
    _KFIFO(kfifo, int) kfifo;
    KFIFO_INIT(&kfifo, 1000);
    assert(KFIFO_CAPACITY(&kfifo) == 1023);
    do {
        int* n = calloc(1, sizeof(int));
        *n = 1;
        KFIFO_ENQUEUE(&kfifo, n);
    } while(!KFIFO_FULL(&kfifo));
    assert(KFIFO_LENGTH(&kfifo) == 1023);
    do {
        int* nn;
        KFIFO_DEQUEUE(&kfifo, nn);
        assert(*nn == 1);
        free(nn);
    } while(!KFIFO_EMPTY(&kfifo));
    assert(KFIFO_LENGTH(&kfifo) == 0);
    KFIFO_FREE(&kfifo);
    return 0;
}

About

Ring queue inspired by linux kernel

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages