aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/alcRing.c
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2014-04-16 01:39:11 -0700
committerChris Robinson <[email protected]>2014-04-16 01:39:11 -0700
commit29cb5058c0b05cca8ebeb40d84aba8a8d2e11075 (patch)
tree749d963f365901b22eabd8eaf164f38f2efb8789 /Alc/alcRing.c
parent9c70ca9da6479595946def59cd616e6823c86d78 (diff)
Use a C11-like mutex wrapper instead of CRITICAL_SECTIONs
Diffstat (limited to 'Alc/alcRing.c')
-rw-r--r--Alc/alcRing.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/Alc/alcRing.c b/Alc/alcRing.c
index f831860f..9b5d8214 100644
--- a/Alc/alcRing.c
+++ b/Alc/alcRing.c
@@ -24,6 +24,7 @@
#include <stdlib.h>
#include "alMain.h"
+#include "threads.h"
#include "compat.h"
@@ -35,7 +36,7 @@ struct RingBuffer {
ALint read_pos;
ALint write_pos;
- CRITICAL_SECTION cs;
+ almtx_t mtx;
};
@@ -51,7 +52,7 @@ RingBuffer *CreateRingBuffer(ALsizei frame_size, ALsizei length)
ring->read_pos = 0;
ring->write_pos = 0;
- InitializeCriticalSection(&ring->cs);
+ almtx_init(&ring->mtx, almtx_plain);
}
return ring;
}
@@ -60,7 +61,7 @@ void DestroyRingBuffer(RingBuffer *ring)
{
if(ring)
{
- DeleteCriticalSection(&ring->cs);
+ almtx_destroy(&ring->mtx);
free(ring);
}
}
@@ -69,9 +70,9 @@ ALsizei RingBufferSize(RingBuffer *ring)
{
ALsizei s;
- EnterCriticalSection(&ring->cs);
+ almtx_lock(&ring->mtx);
s = (ring->write_pos-ring->read_pos+ring->length) % ring->length;
- LeaveCriticalSection(&ring->cs);
+ almtx_unlock(&ring->mtx);
return s;
}
@@ -80,7 +81,7 @@ void WriteRingBuffer(RingBuffer *ring, const ALubyte *data, ALsizei len)
{
int remain;
- EnterCriticalSection(&ring->cs);
+ almtx_lock(&ring->mtx);
remain = (ring->read_pos-ring->write_pos-1+ring->length) % ring->length;
if(remain < len) len = remain;
@@ -103,14 +104,14 @@ void WriteRingBuffer(RingBuffer *ring, const ALubyte *data, ALsizei len)
ring->write_pos %= ring->length;
}
- LeaveCriticalSection(&ring->cs);
+ almtx_unlock(&ring->mtx);
}
void ReadRingBuffer(RingBuffer *ring, ALubyte *data, ALsizei len)
{
int remain;
- EnterCriticalSection(&ring->cs);
+ almtx_lock(&ring->mtx);
remain = ring->length - ring->read_pos;
if(remain < len)
@@ -124,5 +125,5 @@ void ReadRingBuffer(RingBuffer *ring, ALubyte *data, ALsizei len)
ring->read_pos += len;
ring->read_pos %= ring->length;
- LeaveCriticalSection(&ring->cs);
+ almtx_unlock(&ring->mtx);
}