af8c19d9d70e94bf44b077514f60928bc5d9889d
[melted] / src / modules / jackrack / lock_free_fifo.h
1 /*
2 * JACK Rack
3 *
4 * Copyright (C) Robert Ham 2002, 2003 (node@users.sourceforge.net)
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #ifndef __JLH_LOCK_FREE_FIFO_H__
22 #define __JLH_LOCK_FREE_FIFO_H__
23
24 /** lock free fifo ring buffer structure */
25 typedef struct lock_free_fifo {
26 /** Size of the ringbuffer (in elements) */
27 unsigned int size;
28 /** the memory containing the ringbuffer */
29 void * data;
30 /** the size of an element */
31 size_t object_size;
32 /** the current position of the reader */
33 unsigned int read_index;
34 /** the current position of the writer */
35 unsigned int write_index;
36 } lff_t;
37
38 void lff_init (lff_t * lff, unsigned int size, size_t object_size);
39 void lff_free (lff_t * lff);
40
41 lff_t * lff_new (unsigned int size, size_t object_size);
42 void lff_destroy (lff_t * lock_free_fifo);
43
44 int lff_read (lff_t * lock_free_fifo, void * data);
45 int lff_write (lff_t * lock_free_fifo, void * data);
46
47
48 #endif /* __JLH_LOCK_FREE_FIFO_H__ */