AEMessageQueue.h
Go to the documentation of this file.
1 //
2 // AEMessageQueue.h
3 // TheAmazingAudioEngine
4 //
5 // Created by Michael Tyson on 29/04/2016.
6 // Copyright © 2016 A Tasty Pixel. All rights reserved.
7 //
8 // This software is provided 'as-is', without any express or implied
9 // warranty. In no event will the authors be held liable for any damages
10 // arising from the use of this software.
11 //
12 // Permission is granted to anyone to use this software for any purpose,
13 // including commercial applications, and to alter it and redistribute it
14 // freely, subject to the following restrictions:
15 //
16 // 1. The origin of this software must not be misrepresented; you must not
17 // claim that you wrote the original software. If you use this software
18 // in a product, an acknowledgment in the product documentation would be
19 // appreciated but is not required.
20 //
21 // 2. Altered source versions must be plainly marked as such, and must not be
22 // misrepresented as being the original software.
23 //
24 // 3. This notice may not be removed or altered from any source distribution.
25 //
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 #import <Foundation/Foundation.h>
32 #import "AETime.h"
33 
35 typedef struct {
36  BOOL isValue;
37  const void * _Nullable data;
38  size_t length;
39 } AEArgument;
40 
43 
62 #define AEArgumentScalar(argument) \
63  (AEArgument){ YES, &(typeof(argument)){argument}, sizeof(argument) }
64 
80 #define AEArgumentStruct(argument) \
81  (AEArgument){ YES, &(argument), sizeof(argument) }
82 
96 #define AEArgumentData(buffer, size) \
97  (AEArgument) { NO, buffer, size }
98 
100 typedef void (^AEMessageQueueBlock)();
101 
115 @interface AEMessageQueue : NSObject
116 
120 - (instancetype _Nonnull)init;
121 
128 - (instancetype _Nullable)initWithBufferCapacity:(size_t)bufferCapacity;
129 
139 - (void)performBlockOnAudioThread:(AEMessageQueueBlock _Nonnull)block;
140 
156 - (void)performBlockOnAudioThread:(AEMessageQueueBlock _Nonnull)block
157  completionBlock:(AEMessageQueueBlock _Nullable)completionBlock;
158 
171 BOOL AEMessageQueuePerformSelectorOnMainThread(__unsafe_unretained AEMessageQueue * _Nonnull messageQueue,
172  __unsafe_unretained id _Nonnull target,
173  SEL _Nonnull selector,
174  AEArgument arguments, ...);
175 
182 - (void)beginMessageGroup;
183 
187 - (void)endMessageGroup;
188 
194 void AEMessageQueuePoll(__unsafe_unretained AEMessageQueue * _Nonnull THIS);
195 
196 @end
197 
198 #ifdef __cplusplus
199 }
200 #endif