1. Dave Dribin
  2. DDAudioQueue

Commits

Dave Dribin  committed 087fece

Remove all traces of RAAtomicList

  • Participants
  • Parent commits a9f6867
  • Branches default

Comments (0)

Files changed (9)

File DDAudioQueue.xcodeproj/project.pbxproj

View file
  • Ignore whitespace
 		5563B58C117DE0F4001C1C0B /* DDAtomicList.c in Sources */ = {isa = PBXBuildFile; fileRef = 5563B58A117DE0F4001C1C0B /* DDAtomicList.c */; };
 		5563B5ED117DE958001C1C0B /* DDAtomicListTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 5563B5EC117DE958001C1C0B /* DDAtomicListTest.m */; };
 		55B2B67E117AB73000CC1D9A /* DDAudioQueue.m in Sources */ = {isa = PBXBuildFile; fileRef = 55B2B67D117AB73000CC1D9A /* DDAudioQueue.m */; };
-		55B2B681117AB75100CC1D9A /* RAAtomicList.m in Sources */ = {isa = PBXBuildFile; fileRef = 55B2B680117AB75100CC1D9A /* RAAtomicList.m */; };
 		55B2BCAC117C033100CC1D9A /* DDAudioQueueTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 55B2BCAA117C032600CC1D9A /* DDAudioQueueTest.m */; };
-		55B2BCC1117C042000CC1D9A /* DDAudioQueueBuffer.m in Sources */ = {isa = PBXBuildFile; fileRef = 55B2BCC0117C042000CC1D9A /* DDAudioQueueBuffer.m */; };
 		55B2BCC8117C046D00CC1D9A /* DDAudioQueue.m in Sources */ = {isa = PBXBuildFile; fileRef = 55B2B67D117AB73000CC1D9A /* DDAudioQueue.m */; };
-		55B2BCC9117C046D00CC1D9A /* DDAudioQueueBuffer.m in Sources */ = {isa = PBXBuildFile; fileRef = 55B2BCC0117C042000CC1D9A /* DDAudioQueueBuffer.m */; };
-		55B2BCCA117C046D00CC1D9A /* RAAtomicList.m in Sources */ = {isa = PBXBuildFile; fileRef = 55B2B680117AB75100CC1D9A /* RAAtomicList.m */; };
 		55EFEF92117C8E2F00E2F8B6 /* DDAudioQueueReader.m in Sources */ = {isa = PBXBuildFile; fileRef = 55EFEF91117C8E2F00E2F8B6 /* DDAudioQueueReader.m */; };
 		55EFEF93117C8E2F00E2F8B6 /* DDAudioQueueReader.m in Sources */ = {isa = PBXBuildFile; fileRef = 55EFEF91117C8E2F00E2F8B6 /* DDAudioQueueReader.m */; };
 		55EFEFA6117CE82E00E2F8B6 /* DDAudioQueueReaderTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 55EFEFA5117CE82E00E2F8B6 /* DDAudioQueueReaderTest.m */; };
 		5563B5EC117DE958001C1C0B /* DDAtomicListTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DDAtomicListTest.m; sourceTree = "<group>"; };
 		55B2B67C117AB73000CC1D9A /* DDAudioQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DDAudioQueue.h; sourceTree = "<group>"; };
 		55B2B67D117AB73000CC1D9A /* DDAudioQueue.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DDAudioQueue.m; sourceTree = "<group>"; };
-		55B2B67F117AB75100CC1D9A /* RAAtomicList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RAAtomicList.h; sourceTree = "<group>"; };
-		55B2B680117AB75100CC1D9A /* RAAtomicList.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RAAtomicList.m; sourceTree = "<group>"; };
 		55B2BC98117C029A00CC1D9A /* UnitTests.octest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = UnitTests.octest; sourceTree = BUILT_PRODUCTS_DIR; };
 		55B2BC99117C029A00CC1D9A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
 		55B2BCA9117C032600CC1D9A /* DDAudioQueueTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DDAudioQueueTest.h; sourceTree = "<group>"; };
 		55B2BCAA117C032600CC1D9A /* DDAudioQueueTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DDAudioQueueTest.m; sourceTree = "<group>"; };
 		55B2BCBF117C042000CC1D9A /* DDAudioQueueBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DDAudioQueueBuffer.h; sourceTree = "<group>"; };
-		55B2BCC0117C042000CC1D9A /* DDAudioQueueBuffer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DDAudioQueueBuffer.m; sourceTree = "<group>"; };
 		55B2BCF5117C05BD00CC1D9A /* DDAudioQueueDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DDAudioQueueDelegate.h; sourceTree = "<group>"; };
 		55EFEF90117C8E2F00E2F8B6 /* DDAudioQueueReader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DDAudioQueueReader.h; sourceTree = "<group>"; };
 		55EFEF91117C8E2F00E2F8B6 /* DDAudioQueueReader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DDAudioQueueReader.m; sourceTree = "<group>"; };
 				55B2B67D117AB73000CC1D9A /* DDAudioQueue.m */,
 				55B2BCF5117C05BD00CC1D9A /* DDAudioQueueDelegate.h */,
 				55B2BCBF117C042000CC1D9A /* DDAudioQueueBuffer.h */,
