1 /* FluidSynth - A Software Synthesizer
3 * Copyright (C) 2003 Peter Hanappe and others.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public License
7 * as published by the Free Software Foundation; either version 2 of
8 * the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the Free
17 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 * Josh Green <josh@resonance.org>
26 #include "fluid_ringbuffer.h"
27 #include "fluidsynth_priv.h"
31 * Create a lock free queue with a fixed maximum count and size of elements.
32 * @param count Count of elements in queue (fixed max number of queued elements)
33 * @return New lock free queue or NULL if out of memory (error message logged)
35 * Lockless FIFO queues don't use any locking mechanisms and can therefore be
36 * advantageous in certain situations, such as passing data between a lower
37 * priority thread and a higher "real time" thread, without potential lock
38 * contention which could stall the high priority thread. Note that there may
39 * only be one producer thread and one consumer thread.
42 new_fluid_ringbuffer (int count, int elementsize)
44 fluid_ringbuffer_t *queue;
46 fluid_return_val_if_fail (count > 0, NULL);
48 queue = FLUID_NEW (fluid_ringbuffer_t);
52 FLUID_LOG (FLUID_ERR, "Out of memory");
56 queue->array = FLUID_MALLOC (elementsize * count);
61 FLUID_LOG (FLUID_ERR, "Out of memory");
65 /* Clear array, in case dynamic pointer reclaiming is being done */
66 FLUID_MEMSET (queue->array, 0, elementsize * count);
68 queue->totalcount = count;
69 queue->elementsize = elementsize;
78 * Free an event queue.
79 * @param queue Lockless queue instance
81 * Care must be taken when freeing a queue, to ensure that the consumer and
82 * producer threads will no longer access it.
85 delete_fluid_ringbuffer (fluid_ringbuffer_t *queue)
87 FLUID_FREE (queue->array);