summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorxant <xant@dyne.org>2012-06-15 00:41:04 (GMT)
committer xant <xant@dyne.org>2012-06-15 00:41:04 (GMT)
commitd43cd1c33b1fbe0772c070467a35def7d487b118 (patch)
tree28e9d267c979cc5ba9b449eba98081108bda1e61
parent9074fc77665efef7f9e7598a14dd6a701050dc4b (diff)
switched to lockless operations using OSAtomicIncrement32
-rw-r--r--entities/JMXAudioOutput.h5
-rw-r--r--entities/JMXAudioOutput.mm15
2 files changed, 8 insertions, 12 deletions
diff --git a/entities/JMXAudioOutput.h b/entities/JMXAudioOutput.h
index 743617b..8d42311 100644
--- a/entities/JMXAudioOutput.h
+++ b/entities/JMXAudioOutput.h
@@ -46,10 +46,9 @@
UInt32 convertedOffset;
UInt32 chunkSize;
JMXAudioBuffer *samples[kJMXAudioOutputSamplesBufferCount];
- UInt32 wOffset;
- UInt32 rOffset;
+ volatile int32_t wOffset;
+ volatile int32_t rOffset;
BOOL needsPrefill;
- NSLock *writersLock;
}
- (JMXAudioBuffer *)currentSample;
diff --git a/entities/JMXAudioOutput.mm b/entities/JMXAudioOutput.mm
index b11996b..8c690e9 100644
--- a/entities/JMXAudioOutput.mm
+++ b/entities/JMXAudioOutput.mm
@@ -27,6 +27,7 @@
#import "JMXAudioFormat.h"
#define __JMXV8__ 1
#import "JMXAudioOutput.h"
+#import <libkern/OSAtomic.h>
#define kJMXAudioOutputPreBufferMaxSize 30
#define kJMXAudioOutputPreBufferMinSize 15
@@ -139,10 +140,9 @@ static OSStatus _FillComplexBufferProc (
}
#else
JMXAudioBuffer *previousSample;
- [writersLock lock];
previousSample = samples[wOffset%kJMXAudioOutputSamplesBufferCount];
- samples[wOffset++%kJMXAudioOutputSamplesBufferCount] = [buffer retain];
- [writersLock unlock];
+ samples[wOffset+1%kJMXAudioOutputSamplesBufferCount] = [buffer retain];
+ OSAtomicIncrement32(&wOffset);
// let's have the buffer released next time the active pool is drained
// we want to return as soon as possible
if (previousSample)
@@ -161,10 +161,9 @@ static OSStatus _FillComplexBufferProc (
//NSLog(@"r: %d - w: %d", rOffset % kJMXAudioOutputSamplesBufferCount , wOffset % kJMXAudioOutputSamplesBufferCount);
JMXAudioBuffer *sample = nil;
if (rOffset < wOffset && !needsPrefill) {
- @synchronized(self) {
- sample = samples[rOffset%kJMXAudioOutputSamplesBufferCount];
- samples[rOffset++%kJMXAudioOutputSamplesBufferCount] = nil;
- }
+ sample = samples[rOffset%kJMXAudioOutputSamplesBufferCount];
+ samples[rOffset+1%kJMXAudioOutputSamplesBufferCount] = nil;
+ OSAtomicIncrement32(&rOffset);
}
return [sample autorelease];
#else
@@ -233,8 +232,6 @@ static OSStatus _FillComplexBufferProc (
{
if (format)
[format dealloc];
- if (writersLock)
- [writersLock release];
for (int i = 0; i < kJMXAudioOutputSamplesBufferCount; i++) {
if (samples[i])
[samples[i] release];