//this is an example of using gpg to define an auto-lock globalvalue with generic type
//it will be realized to real go code by gpg tool through the .gpgfile with the same name
package example
"sync"
)
type AutoLockGbl struct {
val
lock sync.RWMutex
}
func New(val ) *AutoLockGbl{
p := &AutoLockGbl{}
p.val = val
return p
}
func (me *AutoLockGbl) Get() (r ) {
me.lock.RLock()
defer me.lock.RUnlock()
r = me.val
return
}
func (me *AutoLockGbl) Set(val ) (r ) {
me.lock.Lock()
defer me.lock.Unlock()
r = me.val
me.val = val
return
}
;it is used to generate code from .gp file
[int]
TYPE_NAME=Int
VALUE_TYPE=int
LOCK_COMMENT=
TYPE_NAME=ConstStr
VALUE_TYPE=string
LOCK_COMMENT=//
TYPE_NAME=ConstU64
VALUE_TYPE=uint64
LOCK_COMMENT=//
// Last modify at: 2014-01-21 13:06:46.6378366 +0800 +0800
// !!!!!!!!!NEVER MODIFY IT MANUALLY!!!!!!!!!
//Version: 1.0.0
//Author: [email protected]
//Blog site: http://blog.sina.com.cn/ally2014
//this is an example of using gpg to define an auto-lock globalvalue with generic type
//it will be realized to real go code by gpg tool through the .gpgfile with the same name
package example
"sync"
)
type AutoLockGblInt struct {
val int
lock sync.RWMutex
}
func NewInt(val int) *AutoLockGblInt{
p := &AutoLockGblInt{}
p.val = val
return p
}
func (me *AutoLockGblInt) Get() (r int) {
me.lock.RLock()
defer me.lock.RUnlock()
r = me.val
return
}
func (me *AutoLockGblInt) Set(val int) (r int) {
me.lock.Lock()
defer me.lock.Unlock()
r = me.val
me.val = val
return
}
// Last modify at: 2014-01-21 13:06:46.6408372 +0800 +0800
// !!!!!!!!!NEVER MODIFY IT MANUALLY!!!!!!!!!
//Version: 1.0.0
//Author: [email protected]
//Blog site: http://blog.sina.com.cn/ally2014
//this is an example of using gpg to define an auto-lock globalvalue with generic type
//it will be realized to real go code by gpg tool through the .gpgfile with the same name
package example
//"sync"
)
type AutoLockGblConstStr struct {
val string
//lock sync.RWMutex
}
func NewConstStr(val string) *AutoLockGblConstStr{
p := &AutoLockGblConstStr{}
p.val = val
return p
}
func (me *AutoLockGblConstStr) Get() (r string) {
// me.lock.RLock()
// defer me.lock.RUnlock()
r = me.val
return
}
//func (me *AutoLockGblConstStr) Set(val string) (r string) {
// me.lock.Lock()
// defer me.lock.Unlock()
// r = me.val
// me.val = val
// return
//}