Skip to content

Commit

Permalink
Simplify stateStore api
Browse files Browse the repository at this point in the history
  • Loading branch information
zhulik committed Aug 7, 2024
1 parent 6f56437 commit 2176eb3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
8 changes: 3 additions & 5 deletions gruby.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,14 @@ type ArenaIndex int
// When you're finished with the VM, clean up all resources it is using
// by calling the Close method.
func New() *GRuby {
state := C.mrb_open()

grb := &GRuby{
state: state,
state: C.mrb_open(),
loadedFiles: map[string]bool{},
classes: classMethodMap{},
getArgAccumulator: make([]C.mrb_value, 0, C._go_get_max_funcall_args()),
}

states.Add(state, grb)
states.Add(grb)

return grb
}
Expand Down Expand Up @@ -152,7 +150,7 @@ func (g *GRuby) Module(name string) *Class {
// Close a Gruby, this must be called to properly free resources, and
// should only be called once.
func (g *GRuby) Close() {
states.Delete(g.state)
states.Delete(g)
C.mrb_close(g.state)
}

Expand Down
8 changes: 4 additions & 4 deletions states.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ type stateStore struct {
lock sync.RWMutex
}

func (s *stateStore) Add(state *C.mrb_state, grb *GRuby) {
func (s *stateStore) Add(grb *GRuby) {
s.lock.Lock()
defer s.lock.Unlock()

s.states[state] = grb
s.states[grb.state] = grb
}

func (s *stateStore) Delete(state *C.mrb_state) {
func (s *stateStore) Delete(grb *GRuby) {
s.lock.Lock()
defer s.lock.Unlock()
delete(s.states, state)
delete(s.states, grb.state)
}

func (s *stateStore) Get(state *C.mrb_state) *GRuby {
Expand Down

0 comments on commit 2176eb3

Please sign in to comment.