-				55B2BCC0117C042000CC1D9A /* DDAudioQueueBuffer.m */,
 				55EFEF90117C8E2F00E2F8B6 /* DDAudioQueueReader.h */,
 				55EFEF91117C8E2F00E2F8B6 /* DDAudioQueueReader.m */,
 				5563B589117DE0F4001C1C0B /* DDAtomicList.h */,
 				5563B58A117DE0F4001C1C0B /* DDAtomicList.c */,
-				55B2B67F117AB75100CC1D9A /* RAAtomicList.h */,
-				55B2B680117AB75100CC1D9A /* RAAtomicList.m */,
 			);
 			path = Source;
 			sourceTree = "<group>";
 			files = (
 				55B2BCAC117C033100CC1D9A /* DDAudioQueueTest.m in Sources */,
 				55B2BCC8117C046D00CC1D9A /* DDAudioQueue.m in Sources */,
-				55B2BCC9117C046D00CC1D9A /* DDAudioQueueBuffer.m in Sources */,
-				55B2BCCA117C046D00CC1D9A /* RAAtomicList.m in Sources */,
 				55EFEF92117C8E2F00E2F8B6 /* DDAudioQueueReader.m in Sources */,
 				55EFEFA6117CE82E00E2F8B6 /* DDAudioQueueReaderTest.m in Sources */,
 				5563B58C117DE0F4001C1C0B /* DDAtomicList.c in Sources */,
 				8D11072D0486CEB800E47090 /* main.m in Sources */,
 				256AC3DA0F4B6AC300CF3369 /* DemoAppDelegate.m in Sources */,
 				55B2B67E117AB73000CC1D9A /* DDAudioQueue.m in Sources */,
-				55B2B681117AB75100CC1D9A /* RAAtomicList.m in Sources */,
-				55B2BCC1117C042000CC1D9A /* DDAudioQueueBuffer.m in Sources */,
 				55EFEF93117C8E2F00E2F8B6 /* DDAudioQueueReader.m in Sources */,
 				5563B58B117DE0F4001C1C0B /* DDAtomicList.c in Sources */,
 			);

File Demo/DemoAppDelegate.m

View file
  • Ignore whitespace
 
 static void processBuffer(DDAudioQueueBuffer * buffer, DDAudioQueue * queue)
 {
-    const void * bytes = DDAudioQueueBufferGetBytes(buffer);
-    NSUInteger length = DDAudioQueueBufferGetLength(buffer);
+    const void * bytes = buffer->bytes;
+    NSUInteger length = buffer->length;
     NSLog(@"Processing %u data at %p <0x%08X>", length, bytes, *(uint32_t*)bytes);
 }
 

