aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Alc/ringbuffer.c19
-rw-r--r--OpenAL32/Include/alMain.h14
-rw-r--r--common/atomic.h13
3 files changed, 29 insertions, 17 deletions
diff --git a/Alc/ringbuffer.c b/Alc/ringbuffer.c
index e2ea2ab5..e029e9b6 100644
--- a/Alc/ringbuffer.c
+++ b/Alc/ringbuffer.c
@@ -24,7 +24,8 @@
#include <stdlib.h>
#include "ringbuffer.h"
-#include "alMain.h"
+#include "align.h"
+#include "atomic.h"
#include "threads.h"
#include "almalloc.h"
#include "compat.h"
@@ -49,9 +50,21 @@ struct ll_ringbuffer {
ll_ringbuffer_t *ll_ringbuffer_create(size_t sz, size_t elem_sz)
{
ll_ringbuffer_t *rb;
- size_t power_of_two;
+ size_t power_of_two = 0;
- power_of_two = NextPowerOf2((ALuint)sz);
+ if(sz > 0)
+ {
+ power_of_two = sz - 1;
+ power_of_two |= power_of_two>>1;
+ power_of_two |= power_of_two>>2;
+ power_of_two |= power_of_two>>4;
+ power_of_two |= power_of_two>>8;
+ power_of_two |= power_of_two>>16;
+#if SIZE_MAX > UINT_MAX
+ power_of_two |= power_of_two>>32;
+#endif
+ }
+ power_of_two++;
if(power_of_two < sz) return NULL;
rb = al_malloc(16, sizeof(*rb) + power_of_two*elem_sz);
diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h
index 917e2e39..7af1c195 100644
--- a/OpenAL32/Include/alMain.h
+++ b/OpenAL32/Include/alMain.h
@@ -187,20 +187,6 @@ AL_API ALboolean AL_APIENTRY alIsBufferFormatSupportedSOFT(ALenum format);
#ifdef __GNUC__
-/* This helps cast away the const-ness of a pointer without accidentally
- * changing the pointer type. This is necessary due to Clang's inability to use
- * atomic_load on a const _Atomic variable.
- */
-#define CONST_CAST(T, V) __extension__({ \
- const T _tmp = (V); \
- (T)_tmp; \
-})
-#else
-#define CONST_CAST(T, V) ((T)(V))
-#endif
-
-
-#ifdef __GNUC__
#define LIKELY(x) __builtin_expect(!!(x), !0)
#define UNLIKELY(x) __builtin_expect(!!(x), 0)
#else
diff --git a/common/atomic.h b/common/atomic.h
index 874d510d..2033476b 100644
--- a/common/atomic.h
+++ b/common/atomic.h
@@ -4,6 +4,19 @@
#include "static_assert.h"
#include "bool.h"
+#ifdef __GNUC__
+/* This helps cast away the const-ness of a pointer without accidentally
+ * changing the pointer type. This is necessary due to Clang's inability to use
+ * atomic_load on a const _Atomic variable.
+ */
+#define CONST_CAST(T, V) __extension__({ \
+ const T _tmp = (V); \
+ (T)_tmp; \
+})
+#else
+#define CONST_CAST(T, V) ((T)(V))
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif