forked from TruthHun/BookStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlock.go
More file actions
36 lines (30 loc) · 679 Bytes
/
lock.go
File metadata and controls
36 lines (30 loc) · 679 Bytes
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
package utils
import "sync"
var (
BooksRelease = BooksLock{Books: make(map[int]bool)}
BooksGenerate = BooksLock{Books: make(map[int]bool)}
)
//书籍发布锁和书籍离线文档生成锁
type BooksLock struct {
Books map[int]bool
Lock sync.RWMutex
}
//查询是否存在
func (this BooksLock) Exist(bookId int) (exist bool) {
this.Lock.RLock()
defer this.Lock.RUnlock()
_, exist = this.Books[bookId]
return
}
//设置
func (this BooksLock) Set(bookId int) {
this.Lock.RLock()
defer this.Lock.RUnlock()
this.Books[bookId] = true
}
//删除
func (this BooksLock) Delete(bookId int) {
this.Lock.RLock()
defer this.Lock.RUnlock()
delete(this.Books, bookId)
}