Skip to content

Instantly share code, notes, and snippets.

@buttercutter
Last active December 19, 2018 05:01
Show Gist options
  • Save buttercutter/8d62f2d0bf01d75bbadc518171158a8d to your computer and use it in GitHub Desktop.
Save buttercutter/8d62f2d0bf01d75bbadc518171158a8d to your computer and use it in GitHub Desktop.
/*
* Filename: circ_buf.h
* Version: 1.0
* Description: A circular buffer using API from
* https://github.com/torvalds/linux/blob/master/Documentation/core-api/circular-buffers.rst
*/
#include <linux/circ_buf.h>
// power-of-2 sized buffers
#define CIRC_BUFF_SIZE 8
/**
* Initializes a circ_queue with depth/length len. Returns non-NULL on success,
* NULL if there was a problem creating the queue.
*/
struct circ_buf * init_circ_queue(int len);
/**
* Pushes a pair of unsigned int values into the specified queue at the head.
* Returns 0 on success, non-zero if there is no more space in the queue.
*/
int push_circ_queue(struct circ_buf * q, unsigned int val1, unsigned int val2);
/**
* Pops a pair of unsigned int values out of the specified queue from the tail.
* Returns 0 on success, non-zero if the queue is empty.
*/
int pop_circ_queue(struct circ_buf * q, unsigned int * val1, unsigned int * val2);
/**
* Frees the resources associated with the specified circ_queue.
*/
void free_circ_queue(struct circ_buf * q);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment