1 Star 0 Fork 0

秋来冬风/gtl

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
GLMstackpp.go 1.22 KB
一键复制 编辑 原始数据 按行查看 历史
秋来冬风 提交于 2年前 . 秋来冬风:gofmt
// GLMstackpp
package stack
import (
"sync/atomic"
"time"
)
// 记录为入栈时操作
func (s *GLMstack) pushrecord() {
atomic.AddInt64(&s.pushn, 1)
for {
rw := atomic.LoadInt64(&s.pp)
if rw == pushpp { //正在入栈操作
return
} else if rw == 0 {
bol := atomic.CompareAndSwapInt64(&s.pp, 0, pushpp)
if bol == true { //无操作
return
} else { //正在出栈操作
time.Sleep(time.Duration(s.poptime * s.popn))
}
} else { //正在出栈操作
time.Sleep(time.Duration(s.poptime * s.popn))
}
}
}
// 入栈已完成
func (s *GLMstack) pushok() {
n := atomic.AddInt64(&s.pushn, -1)
if n == 0 {
atomic.StoreInt64(&s.pp, 0)
}
}
// 出栈已完成
func (s *GLMstack) popok() {
n := atomic.AddInt64(&s.popn, -1)
if n == 0 {
atomic.StoreInt64(&s.pp, 0)
}
}
// 记录为出栈时操作
func (s *GLMstack) poprecord() {
atomic.AddInt64(&s.popn, 1)
for {
rw := atomic.LoadInt64(&s.pp)
if rw == poppp { //正在出栈操作
return
} else if rw == 0 {
bol := atomic.CompareAndSwapInt64(&s.pp, 0, poppp)
if bol == true { //无操作
return
} else {
time.Sleep(time.Duration(s.pushtime * s.pushn))
}
} else {
time.Sleep(time.Duration(s.pushtime * s.pushn))
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/qiulaidongfeng/gtl.git
git@gitee.com:qiulaidongfeng/gtl.git
qiulaidongfeng
gtl
gtl
044be384fdfd

搜索帮助