Skip to content

Commit

Permalink
更新 (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
guonaihong authored Feb 16, 2024
1 parent 78979b7 commit da630ca
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
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

0 comments on commit da630ca

Please sign in to comment.