Skip to content

Commit

Permalink
合并tiny的一些特性
Browse files Browse the repository at this point in the history
  • Loading branch information
pangdogs committed Feb 17, 2023
1 parent f58583d commit 75a8941
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
17 changes: 12 additions & 5 deletions localevent/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,27 +48,34 @@ func (event *Event) Init(autoRecover bool, reportError chan error, eventRecursio
}

if event.inited {
panic("repeated init event")
panic("event initialized")
}

if event.inited {
panic("event initialized")
}

event.autoRecover = autoRecover
event.reportError = reportError
event.eventRecursion = eventRecursion
event.subscribers.Init(hookCache, gcCollector)
event.gcCollector = gcCollector
event.opened = true
event.inited = true

event.Open()
}

// Open 打开事件
func (event *Event) Open() {
if !event.inited {
panic("event not initialized")
}

event.subscribers.SetGCCollector(event.gcCollector)
event.opened = true
}

// Close 关闭事件
func (event *Event) Close() {
event.subscribers.SetGCCollector(nil)
event.Clean()
event.opened = false
}
Expand All @@ -82,7 +89,7 @@ func (event *Event) Clean() {
}

func (event *Event) emit(fun func(delegate util.IfaceCache) bool) {
if fun == nil {
if fun == nil || !event.opened {
return
}

Expand Down
2 changes: 1 addition & 1 deletion runtime/ectree.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (ecTree *ECTree) init(runtimeCtx Context, masterTree bool) {
}

if ecTree.inited {
panic("repeated init ec-tree")
panic("ec-tree initialized")
}

ecTree.inited = true
Expand Down
15 changes: 10 additions & 5 deletions util/container/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ func (e *Element[T]) Escaped() bool {
return e.escaped
}

func (e *Element[T]) release() {
*e = Element[T]{}
}

// Released 是否已释放
func (e *Element[T]) Released() bool {
return e.list == nil
}

type _DefaultCache[T any] struct{}

func (*_DefaultCache[T]) Alloc() *Element[T] {
Expand Down Expand Up @@ -203,11 +212,7 @@ func (l *List[T]) insertValue(value T, at *Element[T]) *Element[T] {
func (l *List[T]) remove(e *Element[T]) *Element[T] {
e._prev._next = e._next
e._next._prev = e._prev
e._next = nil
e._prev = nil
e.list = nil
var zero T
e.Value = zero
e.release()
l.cap--
l.gcLen--
return e
Expand Down

0 comments on commit 75a8941

Please sign in to comment.