-
Notifications
You must be signed in to change notification settings - Fork 21
/
collector_sync.go
53 lines (41 loc) · 970 Bytes
/
collector_sync.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package ftdc
import (
"sync"
)
type synchronizedCollector struct {
Collector
mu sync.RWMutex
}
// NewSynchronizedCollector wraps an existing collector in a
// synchronized wrapper that guards against incorrect concurrent
// access.
func NewSynchronizedCollector(coll Collector) Collector {
return &synchronizedCollector{
Collector: coll,
}
}
func (c *synchronizedCollector) Add(in interface{}) error {
c.mu.Lock()
defer c.mu.Unlock()
return c.Collector.Add(in)
}
func (c *synchronizedCollector) SetMetadata(in interface{}) error {
c.mu.Lock()
defer c.mu.Unlock()
return c.Collector.SetMetadata(in)
}
func (c *synchronizedCollector) Resolve() ([]byte, error) {
c.mu.Lock()
defer c.mu.Unlock()
return c.Collector.Resolve()
}
func (c *synchronizedCollector) Reset() {
c.mu.Lock()
defer c.mu.Unlock()
c.Collector.Reset()
}
func (c *synchronizedCollector) Info() CollectorInfo {
c.mu.RLock()
defer c.mu.RUnlock()
return c.Collector.Info()
}