File Source/DDAudioQueue.h

View file
  • Ignore whitespace
 //
 
 #import <Foundation/Foundation.h>
-#import "RAAtomicList.h"
 #import "DDAtomicList.h"
 #import "DDAudioQueueBuffer.h"
 
 {
     id<DDAudioQueueDelegate> _delegate;
     BOOL _isStarted;
-    NSMutableArray * _buffers;
-    RAAtomicListRef _bufferList;
-    RAAtomicListRef _renderList;
-    RAAtomicListRef _availableList;
     NSMutableDictionary * _mallocData;
-    DDAtomicListRef _bufferList2;
-    DDAtomicListRef _renderList2;
-    DDAtomicListRef _availableList2;
+    DDAtomicListRef _bufferList;
+    DDAtomicListRef _renderList;
+    DDAtomicListRef _availableList;
     CFRunLoopRef _runLoop;
     CFRunLoopSourceRef _runLoopSource;
 }

File Source/DDAudioQueue.m

View file
  • Ignore whitespace
 
 COMPILE_ASSERT(offsetof(DDAudioQueueListNode, buffer) == 0, invalid_node_offset);
 
+@interface DDAudioQueue ()
+- (void *)malloc:(size_t)size;
+- (void)free:(void *)bytes;
+@end
+
 @implementation DDAudioQueue
 
 - (id)initWithDelegate:(id<DDAudioQueueDelegate>)delegate;
         return nil;
     
     _delegate = delegate;
-    _buffers = [[NSMutableArray alloc] init];
     _mallocData = [[NSMutableDictionary alloc] init];
     
     return self;
 {
     [self removeFromRunLoop];
     [self reset];
-    [_buffers release];
     [super dealloc];
 }
 
-#if 0
 - (void)sendAvaialableBuffersToDelegate;
 {
     DDAudioQueueBuffer * buffer = NULL;
     do {
-        buffer = RAAtomicListPop(&_availableList);
-        if (buffer != NULL) {
-            buffer.length = 0;
-            [self->_delegate audioQueue:self bufferIsAvailable:buffer];
-        }
-    } while (buffer != NULL);
-}
-#else
-- (void)sendAvaialableBuffersToDelegate;
-{
-    DDAudioQueueBuffer * buffer = NULL;
-    do {
-        buffer = DDAtomicListPop(&_availableList2, NODE_OFFSET);
+        buffer = DDAtomicListPop(&_availableList, NODE_OFFSET);
         if (buffer != NULL) {
             buffer->length = 0;
             [self->_delegate audioQueue:self bufferIsAvailable:buffer];
         }
     } while (buffer != NULL);
 }
-#endif
 
 static void MyPerformCallback(void * info)
 {
     _runLoop = NULL;
 }
 
-#if 0
-- (void)popAllFromList:(RAAtomicListRef *)list
+- (void)popAllFromList:(DDAtomicListRef *)list
 {
-	while (RAAtomicListPop(list)) {
+	while (DDAtomicListPop(list, NODE_OFFSET)) {
     }
 }
 
     [self popAllFromList:&_renderList];
     [self popAllFromList:&_availableList];
 }
