1 Star 0 Fork 0

魔山/utils

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
concurrentlist.go 1.22 KB
一键复制 编辑 原始数据 按行查看 历史
魔山 提交于 2022-03-09 10:14 +08:00 . 1
package concurrent
import (
"container/list"
"sync"
)
type ConcurrentList struct {
list *list.List
mutex sync.Mutex
}
func New() *ConcurrentList {
return &ConcurrentList{list: list.New()}
}
func (c *ConcurrentList) Front() *list.Element {
return c.list.Front()
}
func (c *ConcurrentList) Back() *list.Element {
return c.list.Back()
}
func (c *ConcurrentList) MoveToFront(e *list.Element) {
c.mutex.Lock()
defer c.mutex.Unlock()
c.list.MoveToFront(e)
}
func (c *ConcurrentList) MoveToBack(e *list.Element) {
c.mutex.Lock()
defer c.mutex.Unlock()
c.list.MoveToBack(e)
}
func (c *ConcurrentList) MoveAfter(e *list.Element, mark *list.Element) {
c.mutex.Lock()
defer c.mutex.Unlock()
c.list.MoveAfter(e, mark)
}
func (c *ConcurrentList) InsertAfter(v interface{}, mark *list.Element) {
c.mutex.Lock()
defer c.mutex.Unlock()
c.list.InsertAfter(v, mark)
}
func (c *ConcurrentList) InsertBefore(v interface{}, mark *list.Element) {
c.mutex.Lock()
defer c.mutex.Unlock()
c.list.InsertBefore(v, mark)
}
func (c *ConcurrentList) PushFront(v interface{}) {
c.mutex.Lock()
defer c.mutex.Unlock()
c.list.PushFront(v)
}
func (c *ConcurrentList) Remove(e *list.Element) {
c.mutex.Lock()
defer c.mutex.Unlock()
c.list.Remove(e)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/magic-mountain/utils.git
git@gitee.com:magic-mountain/utils.git
magic-mountain
utils
utils
baecc60c2fce

搜索帮助