mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-11-15 16:56:08 -05:00
71 lines
1.1 KiB
Go
71 lines
1.1 KiB
Go
package core
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"v2ray.com/core/features/stats"
|
|
)
|
|
|
|
type syncStatManager struct {
|
|
sync.RWMutex
|
|
stats.Manager
|
|
}
|
|
|
|
func (*syncStatManager) Type() interface{} {
|
|
return stats.ManagerType()
|
|
}
|
|
|
|
func (s *syncStatManager) Start() error {
|
|
s.RLock()
|
|
defer s.RUnlock()
|
|
|
|
if s.Manager == nil {
|
|
return nil
|
|
}
|
|
|
|
return s.Manager.Start()
|
|
}
|
|
|
|
func (s *syncStatManager) Close() error {
|
|
s.RLock()
|
|
defer s.RUnlock()
|
|
|
|
if s.Manager == nil {
|
|
return nil
|
|
}
|
|
return s.Manager.Close()
|
|
}
|
|
|
|
func (s *syncStatManager) RegisterCounter(name string) (stats.Counter, error) {
|
|
s.RLock()
|
|
defer s.RUnlock()
|
|
|
|
if s.Manager == nil {
|
|
return nil, newError("StatManager not set.")
|
|
}
|
|
return s.Manager.RegisterCounter(name)
|
|
}
|
|
|
|
func (s *syncStatManager) GetCounter(name string) stats.Counter {
|
|
s.RLock()
|
|
defer s.RUnlock()
|
|
|
|
if s.Manager == nil {
|
|
return nil
|
|
}
|
|
return s.Manager.GetCounter(name)
|
|
}
|
|
|
|
func (s *syncStatManager) Set(m stats.Manager) {
|
|
if m == nil {
|
|
return
|
|
}
|
|
s.Lock()
|
|
defer s.Unlock()
|
|
|
|
if s.Manager != nil {
|
|
s.Manager.Close() // nolint: errcheck
|
|
}
|
|
s.Manager = m
|
|
}
|