Skip to content

Commit 2249bd4

Browse files
author
Yusuke Kato
authored
[patch] bugfix length counter decrement logic changed to CAS (#41)
Signed-off-by: kpango <[email protected]>
1 parent 79283f2 commit 2249bd4

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

gache.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,12 @@ func Set(key string, val interface{}) {
289289

290290
// Delete deletes value from Gache using key
291291
func (g *gache) Delete(key string) {
292-
atomic.StoreUint64(&g.l, atomic.LoadUint64(&g.l)-1)
293-
g.shards[xxhash.Sum64(*(*[]byte)(unsafe.Pointer(&key)))&mask].Delete(key)
292+
for {
293+
if v := atomic.LoadUint64((*uint64)(&g.l)); atomic.CompareAndSwapUint64((*uint64)(&g.l), v, v-1) {
294+
g.shards[xxhash.Sum64(*(*[]byte)(unsafe.Pointer(&key)))&mask].Delete(key)
295+
return
296+
}
297+
}
294298
}
295299

296300
// Delete deletes value from Gache using key

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ require (
1212
github.com/kpango/fastime v1.0.8
1313
github.com/kpango/glg v1.3.0
1414
github.com/patrickmn/go-cache v2.1.0+incompatible
15-
github.com/pierrec/lz4 v2.0.5+incompatible
1615
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6
1716
google.golang.org/appengine v1.5.0 // indirect
1817
)

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ github.com/kpango/glg v1.3.0 h1:77BWdR0kKkFloM2eSAr0A7lWvUyAIlOhj4LV5n2hrB8=
2929
github.com/kpango/glg v1.3.0/go.mod h1:7zzaAoMqvngad+sagWLjr00EQMJaqyGONdg0WYBAO3M=
3030
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
3131
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
32-
github.com/pierrec/lz4 v2.0.5+incompatible h1:2xWsjqPFWcplujydGg4WmhC/6fZqK42wMM8aXeqhl0I=
33-
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
3432
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
3533
github.com/vmihailenco/msgpack v4.0.1+incompatible h1:RMF1enSPeKTlXrXdOcqjFUElywVZjjC6pqse21bKbEU=
3634
github.com/vmihailenco/msgpack v4.0.1+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=

0 commit comments

Comments
 (0)