Skip to content

Commit

Permalink
Add lock to gomod.go
Browse files Browse the repository at this point in the history
Protect goModule from multiple simultaneous initialisations.
  • Loading branch information
qur committed Jun 2, 2012
1 parent 00263cf commit bfc0dbd
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/gomod.go
Expand Up @@ -7,8 +7,12 @@ package py
// #include "utils.h"
import "C"

// TODO: needs lock
var goModule *Module
import "sync"

var (
goModLock sync.Mutex
goModule *Module
)

// InitGoModules initializes (and returns) the special built-in "go" module.
// This module exports go specific items to Python that can be accessed by
Expand All @@ -19,6 +23,9 @@ var goModule *Module
// This function may be called more than once to get at the *Module, the module
// will only be created and initialized once.
func InitGoModule() (*Module, error) {
goModLock.Lock()
defer goModLock.Unlock()

if goModule != nil {
return goModule, nil
}
Expand Down

0 comments on commit bfc0dbd

Please sign in to comment.