-#else
-- (void)popAllFromList:(DDAtomicListRef *)list
-{
-	while (DDAtomicListPop(list, NODE_OFFSET)) {
-    }
-}
-
-- (void)reset;
-{
-    [self popAllFromList:&_bufferList2];
-    [self popAllFromList:&_renderList2];
-    [self popAllFromList:&_availableList2];
-}
-#endif
-
-#if 0
-- (DDAudioQueueBuffer *)allocateBufferWithCapacity:(NSUInteger)capacity error:(NSError **)error;
-{
-    DDAudioQueueBuffer * buffer = [[(DDAudioQueueBuffer *)[DDAudioQueueBuffer alloc] initWithCapacity:capacity] autorelease];
-    [_buffers addObject:buffer];
-    
-    return buffer;
-}
-
-- (BOOL)enqueueBuffer:(DDAudioQueueBuffer *)buffer;
-{
-    NSAssert(buffer != nil, @"Buffer must not be nil");
-    RAAtomicListInsert(&_bufferList, buffer);
-    return YES;
-}
-#endif
-
-- (void *)malloc:(size_t)size
-{
-    NSMutableData * data = [NSMutableData dataWithLength:size];
-    void * bytes = [data mutableBytes];
-    NSValue * bytesValue = [NSValue valueWithPointer:bytes];
-    [_mallocData setObject:data forKey:bytesValue];
-    return bytes;
-}
-
-- (void)free:(void *)bytes
-{
-    NSValue * bytesValue = [NSValue valueWithPointer:bytes];
-    [_mallocData removeObjectForKey:bytesValue];
-}
 
 - (DDAudioQueueBuffer *)allocateBufferWithCapacity:(NSUInteger)capacity error:(NSError **)error;
 {
     // Can only assign capacity and bytes on creation because they're const.
     // Can't create and assign dynamic memory, so cheat by creating
     // a temporary one on the stack and memcpy it to our malloc'd node.
-    DDAudioQueueBuffer buffer = {
+    DDAudioQueueBuffer tempBuffer = {
         .capacity = capacity,
         .length = 0,
         .bytes = bufferBytes,
     };
-    memcpy(&node->buffer, &buffer, sizeof(buffer));
+    memcpy(&node->buffer, &tempBuffer, sizeof(node->buffer));
     
-    DDAudioQueueBuffer * buffer2 = &node->buffer;
-    NSAssert(node == (void *)buffer2, @"Invalid node layout");
+    DDAudioQueueBuffer * buffer = &node->buffer;
+    NSAssert(node == (void *)buffer, @"Invalid node layout");
     
-    return buffer2;
+    return buffer;
 }
 
 - (void)deallocateBuffer:(DDAudioQueueBuffer *)buffer;
 {
     NSAssert(buffer != nil, @"Buffer must not be nil");
     DDAudioQueueListNode * node = (DDAudioQueueListNode *)buffer;
-    DDAtomicListInsert(&_bufferList2, node, NODE_OFFSET);
+    DDAtomicListInsert(&_bufferList, node, NODE_OFFSET);
     return YES;
 }
 
-#if 0
 DDAudioQueueBuffer * DDAudioQueueDequeueBuffer(DDAudioQueue * queue)
 {
-    DDAudioQueueBuffer * buffer = (id)RAAtomicListPop(&queue->_renderList);
+    DDAudioQueueBuffer * buffer = DDAtomicListPop(&queue->_renderList, NODE_OFFSET);
     if (buffer == nil) {
-        queue->_renderList = RAAtomicListSteal(&queue->_bufferList);
-        RAAtomicListReverse(&queue->_renderList);
-        buffer = (id)RAAtomicListPop(&queue->_renderList);
+        queue->_renderList = DDAtomicListSteal(&queue->_bufferList);
+        DDAtomicListReverse(&queue->_renderList, NODE_OFFSET);
+        buffer = DDAtomicListPop(&queue->_renderList, NODE_OFFSET);
     }
     return buffer;
 }
 
 void DDAudioQueueMakeBufferAvailable(DDAudioQueue * queue, DDAudioQueueBuffer * buffer)
 {
-    RAAtomicListInsert(&queue->_availableList, buffer);
+    DDAtomicListInsert(&queue->_availableList, buffer, NODE_OFFSET);
     CFRunLoopSourceSignal(queue->_runLoopSource);
     CFRunLoopWakeUp(queue->_runLoop);
 }
-#else
-DDAudioQueueBuffer * DDAudioQueueDequeueBuffer(DDAudioQueue * queue)
+
+- (void *)malloc:(size_t)size;
 {
-    DDAudioQueueBuffer * buffer = DDAtomicListPop(&queue->_renderList2, NODE_OFFSET);
-    if (buffer == nil) {
-        queue->_renderList2 = DDAtomicListSteal(&queue->_bufferList2);
-        DDAtomicListReverse(&queue->_renderList2, NODE_OFFSET);
-        buffer = DDAtomicListPop(&queue->_renderList2, NODE_OFFSET);
-    }
-    return buffer;
+    NSMutableData * data = [NSMutableData dataWithLength:size];
+    void * bytes = [data mutableBytes];
+    NSValue * bytesValue = [NSValue valueWithPointer:bytes];
+    [_mallocData setObject:data forKey:bytesValue];
+    return bytes;
 }
 
-void DDAudioQueueMakeBufferAvailable(DDAudioQueue * queue, DDAudioQueueBuffer * buffer)
+- (void)free:(void *)bytes;
 {
-    DDAtomicListInsert(&queue->_availableList2, buffer, NODE_OFFSET);
-    CFRunLoopSourceSignal(queue->_runLoopSource);
-    CFRunLoopWakeUp(queue->_runLoop);
+    NSValue * bytesValue = [NSValue valueWithPointer:bytes];
+    [_mallocData removeObjectForKey:bytesValue];
 }
-#endif
 
 @end

File Source/DDAudioQueueBuffer.h

View file
  • Ignore whitespace
     NSUInteger length;
     void * const bytes;
 } DDAudioQueueBuffer;
