SameBoy | Accurate GB/GBC emulator |
| download: https://git.y1.nz/archives/sameboy.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit 9383acda342784794a4c624d313df21cfafd7244 parent 44618f75c433096f5f38890442ec5742d895c6a6 Author: Lior Halphon <LIJI32@gmail.com> Date: Sun, 31 Jul 2022 00:41:27 +0300 Optimize performAtomicBlock Diffstat:
| M | Cocoa/Document.m | 33 | ++++++++++++++++++++++++--------- |
1 file changed, 24 insertions(+), 9 deletions(-)
diff --git a/Cocoa/Document.m b/Cocoa/Document.m @@ -104,6 +104,8 @@ enum model { NSSavePanel *_audioSavePanel; bool _isRecordingAudio; + + volatile void (^_pendingAtomicBlock)(); } @property GBAudioClient *audioClient; @@ -477,7 +479,7 @@ static unsigned *multiplication_table_for_frequency(unsigned frequency) return ret; } -- (void) run +- (void)run { assert(!master); [self preRun]; @@ -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,20 +1516,25 @@ 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; + isRunning |= master->running; } - if (was_running) { - [self stop]; + if (!isRunning) { + block(); + return; } - block(); - if (was_running) { - [self start]; + + if (master) { + [master performAtomicBlock:block]; + return; } + + _pendingAtomicBlock = block; + while (_pendingAtomicBlock); } -- (NSString *) captureOutputForBlock: (void (^)())block +- (NSString *)captureOutputForBlock: (void (^)())block { capturedOutput = [[NSMutableString alloc] init]; [self performAtomicBlock:block];
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.