Skip to content

Commit

Permalink
use dispatch_async
Browse files Browse the repository at this point in the history
  • Loading branch information
Code-Hex committed Oct 15, 2023
1 parent a227f03 commit ea837f0
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
10 changes: 5 additions & 5 deletions virtualization_11.m
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ void VZVirtioSocketDevice_setSocketListenerForPort(void *socketDevice, void *vmQ
void VZVirtioSocketDevice_removeSocketListenerForPort(void *socketDevice, void *vmQueue, uint32_t port)
{
if (@available(macOS 11, *)) {
dispatch_sync((dispatch_queue_t)vmQueue, ^{
dispatch_async((dispatch_queue_t)vmQueue, ^{
[(VZVirtioSocketDevice *)socketDevice removeSocketListenerForPort:port];
});
return;
Expand Down Expand Up @@ -837,7 +837,7 @@ bool vmCanStart(void *machine, void *queue)
{
if (@available(macOS 11, *)) {
__block BOOL result;
dispatch_async((dispatch_queue_t)queue, ^{
dispatch_sync((dispatch_queue_t)queue, ^{
result = ((VZVirtualMachine *)machine).canStart;
});
return (bool)result;
Expand All @@ -850,7 +850,7 @@ bool vmCanPause(void *machine, void *queue)
{
if (@available(macOS 11, *)) {
__block BOOL result;
dispatch_async((dispatch_queue_t)queue, ^{
dispatch_sync((dispatch_queue_t)queue, ^{
result = ((VZVirtualMachine *)machine).canPause;
});
return (bool)result;
Expand All @@ -863,7 +863,7 @@ bool vmCanResume(void *machine, void *queue)
{
if (@available(macOS 11, *)) {
__block BOOL result;
dispatch_async((dispatch_queue_t)queue, ^{
dispatch_sync((dispatch_queue_t)queue, ^{
result = ((VZVirtualMachine *)machine).canResume;
});
return (bool)result;
Expand All @@ -876,7 +876,7 @@ bool vmCanRequestStop(void *machine, void *queue)
{
if (@available(macOS 11, *)) {
__block BOOL result;
dispatch_async((dispatch_queue_t)queue, ^{
dispatch_sync((dispatch_queue_t)queue, ^{
result = ((VZVirtualMachine *)machine).canRequestStop;
});
return (bool)result;
Expand Down
2 changes: 1 addition & 1 deletion virtualization_12.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ bool vmCanStop(void *machine, void *queue)
{
if (@available(macOS 12, *)) {
__block BOOL result;
dispatch_async((dispatch_queue_t)queue, ^{
dispatch_sync((dispatch_queue_t)queue, ^{
result = ((VZVirtualMachine *)machine).canStop;
});
return (bool)result;
Expand Down
4 changes: 2 additions & 2 deletions virtualization_12_arm64.m
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ VZMacHardwareModelStruct convertVZMacHardwareModel2Struct(void *hardwareModelPtr
__block VZMacOSInstaller *ret;
NSString *restoreImageFilePathNSString = [NSString stringWithUTF8String:restoreImageFilePath];
NSURL *restoreImageFileURL = [NSURL fileURLWithPath:restoreImageFilePathNSString];
dispatch_sync((dispatch_queue_t)vmQueue, ^{
dispatch_async((dispatch_queue_t)vmQueue, ^{
ret = [[VZMacOSInstaller alloc] initWithVirtualMachine:(VZVirtualMachine *)virtualMachine restoreImageURL:restoreImageFileURL];
});
return ret;
Expand All @@ -427,7 +427,7 @@ void installByVZMacOSInstaller(void *installerPtr, void *vmQueue, void *progress
{
if (@available(macOS 12, *)) {
VZMacOSInstaller *installer = (VZMacOSInstaller *)installerPtr;
dispatch_sync((dispatch_queue_t)vmQueue, ^{
dispatch_async((dispatch_queue_t)vmQueue, ^{
[installer installWithCompletionHandler:^(NSError *error) {
macOSInstallCompletionHandler(completionHandler, error);
}];
Expand Down
2 changes: 1 addition & 1 deletion virtualization_13.m
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ void startWithOptionsCompletionHandler(void *machine, void *queue, void *options
#ifdef INCLUDE_TARGET_OSX_13
if (@available(macOS 13, *)) {
vm_completion_handler_t handler = makeVMCompletionHandler(cgoHandle);
dispatch_sync((dispatch_queue_t)queue, ^{
dispatch_async((dispatch_queue_t)queue, ^{
[(VZVirtualMachine *)machine startWithOptions:options completionHandler:handler];
});
Block_release(handler);
Expand Down
4 changes: 2 additions & 2 deletions virtualization_14_arm64.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void restoreMachineStateFromURLWithCompletionHandler(void *machine, void *queue,
NSString *saveFilePathNSString = [NSString stringWithUTF8String:saveFilePath];
NSURL *saveFileURL = [NSURL fileURLWithPath:saveFilePathNSString];
vm_completion_handler_t handler = makeVMCompletionHandler(cgoHandle);
dispatch_sync((dispatch_queue_t)queue, ^{
dispatch_async((dispatch_queue_t)queue, ^{
[(VZVirtualMachine *)machine restoreMachineStateFromURL:saveFileURL completionHandler:handler];
});
Block_release(handler);
Expand Down Expand Up @@ -74,7 +74,7 @@ void saveMachineStateToURLWithCompletionHandler(void *machine, void *queue, uint
NSString *saveFilePathNSString = [NSString stringWithUTF8String:saveFilePath];
NSURL *saveFileURL = [NSURL fileURLWithPath:saveFilePathNSString];
vm_completion_handler_t handler = makeVMCompletionHandler(cgoHandle);
dispatch_sync((dispatch_queue_t)queue, ^{
dispatch_async((dispatch_queue_t)queue, ^{
[(VZVirtualMachine *)machine saveMachineStateToURL:saveFileURL completionHandler:handler];
});
Block_release(handler);
Expand Down
2 changes: 1 addition & 1 deletion virtualization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ func TestStop(t *testing.T) {
vm := container.VirtualMachine

if got := vm.CanStop(); !got {
t.Fatal("want CanRequestStop is true")
t.Fatal("want CanStop is true")
}
if err := vm.Stop(); err != nil {
t.Fatal(err)
Expand Down

0 comments on commit ea837f0

Please sign in to comment.