kunt

golang IRC bot
git clone git://git.2f30.org/kunt
Log | Files | Refs | LICENSE

commit e1c4909c9cdee460a92d6c4b98b5fc2ea293f121
parent 103e5d65ba25359b8a4b5018be16529a5ea3685e
Author: sin <sin@2f30.org>
Date:   Fri, 26 Apr 2013 16:52:55 +0100

fsdb: Add some comments, ensure lock is taken in Len()

Diffstat:
Msrc/fsdb/fsdb.go | 4+++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/fsdb/fsdb.go b/src/fsdb/fsdb.go @@ -122,6 +122,7 @@ func (d *Fsdb) Load() error { } // Check if `buf' already exists in the DB +// Expects `d.lock' to be held by caller func (d *Fsdb) dup(buf []byte) bool { for _, v := range d.dbMap { if string(v.data) == string(buf) { @@ -172,7 +173,6 @@ func (d *Fsdb) Get(key int) ([]byte, error) { func (d *Fsdb) Rand() ([]byte, int) { d.lock.Lock() defer d.lock.Unlock() - idx := rand.Intn(len(d.dbMap)) i := 0 for k, _ := range d.dbMap { @@ -195,5 +195,7 @@ func (d *Fsdb) Empty() bool { } func (d *Fsdb) Len() int { + d.lock.Lock() + defer d.lock.Unlock() return len(d.dbMap) }