/* * Lock free FIFO * * Copyright (C) Robert Ham 2002, 2003 (node_AT_users.sourceforge.net) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef __LOCK_FREE_FIFO_H__ #define __LOCK_FREE_FIFO_H__ #include typedef struct _lff lff_t; /** lock free fifo ring buffer structure */ struct _lff { /** Size of the ringbuffer (in elements) */ unsigned int size; /** the memory containing the ringbuffer */ void * data; /** the size of an element */ size_t object_size; /** the current position of the reader */ atomic_t read_index; /** the current position of the writer */ atomic_t write_index; }; void lff_init (lff_t * lff, unsigned int size, size_t object_size); void lff_free (lff_t * lff); lff_t * lff_new (unsigned int size, size_t object_size); void lff_destroy (lff_t * lock_free_fifo); int lff_read (lff_t * lock_free_fifo, void * data); int lff_write (lff_t * lock_free_fifo, const void * data); #endif /* __LOCK_FREE_FIFO_H__ */