You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
v2ray-core/stats.go

71 lines
1.1 KiB

7 years ago
package core
import (
"sync"
"v2ray.com/core/features/stats"
)
7 years ago
type syncStatManager struct {
sync.RWMutex
stats.Manager
7 years ago
}
func (*syncStatManager) Type() interface{} {
return stats.ManagerType()
}
7 years ago
func (s *syncStatManager) Start() error {
s.RLock()
defer s.RUnlock()
if s.Manager == nil {
return nil
7 years ago
}
return s.Manager.Start()
7 years ago
}
func (s *syncStatManager) Close() error {
s.RLock()
defer s.RUnlock()
if s.Manager == nil {
return nil
7 years ago
}
return s.Manager.Close()
7 years ago
}
func (s *syncStatManager) RegisterCounter(name string) (stats.Counter, error) {
7 years ago
s.RLock()
defer s.RUnlock()
if s.Manager == nil {
7 years ago
return nil, newError("StatManager not set.")
}
return s.Manager.RegisterCounter(name)
7 years ago
}
func (s *syncStatManager) GetCounter(name string) stats.Counter {
7 years ago
s.RLock()
defer s.RUnlock()
if s.Manager == nil {
7 years ago
return nil
}
return s.Manager.GetCounter(name)
7 years ago
}
func (s *syncStatManager) Set(m stats.Manager) {
if m == nil {
return
}
7 years ago
s.Lock()
defer s.Unlock()
if s.Manager != nil {
s.Manager.Close() // nolint: errcheck
7 years ago
}
s.Manager = m
7 years ago
}