-
Notifications
You must be signed in to change notification settings - Fork 2
/
mutex.go
90 lines (74 loc) · 1.57 KB
/
mutex.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package main
import (
"sync"
"golang.org/x/net/html"
)
type DocPage struct {
sync.RWMutex
doc *html.Node
docStr string
}
func (docPage *DocPage) GetPage() *html.Node {
docPage.RLock()
defer docPage.RUnlock()
return docPage.doc
}
func (docPage *DocPage) SetPage(doc *html.Node) {
docPage.Lock()
docPage.doc = doc
docPage.Unlock()
}
func (docPage *DocPage) GetStrPage() string {
docPage.RLock()
defer docPage.RUnlock()
return docPage.docStr
}
func (docPage *DocPage) SetStrPage(docStr string) {
docPage.Lock()
docPage.docStr = docStr
docPage.Unlock()
}
type LoginCreds struct {
sync.RWMutex
username string
password string
}
func (loginCreds *LoginCreds) GetCreds() (string, string) {
loginCreds.RLock()
defer loginCreds.RUnlock()
return loginCreds.username, loginCreds.password
}
func (loginCreds *LoginCreds) SetCreds(username string, password string) {
loginCreds.Lock()
loginCreds.username = username
loginCreds.password = password
loginCreds.Unlock()
}
type GlobalFlag struct {
sync.RWMutex
flag bool
}
func (flag *GlobalFlag) GetFlag() bool {
flag.RLock()
defer flag.RUnlock()
return flag.flag
}
func (flag *GlobalFlag) SetFlag(flagVal bool) {
flag.Lock()
flag.flag = flagVal
flag.Unlock()
}
type CachedStat struct {
sync.RWMutex
stat *DeviceStats
}
func (stat *CachedStat) GetStat() *DeviceStats {
stat.RLock()
defer stat.RUnlock()
return stat.stat
}
func (stat *CachedStat) SetStat(statVal *DeviceStats) {
stat.Lock()
stat.stat = statVal
stat.Unlock()
}