//go:build windows package installer import ( "errors" "runtime" "testing" "golang.org/x/sys/windows" ) const shellFixtureMutexName = `Local\ReimsGo-Test-MSYS` func lockPOSIXShell(t *testing.T) { t.Helper() runtime.LockOSThread() name, err := windows.UTF16PtrFromString(shellFixtureMutexName) if err != nil { runtime.UnlockOSThread() t.Fatal(err) } handle, err := windows.CreateMutex(nil, false, name) if err != nil && !errors.Is(err, windows.ERROR_ALREADY_EXISTS) { runtime.UnlockOSThread() t.Fatalf("create MSYS test mutex: %v", err) } event, err := windows.WaitForSingleObject(handle, windows.INFINITE) if err != nil { _ = windows.CloseHandle(handle) runtime.UnlockOSThread() t.Fatalf("wait for MSYS test mutex: %v", err) } if event != windows.WAIT_OBJECT_0 && event != windows.WAIT_ABANDONED { _ = windows.CloseHandle(handle) runtime.UnlockOSThread() t.Fatalf("unexpected MSYS test mutex result: %#x", event) } t.Cleanup(func() { if err := windows.ReleaseMutex(handle); err != nil { t.Errorf("release MSYS test mutex: %v", err) } if err := windows.CloseHandle(handle); err != nil { t.Errorf("close MSYS test mutex: %v", err) } runtime.UnlockOSThread() }) }