Skip to content

Commit

Permalink
Merge pull request #126 from Code-Hex/add/go-infinity-channel
Browse files Browse the repository at this point in the history
add go-infinity-channel
  • Loading branch information
Code-Hex committed Apr 15, 2023
2 parents 424c865 + 00e3602 commit 6c8b0b0
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 9 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/compile.yml
Expand Up @@ -30,8 +30,9 @@ jobs:
- macOS-11
- macOS-12
go:
- 1.18
- 1.19
- '^1.18'
- '^1.19'
- '^1.20'
steps:
- name: Check out repository code
uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions example/gui-linux/go.mod
Expand Up @@ -10,6 +10,7 @@ require (
)

require (
github.com/Code-Hex/go-infinity-channel v1.0.0 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
golang.org/x/mod v0.6.0 // indirect
golang.org/x/sys v0.1.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions example/gui-linux/go.sum
@@ -1,3 +1,5 @@
github.com/Code-Hex/go-infinity-channel v1.0.0 h1:M8BWlfDOxq9or9yvF9+YkceoTkDI1pFAqvnP87Zh0Nw=
github.com/Code-Hex/go-infinity-channel v1.0.0/go.mod h1:5yUVg/Fqao9dAjcpzoQ33WwfdMWmISOrQloDRn3bsvY=
github.com/Songmu/prompter v0.5.1 h1:IAsttKsOZWSDw7bV1mtGn9TAmLFAjXbp9I/eYmUUogo=
github.com/Songmu/prompter v0.5.1/go.mod h1:CS3jEPD6h9IaLaG6afrl1orTgII9+uDWuw95dr6xHSw=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
Expand Down
5 changes: 4 additions & 1 deletion example/linux/go.mod
Expand Up @@ -10,4 +10,7 @@ require (
golang.org/x/sys v0.1.0
)

require golang.org/x/mod v0.6.0 // indirect
require (
github.com/Code-Hex/go-infinity-channel v1.0.0 // indirect
golang.org/x/mod v0.6.0 // indirect
)
2 changes: 2 additions & 0 deletions example/linux/go.sum
@@ -1,3 +1,5 @@
github.com/Code-Hex/go-infinity-channel v1.0.0 h1:M8BWlfDOxq9or9yvF9+YkceoTkDI1pFAqvnP87Zh0Nw=
github.com/Code-Hex/go-infinity-channel v1.0.0/go.mod h1:5yUVg/Fqao9dAjcpzoQ33WwfdMWmISOrQloDRn3bsvY=
github.com/pkg/term v1.1.0 h1:xIAAdCMh3QIAy+5FrE8Ad8XoDhEU4ufwbaSozViP9kk=
github.com/pkg/term v1.1.0/go.mod h1:E25nymQcrSllhX42Ok8MRm1+hyBdHY0dCeiKZ9jpNGw=
golang.org/x/crypto v0.1.0 h1:MDRAIl0xIo9Io2xV565hzXHw3zVseKrJKodhohM5CjU=
Expand Down
5 changes: 4 additions & 1 deletion example/macOS/go.mod
Expand Up @@ -6,4 +6,7 @@ replace github.com/Code-Hex/vz/v3 => ../../

require github.com/Code-Hex/vz/v3 v3.0.0-00010101000000-000000000000

require golang.org/x/mod v0.6.0 // indirect
require (
github.com/Code-Hex/go-infinity-channel v1.0.0 // indirect
golang.org/x/mod v0.6.0 // indirect
)
2 changes: 2 additions & 0 deletions example/macOS/go.sum
@@ -1,3 +1,5 @@
github.com/Code-Hex/go-infinity-channel v1.0.0 h1:M8BWlfDOxq9or9yvF9+YkceoTkDI1pFAqvnP87Zh0Nw=
github.com/Code-Hex/go-infinity-channel v1.0.0/go.mod h1:5yUVg/Fqao9dAjcpzoQ33WwfdMWmISOrQloDRn3bsvY=
golang.org/x/crypto v0.1.0 h1:MDRAIl0xIo9Io2xV565hzXHw3zVseKrJKodhohM5CjU=
golang.org/x/mod v0.6.0 h1:b9gGHsz9/HhJ3HF5DHQytPpuwocVTChQJK3AvoLRD5I=
golang.org/x/mod v0.6.0/go.mod h1:4mET923SAdbXp2ki8ey+zGs1SLqsuM2Y0uvdZR/fUNI=
Expand Down
1 change: 1 addition & 0 deletions go.mod
Expand Up @@ -3,6 +3,7 @@ module github.com/Code-Hex/vz/v3
go 1.19

require (
github.com/Code-Hex/go-infinity-channel v1.0.0
golang.org/x/crypto v0.1.0
golang.org/x/mod v0.6.0
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
@@ -1,3 +1,5 @@
github.com/Code-Hex/go-infinity-channel v1.0.0 h1:M8BWlfDOxq9or9yvF9+YkceoTkDI1pFAqvnP87Zh0Nw=
github.com/Code-Hex/go-infinity-channel v1.0.0/go.mod h1:5yUVg/Fqao9dAjcpzoQ33WwfdMWmISOrQloDRn3bsvY=
golang.org/x/crypto v0.1.0 h1:MDRAIl0xIo9Io2xV565hzXHw3zVseKrJKodhohM5CjU=
golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw=
golang.org/x/mod v0.6.0 h1:b9gGHsz9/HhJ3HF5DHQytPpuwocVTChQJK3AvoLRD5I=
Expand Down
10 changes: 5 additions & 5 deletions virtualization.go
Expand Up @@ -13,6 +13,7 @@ import (
"sync"
"unsafe"

infinity "github.com/Code-Hex/go-infinity-channel"
"github.com/Code-Hex/vz/v3/internal/objc"
)

Expand Down Expand Up @@ -81,7 +82,7 @@ type VirtualMachine struct {

type machineState struct {
state VirtualMachineState
stateNotify chan VirtualMachineState
stateNotify *infinity.Channel[VirtualMachineState]

mu sync.RWMutex
}
Expand All @@ -104,7 +105,7 @@ func NewVirtualMachine(config *VirtualMachineConfiguration) (*VirtualMachine, er

stateHandle := cgo.NewHandle(&machineState{
state: VirtualMachineState(0),
stateNotify: make(chan VirtualMachineState),
stateNotify: infinity.NewChannel[VirtualMachineState](),
})

v := &VirtualMachine{
Expand Down Expand Up @@ -160,8 +161,7 @@ func changeStateOnObserver(newStateRaw C.int, cgoHandlerPtr unsafe.Pointer) {
v.mu.Lock()
newState := VirtualMachineState(newStateRaw)
v.state = newState
// for non-blocking
go func() { v.stateNotify <- newState }()
v.stateNotify.In() <- newState
v.mu.Unlock()
}

Expand All @@ -188,7 +188,7 @@ func (v *VirtualMachine) StateChangedNotify() <-chan VirtualMachineState {
val, _ := v.stateHandle.Value().(*machineState)
val.mu.RLock()
defer val.mu.RUnlock()
return val.stateNotify
return val.stateNotify.Out()
}

// CanStart returns true if the machine is in a state that can be started.
Expand Down

0 comments on commit 6c8b0b0

Please sign in to comment.