re-check in write lock on hash of mutexes for collections
This commit is contained in:
parent
be900ca877
commit
8308b199f7
11
scribble.go
11
scribble.go
|
@ -40,13 +40,12 @@ type (
|
|||
func New(dir string, logger hatchet.Logger) (*Driver, error) {
|
||||
dir = filepath.Clean(dir)
|
||||
|
||||
fmt.Printf("Creating database directory at '%v'...\n", dir)
|
||||
|
||||
//
|
||||
if logger == nil {
|
||||
logger = hatchet.DevNullLogger{}
|
||||
}
|
||||
|
||||
logger.Info("Creating database directory at '%v'...\n", dir)
|
||||
|
||||
//
|
||||
d := &Driver{
|
||||
dir: dir,
|
||||
|
@ -218,8 +217,10 @@ func (d *Driver) getOrCreateMutex(collection string) sync.Mutex {
|
|||
if !ok {
|
||||
|
||||
d.maplock.Lock()
|
||||
c = sync.Mutex{}
|
||||
d.mutexes[collection] = c
|
||||
if c, ok = d.mutexes[collection]; !ok {
|
||||
c = sync.Mutex{}
|
||||
d.mutexes[collection] = c
|
||||
}
|
||||
d.maplock.Unlock()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue