Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

更新 #23

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions min_heap_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ type minHeapNode struct {
isSchedule bool // 是否是周期性任务
}

func (m *minHeapNode) Stop() {
func (m *minHeapNode) Stop() bool {
m.root.removeTimeNode(m)
return true
}
func (m *minHeapNode) Reset(d time.Duration) {
func (m *minHeapNode) Reset(d time.Duration) bool {
m.root.resetTimeNode(m, d)
return true
}

func (m *minHeapNode) Next(now time.Time) time.Time {
Expand Down
8 changes: 5 additions & 3 deletions time_wheel_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ type timeNode struct {
//
// 1和3.1状态是没有问题的
// 2和3.2状态会是没有锁保护下的操作,会有数据竞争
func (t *timeNode) Stop() {
func (t *timeNode) Stop() bool {

atomic.StoreUint32(&t.stop, haveStop)

Expand All @@ -87,14 +87,15 @@ func (t *timeNode) Stop() {
cpyList.Lock()
defer cpyList.Unlock()
if atomic.LoadUint64(&t.version) != atomic.LoadUint64(&cpyList.version) {
return
return false
}

cpyList.Del(&t.Head)
return true
}

// warning: 该函数目前没有稳定
func (t *timeNode) Reset(expire time.Duration) {
func (t *timeNode) Reset(expire time.Duration) bool {
cpyList := (*Time)(atomic.LoadPointer(&t.list))
cpyList.Lock()
defer cpyList.Unlock()
Expand All @@ -109,4 +110,5 @@ func (t *timeNode) Reset(expire time.Duration) {
t.expire = uint64(expire)

t.root.add(t, jiffies)
return true
}
4 changes: 2 additions & 2 deletions timer.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ type Timer interface {

// 停止单个定时器
type TimeNoder interface {
Stop()
Stop() bool
// 重置时间器
Reset(expire time.Duration)
Reset(expire time.Duration) bool
}

// 定时器构造函数
Expand Down
Loading