timer

package
v0.2.16 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 19, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Stop added in v0.2.14

func Stop()

Types

type Head struct {
	Next *Head
	Prev *Head
	// contains filtered or unexported fields
}

func (*Head) Add

func (h *Head) Add(new *Head)

func (*Head) AddTail

func (h *Head) AddTail(new *Head)

func (*Head) Del

func (h *Head) Del(head *Head)

func (*Head) DelInit

func (h *Head) DelInit(pos *Head)

func (*Head) Empty

func (h *Head) Empty() bool

func (*Head) Entry

func (pos *Head) Entry(offset uintptr) unsafe.Pointer

func (*Head) FirstEntry

func (h *Head) FirstEntry(offset uintptr) unsafe.Pointer

func (*Head) FirstEntryOrNil

func (h *Head) FirstEntryOrNil(offset uintptr) unsafe.Pointer

func (*Head) ForEach

func (h *Head) ForEach(callback func(pos *Head))

func (*Head) ForEachPrev

func (h *Head) ForEachPrev(callback func(pos *Head))

func (*Head) ForEachPrevSafe

func (h *Head) ForEachPrevSafe(callback func(pos *Head))

func (*Head) ForEachSafe

func (h *Head) ForEachSafe(callback func(pos *Head))

func (*Head) Init

func (h *Head) Init()

初始化表头的函数,指向自己形成一个环

func (*Head) IsLast

func (h *Head) IsLast() bool

func (*Head) LastEntry

func (h *Head) LastEntry(offset uintptr) unsafe.Pointer

func (*Head) Len

func (h *Head) Len() int

func (*Head) Move

func (h *Head) Move(list *Head)

func (*Head) MoveTail

func (h *Head) MoveTail(list *Head)

func (*Head) NextEntry

func (pos *Head) NextEntry(offset uintptr) unsafe.Pointer

func (*Head) PrevEntry

func (pos *Head) PrevEntry(offset uintptr) unsafe.Pointer

func (*Head) Replace

func (h *Head) Replace(new *Head)

func (*Head) ReplaceInit

func (h *Head) ReplaceInit(new *Head)

func (*Head) RotateLeft

func (h *Head) RotateLeft()

type Time

type Time struct {
	sync.Mutex
	// contains filtered or unexported fields
}

先使用sync.Mutex实现功能 后面使用cas优化

func (*Time) Stop

func (t *Time) Stop()

一个timeNode节点有4个状态 1.存在于初始化链表中 2.被移动到tmp链表 3.1 和 3.2是if else的状态

3.1被移动到new链表
3.2直接执行

1和3.1状态是没有问题的 2和3.2状态会是没有锁保护下的操作,会有数据竞争

type TimeEventMsg added in v0.2.14

type TimeEventMsg struct {
	Callback func()
}

type TimeHandler added in v0.2.14

type TimeHandler interface {
	EventChan() <-chan TypeEventChan

	After(delay time.Duration, cb func()) TimeNoder

	Schedule(interval time.Duration, cb func()) TimeNoder

	// 停止所有定时器
	Stop()

	// 删除handler
	DelSelf()

	PrintDebug()
}

func NewHandler added in v0.2.15

func NewHandler() TimeHandler

type TimeNoder

type TimeNoder interface {
	Stop()
}

停止单个定时器

type Timer

type Timer interface {

	// 停止所有定时器
	Stop()

	Start()

	NewHandler() TimeHandler
}

定时器接口

func Instance

func Instance() Timer

func NewTimer

func NewTimer() Timer

type TypeEventChan added in v0.2.14

type TypeEventChan interface{}

type TypeEventChan func(...interface{})

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL