| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- package redpoint
- import (
- "bet24.com/log"
- "sync"
- )
- type redpointmgr struct {
- lock *sync.RWMutex
- user_list map[int]*user_redPoint
- }
- func newRedpointMgr() *redpointmgr {
- ret := new(redpointmgr)
- ret.lock = &sync.RWMutex{}
- ret.user_list = make(map[int]*user_redPoint)
- log.Debug("redpoint manager running")
- return ret
- }
- func (this *redpointmgr) check(userId int) *redPoint {
- user := this.getUser(userId)
- if user == nil {
- log.Debug("redpointmgr.check userId[%d] is not exist", userId)
- return nil
- }
- return user.check()
- }
- func (this *redpointmgr) getUser(userId int) *user_redPoint {
- this.lock.RLock()
- user, ok := this.user_list[userId]
- this.lock.RUnlock()
- if !ok {
- user = newUserRedpoint(userId)
- if user == nil {
- return nil
- }
- this.lock.Lock()
- this.user_list[userId] = user
- this.lock.Unlock()
- }
- return user
- }
- func (this *redpointmgr) onUserEnter(userId int) {
- this.lock.Lock()
- defer this.lock.Unlock()
- _, ok := this.user_list[userId]
- if !ok {
- this.user_list[userId] = newUserRedpoint(userId)
- }
- }
- func (this *redpointmgr) onUserExit(userId int) {
- this.lock.Lock()
- defer this.lock.Unlock()
- u, _ := this.user_list[userId]
- if u != nil {
- u.destructor()
- delete(this.user_list, userId)
- }
- }
- func (this *redpointmgr) dump(param string) {
- log.Release("-------------------------------")
- log.Release("redpointmgr.dump")
- defer func() {
- log.Release("+++++++++++++++++++++++++++++++")
- log.Release("")
- }()
- this.lock.RLock()
- log.Release(" total user count[%d]", len(this.user_list))
- for k, v := range this.user_list {
- log.Release(" %d,userId[%d],counter[%d]", k, v.userId, v.counter)
- }
- this.lock.RUnlock()
- }
|