re-check in write lock on hash of mutexes for collections

This commit is contained in:
Chris Holland 2015-10-13 08:45:43 -07:00
parent be900ca877
commit 8308b199f7
1 changed files with 6 additions and 5 deletions

View File

@ -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()
}