diff --git a/g/container/gtype/bool.go b/g/container/gtype/bool.go index 4ba580fdd..a6efdd321 100644 --- a/g/container/gtype/bool.go +++ b/g/container/gtype/bool.go @@ -34,6 +34,6 @@ func (t *Bool)Set(value bool) { } } -func (t *Bool)Get() bool { +func (t *Bool)Val() bool { return atomic.LoadInt32(&t.val) > 0 } diff --git a/g/container/gtype/bytes.go b/g/container/gtype/bytes.go index 8d07ad113..dc266f59e 100644 --- a/g/container/gtype/bytes.go +++ b/g/container/gtype/bytes.go @@ -28,7 +28,7 @@ func (t *Bytes)Set(value []byte) { t.mu.Unlock() } -func (t *Bytes)Get() []byte { +func (t *Bytes)Val() []byte { t.mu.RLock() b := t.val t.mu.RUnlock() diff --git a/g/container/gtype/float32.go b/g/container/gtype/float32.go index d65e8de3b..5f7d70080 100644 --- a/g/container/gtype/float32.go +++ b/g/container/gtype/float32.go @@ -25,7 +25,7 @@ func (t *Float32)Set(value float32) { atomic.StoreUint32(&t.val, uint32(value)) } -func (t *Float32)Get() int { +func (t *Float32)Val() int { return int(atomic.LoadUint32(&t.val)) } diff --git a/g/container/gtype/float64.go b/g/container/gtype/float64.go index 4959eef67..e1f82a01a 100644 --- a/g/container/gtype/float64.go +++ b/g/container/gtype/float64.go @@ -25,7 +25,7 @@ func (t *Float64)Set(value float32) { atomic.StoreUint64(&t.val, uint64(value)) } -func (t *Float64)Get() int { +func (t *Float64)Val() int { return int(atomic.LoadUint64(&t.val)) } diff --git a/g/container/gtype/gtype_test.go b/g/container/gtype/gtype_test.go index f62a9ee5b..60ac15fac 100644 --- a/g/container/gtype/gtype_test.go +++ b/g/container/gtype/gtype_test.go @@ -34,7 +34,7 @@ func BenchmarkInt_Set(b *testing.B) { func BenchmarkInt_Get(b *testing.B) { for i := 0; i < b.N; i++ { - it.Get() + it.Val() } } @@ -52,7 +52,7 @@ func BenchmarkInt32_Set(b *testing.B) { func BenchmarkInt32_Get(b *testing.B) { for i := int32(0); i < int32(b.N); i++ { - it32.Get() + it32.Val() } } @@ -70,7 +70,7 @@ func BenchmarkInt64_Set(b *testing.B) { func BenchmarkInt64_Get(b *testing.B) { for i := int64(0); i < int64(b.N); i++ { - it64.Get() + it64.Val() } } @@ -90,7 +90,7 @@ func BenchmarkUint_Set(b *testing.B) { func BenchmarkUint_Get(b *testing.B) { for i := uint(0); i < uint(b.N); i++ { - uit.Get() + uit.Val() } } @@ -110,7 +110,7 @@ func BenchmarkUint32_Set(b *testing.B) { func BenchmarkUint32_Get(b *testing.B) { for i := uint32(0); i < uint32(b.N); i++ { - uit32.Get() + uit32.Val() } } @@ -129,7 +129,7 @@ func BenchmarkUint64_Set(b *testing.B) { func BenchmarkUint64_Get(b *testing.B) { for i := uint64(0); i < uint64(b.N); i++ { - uit64.Get() + uit64.Val() } } @@ -149,7 +149,7 @@ func BenchmarkBool_Set(b *testing.B) { func BenchmarkBool_Get(b *testing.B) { for i := 0; i < b.N; i++ { - bl.Get() + bl.Val() } } @@ -163,7 +163,7 @@ func BenchmarkString_Set(b *testing.B) { func BenchmarkString_Get(b *testing.B) { for i := 0; i < b.N; i++ { - str.Get() + str.Val() } } @@ -177,7 +177,7 @@ func BenchmarkBytes_Set(b *testing.B) { func BenchmarkBytes_Get(b *testing.B) { for i := 0; i < b.N; i++ { - bytes.Get() + bytes.Val() } } @@ -190,7 +190,7 @@ func BenchmarkInterface_Set(b *testing.B) { func BenchmarkInterface_Get(b *testing.B) { for i := 0; i < b.N; i++ { - inf.Get() + inf.Val() } } diff --git a/g/container/gtype/int.go b/g/container/gtype/int.go index ffd0ce041..47d06deed 100644 --- a/g/container/gtype/int.go +++ b/g/container/gtype/int.go @@ -25,7 +25,7 @@ func (t *Int)Set(value int) { atomic.StoreInt64(&t.val, int64(value)) } -func (t *Int)Get() int { +func (t *Int)Val() int { return int(atomic.LoadInt64(&t.val)) } diff --git a/g/container/gtype/int32.go b/g/container/gtype/int32.go index fac7d1081..aa764a940 100644 --- a/g/container/gtype/int32.go +++ b/g/container/gtype/int32.go @@ -25,7 +25,7 @@ func (t *Int32)Set(value int32) { atomic.StoreInt32(&t.val, value) } -func (t *Int32)Get() int32 { +func (t *Int32)Val() int32 { return atomic.LoadInt32(&t.val) } diff --git a/g/container/gtype/int64.go b/g/container/gtype/int64.go index 35b24f5e2..cd1d636a3 100644 --- a/g/container/gtype/int64.go +++ b/g/container/gtype/int64.go @@ -25,7 +25,7 @@ func (t *Int64)Set(value int64) { atomic.StoreInt64(&t.val, value) } -func (t *Int64)Get() int64 { +func (t *Int64)Val() int64 { return atomic.LoadInt64(&t.val) } diff --git a/g/container/gtype/interface.go b/g/container/gtype/interface.go index 6d2e7ca0f..2be0dd676 100644 --- a/g/container/gtype/interface.go +++ b/g/container/gtype/interface.go @@ -28,7 +28,7 @@ func (t *Interface)Set(value interface{}) { t.mu.Unlock() } -func (t *Interface)Get() interface{} { +func (t *Interface)Val() interface{} { t.mu.RLock() b := t.val t.mu.RUnlock() diff --git a/g/container/gtype/string.go b/g/container/gtype/string.go index a4fddc837..03a573688 100644 --- a/g/container/gtype/string.go +++ b/g/container/gtype/string.go @@ -28,7 +28,7 @@ func (t *String)Set(value string) { t.mu.Unlock() } -func (t *String)Get() string { +func (t *String)Val() string { t.mu.RLock() s := t.val t.mu.RUnlock() diff --git a/g/container/gtype/uint.go b/g/container/gtype/uint.go index 5b9e75096..533025226 100644 --- a/g/container/gtype/uint.go +++ b/g/container/gtype/uint.go @@ -25,7 +25,7 @@ func (t *Uint)Set(value uint) { atomic.StoreUint64(&t.val, uint64(value)) } -func (t *Uint)Get() uint { +func (t *Uint)Val() uint { return uint(atomic.LoadUint64(&t.val)) } diff --git a/g/container/gtype/uint32.go b/g/container/gtype/uint32.go index acf575eaf..5eedf5c34 100644 --- a/g/container/gtype/uint32.go +++ b/g/container/gtype/uint32.go @@ -25,7 +25,7 @@ func (t *Uint32)Set(value uint32) { atomic.StoreUint32(&t.val, value) } -func (t *Uint32)Get() uint32 { +func (t *Uint32)Val() uint32 { return atomic.LoadUint32(&t.val) } diff --git a/g/container/gtype/uint64.go b/g/container/gtype/uint64.go index a62e528fc..0a0966c93 100644 --- a/g/container/gtype/uint64.go +++ b/g/container/gtype/uint64.go @@ -25,7 +25,7 @@ func (t *Uint64)Set(value uint64) { atomic.StoreUint64(&t.val, value) } -func (t *Uint64)Get() uint64 { +func (t *Uint64)Val() uint64 { return atomic.LoadUint64(&t.val) } diff --git a/g/os/gcache/gcache.go b/g/os/gcache/gcache.go index bbc4ad61f..7d05aca72 100644 --- a/g/os/gcache/gcache.go +++ b/g/os/gcache/gcache.go @@ -292,8 +292,8 @@ func (c *Cache) autoClearLoop() { c.smu.Unlock() } // LRU缓存淘汰处理 - if c.cap.Get() > 0 { - for i := c.Size() - c.cap.Get(); i > 0; i-- { + if c.cap.Val() > 0 { + for i := c.Size() - c.cap.Val(); i > 0; i-- { if s := c.lru.Pop(); s != "" { c.clearByKey(s) }