Update Fluidsynth to 2.0.1
[ardour.git] / libs / fluidsynth / src / fluid_ringbuffer.c
index f6c06dd76d16819fa2cdbb4a48cfce5070faadc0..71fd1e48a3b6aa170811d3c92d6c62e7b198ac99 100644 (file)
@@ -3,16 +3,16 @@
  * Copyright (C) 2003  Peter Hanappe and others.
  *
  * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public License
- * as published by the Free Software Foundation; either version 2 of
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
  * the License, or (at your option) any later version.
  *
  * This library 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
- * Library General Public License for more details.
+ * Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU Library General Public
+ * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  * 02110-1301, USA
  * only be one producer thread and one consumer thread.
  */
 fluid_ringbuffer_t *
-new_fluid_ringbuffer (int count, int elementsize)
+new_fluid_ringbuffer(int count, int elementsize)
 {
-  fluid_ringbuffer_t *queue;
+    fluid_ringbuffer_t *queue;
 
-  fluid_return_val_if_fail (count > 0, NULL);
+    fluid_return_val_if_fail(count > 0, NULL);
 
-  queue = FLUID_NEW (fluid_ringbuffer_t);
+    queue = FLUID_NEW(fluid_ringbuffer_t);
 
-  if (!queue)
-  {
-    FLUID_LOG (FLUID_ERR, "Out of memory");
-    return NULL;
-  }
+    if(!queue)
+    {
+        FLUID_LOG(FLUID_ERR, "Out of memory");
+        return NULL;
+    }
 
-  queue->array = FLUID_MALLOC (elementsize * count);
+    queue->array = FLUID_MALLOC(elementsize * count);
 
-  if (!queue->array)
-  {
-    FLUID_FREE (queue);
-    FLUID_LOG (FLUID_ERR, "Out of memory");
-    return NULL;
-  }
+    if(!queue->array)
+    {
+        FLUID_LOG(FLUID_ERR, "Out of memory");
+        delete_fluid_ringbuffer(queue);
+        return NULL;
+    }
 
-  /* Clear array, in case dynamic pointer reclaiming is being done */
-  FLUID_MEMSET (queue->array, 0, elementsize * count);
+    /* Clear array, in case dynamic pointer reclaiming is being done */
+    FLUID_MEMSET(queue->array, 0, elementsize * count);
 
-  queue->totalcount = count;
-  queue->elementsize = elementsize;
-  queue->count = 0;
-  queue->in = 0;
-  queue->out = 0;
+    queue->totalcount = count;
+    queue->elementsize = elementsize;
+    fluid_atomic_int_set(&queue->count, 0);
+    queue->in = 0;
+    queue->out = 0;
 
-  return (queue);
+    return (queue);
 }
 
 /**
@@ -82,8 +82,9 @@ new_fluid_ringbuffer (int count, int elementsize)
  * producer threads will no longer access it.
  */
 void
-delete_fluid_ringbuffer (fluid_ringbuffer_t *queue)
+delete_fluid_ringbuffer(fluid_ringbuffer_t *queue)
 {
-  FLUID_FREE (queue->array);
-  FLUID_FREE (queue);
+    fluid_return_if_fail(queue != NULL);
+    FLUID_FREE(queue->array);
+    FLUID_FREE(queue);
 }