Optimize performAtomicBlock
@@ -104,6 +104,8 @@ enum model {
NSSavePanel *_audioSavePanel;
bool _isRecordingAudio;
+
+ volatile void (^_pendingAtomicBlock)();
}
@property GBAudioClient *audioClient;
@@ -492,6 +494,10 @@ static unsigned *multiplication_table_for_frequency(unsigned frequency)
else {
linkOffset -= masterTable[GB_run(&slave->gb)];
}
+ if (unlikely(_pendingAtomicBlock)) {
+ _pendingAtomicBlock();
+ _pendingAtomicBlock = nil;
+ }
}
free(masterTable);
free(slaveTable);
@@ -509,6 +515,10 @@ static unsigned *multiplication_table_for_frequency(unsigned frequency)
else {
GB_run(&gb);
}
+ if (unlikely(_pendingAtomicBlock)) {
+ _pendingAtomicBlock();
+ _pendingAtomicBlock = nil;
+ }
}
}
[self postRun];
@@ -1506,17 +1516,22 @@ static bool is_path_writeable(const char *path)
- (void) performAtomicBlock: (void (^)())block
{
while (!GB_is_inited(&gb));
- bool was_running = running && !GB_debugger_is_stopped(&gb);
+ bool isRunning = running && !GB_debugger_is_stopped(&gb);
if (master) {
- was_running |= master->running;
- }
- if (was_running) {
- [self stop];
+ isRunning |= master->running;
}
+ if (!isRunning) {
block();
- if (was_running) {
- [self start];
+ return;
+ }
+
+ if (master) {
+ [master performAtomicBlock:block];
+ return;
}
+
+ _pendingAtomicBlock = block;
+ while (_pendingAtomicBlock);
}
- (NSString *)captureOutputForBlock: (void (^)())block
