cubefs

Форк
0
/
synclist.go 
122 строки · 2.5 Кб
1
// Copyright 2018 The CubeFS Authors.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12
// implied. See the License for the specific language governing
13
// permissions and limitations under the License.
14

15
package synclist
16

17
import (
18
	"container/list"
19
	"sync"
20
)
21

22
type SyncList struct {
23
	list.List
24
	mu sync.RWMutex
25
}
26

27
func New() *SyncList {
28
	l := new(SyncList)
29
	l.Init()
30
	return l
31
}
32

33
func (l *SyncList) Init() *SyncList {
34
	l.mu.Lock()
35
	l.List.Init()
36
	l.mu.Unlock()
37
	return l
38
}
39

40
func (l *SyncList) Remove(e *list.Element) interface{} {
41
	l.mu.Lock()
42
	defer l.mu.Unlock()
43
	return l.List.Remove(e)
44
}
45

46
func (l *SyncList) PushFront(v interface{}) *list.Element {
47
	l.mu.Lock()
48
	defer l.mu.Unlock()
49
	return l.List.PushFront(v)
50
}
51

52
func (l *SyncList) Back() *list.Element {
53
	l.mu.RLock()
54
	defer l.mu.RUnlock()
55
	return l.List.Back()
56
}
57

58
func (l *SyncList) PushBack(v interface{}) *list.Element {
59
	l.mu.Lock()
60
	defer l.mu.Unlock()
61
	return l.List.PushBack(v)
62
}
63

64
func (l *SyncList) InsertBefore(v interface{}, mark *list.Element) *list.Element {
65
	l.mu.Lock()
66
	defer l.mu.Unlock()
67
	return l.List.InsertBefore(v, mark)
68
}
69

70
func (l *SyncList) InsertAfter(v interface{}, mark *list.Element) *list.Element {
71
	l.mu.Lock()
72
	defer l.mu.Unlock()
73
	return l.List.InsertAfter(v, mark)
74
}
75

76
func (l *SyncList) Len() int {
77
	l.mu.RLock()
78
	defer l.mu.RUnlock()
79
	return l.List.Len()
80
}
81

82
func (l *SyncList) Front() *list.Element {
83
	l.mu.RLock()
84
	defer l.mu.RUnlock()
85
	return l.List.Front()
86
}
87

88
func (l *SyncList) MoveToFront(e *list.Element) {
89
	l.mu.Lock()
90
	l.List.MoveToFront(e)
91
	l.mu.Unlock()
92
}
93

94
func (l *SyncList) MoveToBack(e *list.Element) {
95
	l.mu.Lock()
96
	l.List.MoveToBack(e)
97
	l.mu.Unlock()
98
}
99

100
func (l *SyncList) MoveBefore(e, mark *list.Element) {
101
	l.mu.Lock()
102
	l.List.MoveBefore(e, mark)
103
	l.mu.Unlock()
104
}
105

106
func (l *SyncList) MoveAfter(e, mark *list.Element) {
107
	l.mu.Lock()
108
	l.List.MoveAfter(e, mark)
109
	l.mu.Unlock()
110
}
111

112
func (l *SyncList) PushBackList(other *SyncList) {
113
	l.mu.Lock()
114
	l.List.PushBackList(&other.List)
115
	l.mu.Unlock()
116
}
117

118
func (l *SyncList) PushFrontList(other *SyncList) {
119
	l.mu.Lock()
120
	l.List.PushFrontList(&other.List)
121
	l.mu.Unlock()
122
}
123

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.