1 Star 0 Fork 0

magicianlyx / GoLog

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
status_settle.go 600 Bytes
一键复制 编辑 原始数据 按行查看 历史
magicianlyx 提交于 2022-01-24 17:45 . -
package pool
import (
"sync"
"time"
)
// 单线程状态总结(线程安全)
type StatusSettle struct {
l sync.RWMutex
status GoroutineStatus
duration time.Duration
}
func NewStatusSettle(status GoroutineStatus, duration time.Duration) *StatusSettle {
return &StatusSettle{
l: sync.RWMutex{},
status: status,
duration: duration,
}
}
func (s *StatusSettle) AddDuration(duration time.Duration) {
s.l.Lock()
defer s.l.Unlock()
s.duration += duration
}
func (s *StatusSettle) GetDuration() time.Duration {
s.l.RLock()
defer s.l.RUnlock()
return s.duration
}
Go
1
https://gitee.com/magicianlyx/GoLog.git
git@gitee.com:magicianlyx/GoLog.git
magicianlyx
GoLog
GoLog
20c45f9b998d

搜索帮助

53164aa7 5694891 3bd8fe86 5694891