-
-#if 0
-@interface DDAudioQueueBuffer : NSObject
-{
-@private
-    NSMutableData * _data;
-    NSUInteger _capacity;
-    void * _bytes;
-    NSUInteger _length;
-}
-
-@property (nonatomic, readonly) NSUInteger capacity;
-@property (nonatomic, readonly) void * bytes;
-@property (nonatomic, readwrite) NSUInteger length;
-
-- (id)initWithCapacity:(NSUInteger)capacity;
-
-@end
-#endif
-
-const void * DDAudioQueueBufferGetBytes(DDAudioQueueBuffer * buffer);
-NSUInteger DDAudioQueueBufferGetLength(DDAudioQueueBuffer * buffer);

File Source/DDAudioQueueBuffer.m

  • Ignore whitespace
-//
-
-#import "DDAudioQueueBuffer.h"
-
-
-#if 0
-@implementation DDAudioQueueBuffer
-
-- (id)initWithCapacity:(NSUInteger)capacity;
-{
-    self = [super init];
-    if (self == nil)
-        return nil;
-    
-    _data = [[NSMutableData alloc] initWithLength:capacity];
-    _capacity = capacity;
-    _bytes = [_data mutableBytes];
-    _length = 0;
-    
-    return self;
-}
-
-- (void) dealloc
-{
-    [_data release];
-    [super dealloc];
-}
-
-- (NSUInteger)capacity;
-{
-    return _capacity;
-}
-
-- (void *)bytes;
-{
-    return _bytes;
-}
-
-- (NSUInteger)length;
-{
-    return _length;
-}
-
-- (void)setLength:(NSUInteger)length;
-{
-    _length = length;
-}
-
-const void * DDAudioQueueBufferGetBytes(DDAudioQueueBuffer * buffer)
-{
-    return buffer->_bytes;
-}
-
-NSUInteger DDAudioQueueBufferGetLength(DDAudioQueueBuffer * buffer)
-{
-    return buffer->_length;
-}
-
-@end
-#endif
-
-const void * DDAudioQueueBufferGetBytes(DDAudioQueueBuffer * buffer)
-{
-    return buffer->bytes;
-}
-
-NSUInteger DDAudioQueueBufferGetLength(DDAudioQueueBuffer * buffer)
-{
-    return buffer->length;
-}

