Skip to content

Commit

Permalink
snes: walk back the ExclusiveUse to just Use and avoid double-lock pr…
Browse files Browse the repository at this point in the history
…oblems
  • Loading branch information
JamesDunne committed Jun 16, 2021
1 parent 753fa18 commit 1967e1c
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 16 deletions.
2 changes: 1 addition & 1 deletion snes/basedriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (b *BaseDeviceDriver) UseDevice(
b.devicesRw.Unlock()
}

err = device.ExclusiveUse(ctx, use)
err = device.Use(ctx, use)

if device.IsClosed() {
b.devicesRw.Lock()
Expand Down
4 changes: 2 additions & 2 deletions snes/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ type DeviceMemoryUser func(context context.Context, memory DeviceMemory) error
type Device interface {
IsClosed() bool

// ExclusiveUse provides exclusive access to the entire device to the user func
ExclusiveUse(ctx context.Context, user DeviceUser) error
// Use provides non-exclusive access to the device's subsystems to the user func
Use(ctx context.Context, user DeviceUser) error

// UseMemory provides exclusive access to only the memory subsystem of the device to the user func
UseMemory(ctx context.Context, user DeviceMemoryUser) error
Expand Down
2 changes: 1 addition & 1 deletion snes/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type DeviceUser func(context.Context, Device) error
type DeviceDriver interface {
DeviceKey(uri *url.URL) string

// UseDevice grants exclusive access for DeviceUser to a Device uniquely identified by its uri
// UseDevice grants non-exclusive access for DeviceUser to a Device uniquely identified by its uri
UseDevice(ctx context.Context, uri *url.URL, user DeviceUser) error
}

Expand Down
5 changes: 1 addition & 4 deletions snes/fxpakpro/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@ func (d *Device) IsClosed() bool {
return d.isClosed
}

func (d *Device) ExclusiveUse(ctx context.Context, user snes.DeviceUser) error {
func (d *Device) Use(ctx context.Context, user snes.DeviceUser) error {
if user == nil {
return nil
}

defer d.lock.Unlock()
d.lock.Lock()

return user(ctx, d)
}

Expand Down
5 changes: 1 addition & 4 deletions snes/mock/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,11 @@ func (d *Device) IsClosed() bool {
return false
}

func (d *Device) ExclusiveUse(context context.Context, user snes.DeviceUser) error {
func (d *Device) Use(context context.Context, user snes.DeviceUser) error {
if user == nil {
return nil
}

defer d.lock.Unlock()
d.lock.Lock()

return user(context, d)
}

Expand Down
5 changes: 1 addition & 4 deletions snes/retroarch/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,11 @@ func (d *Device) IsClosed() bool {
return d.c.IsClosed()
}

func (d *Device) ExclusiveUse(ctx context.Context, user snes.DeviceUser) error {
func (d *Device) Use(ctx context.Context, user snes.DeviceUser) error {
if user == nil {
return nil
}

defer d.lock.Unlock()
d.lock.Lock()

return user(ctx, d)
}

Expand Down

0 comments on commit 1967e1c

Please sign in to comment.