File Source/DDAudioQueueReader.m

View file
  • Ignore whitespace
         return 0;
     }
     
-    NSUInteger bufferLength = DDAudioQueueBufferGetLength(reader->_readBuffer);
+    NSUInteger bufferLength = reader->_readBuffer->length;
     NSUInteger bytesRemainingInReadBuffer = bufferLength - reader->_readCursor;
     UInt32 bytesToCopy = MIN(bytesToRead, bytesRemainingInReadBuffer);
 
-    const uint8_t * readBufferBytes = DDAudioQueueBufferGetBytes(reader->_readBuffer);
+    const uint8_t * readBufferBytes = reader->_readBuffer->bytes;
     readBufferBytes += reader->_readCursor;
     
     memcpy(buffer, readBufferBytes, bytesToCopy);

File Source/RAAtomicList.h

  • Ignore whitespace
-//
-//  RAAtomicList.h
-//  AudioHijackKit2
-//
-//  Created by Michael Ash on 11/9/08.
-//  Copyright 2008 Rogue Amoeba Software, LLC. All rights reserved.
-//
-
-#import <Cocoa/Cocoa.h>
-
-
-// thread safe linked list utilities
-// a NULL list is considered empty
-typedef struct RAAtomicListNode *RAAtomicListRef;
-
-
-// thread safe functions: may be called on a shared list from multiple threads with no locking
-void RAAtomicListInsert( RAAtomicListRef *listPtr, void *elt );
-RAAtomicListRef RAAtomicListSteal( RAAtomicListRef *listPtr );
-
-// thread unsafe functions: must be called only on lists which other threads cannot access
-void RAAtomicListReverse( RAAtomicListRef *listPtr );
-void *RAAtomicListPop( RAAtomicListRef *listPtr); // returns NULL on empty list
-

File Source/RAAtomicList.m

  • Ignore whitespace
-//
-//  RAAtomicList.m
-//  AudioHijackKit2
-//
-//  Created by Michael Ash on 11/9/08.
-//  Copyright 2008 Rogue Amoeba Software, LLC. All rights reserved.
-//
-
-#import "RAAtomicList.h"
-
-#import <libkern/OSAtomic.h>
-
-
-struct RAAtomicListNode
-{
-	struct RAAtomicListNode *next;
-	void *elt;
-};
-
-void RAAtomicListInsert( RAAtomicListRef *listPtr, void *elt )
-{
-	struct RAAtomicListNode *node = malloc( sizeof( *node ) );
-	node->elt = elt;
-	
-	do {
-		node->next = *listPtr;
-	} while( !OSAtomicCompareAndSwapPtrBarrier( node->next, node, (void **)listPtr ) );
-}
-
-RAAtomicListRef RAAtomicListSteal( RAAtomicListRef *listPtr )
-{
-	RAAtomicListRef ret;
-	do {
-		ret = *listPtr;
-	} while( !OSAtomicCompareAndSwapPtrBarrier( ret, NULL, (void **)listPtr ) );
-	return ret;
-}
-
-void RAAtomicListReverse( RAAtomicListRef *listPtr )
-{
-	struct RAAtomicListNode *cur = *listPtr;
-	struct RAAtomicListNode *prev = NULL;
-	struct RAAtomicListNode *next = NULL;
-	
-	if( !cur )
-		return;
-	
-	do {
-		next = cur->next;
-		cur->next = prev;
-		
-		if( next )
-		{
-			prev = cur;
-			cur = next;
-		}
-	} while( next );
-	
-	*listPtr = cur;
-}
-
-void *RAAtomicListPop( RAAtomicListRef *listPtr)
-{
-	struct RAAtomicListNode *node = *listPtr;
-	if( !node )
-		return NULL;
-	
-	*listPtr = node->next;
-	
-	void *elt = node->elt;
-	free( node );
-	return elt;
-}
-