Skip to content

Commit b94cb72

Browse files
committed
整理代码
1 parent e65766c commit b94cb72

4 files changed

Lines changed: 7 additions & 16 deletions

File tree

ec/ictx/context.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ type Context interface {
4747

4848
type iContext interface {
4949
init(parentCtx context.Context, autoRecover bool, reportError chan error)
50-
setPaired(v bool) bool
51-
getPaired() bool
50+
getPaired() *atomic.Bool
5251
returnTerminated()
5352
}
5453

@@ -107,12 +106,8 @@ func (ctx *ContextBehavior) init(parentCtx context.Context, autoRecover bool, re
107106
ctx.terminated = async.MakeAsyncRet()
108107
}
109108

110-
func (ctx *ContextBehavior) setPaired(v bool) bool {
111-
return ctx.paired.CompareAndSwap(!v, v)
112-
}
113-
114-
func (ctx *ContextBehavior) getPaired() bool {
115-
return ctx.paired.Load()
109+
func (ctx *ContextBehavior) getPaired() *atomic.Bool {
110+
return &ctx.paired
116111
}
117112

118113
func (ctx *ContextBehavior) returnTerminated() {

ec/ictx/unsafe_context.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ package ictx
2121

2222
import (
2323
"context"
24+
"sync/atomic"
2425
)
2526

2627
// Deprecated: UnsafeContext 访问上下文内部方法
@@ -39,13 +40,8 @@ func (u _UnsafeContext) Init(parentCtx context.Context, autoRecover bool, report
3940
u.init(parentCtx, autoRecover, reportError)
4041
}
4142

42-
// SetPaired 设置配对标记
43-
func (u _UnsafeContext) SetPaired(v bool) bool {
44-
return u.setPaired(v)
45-
}
46-
4743
// GetPaired 获取配对标记
48-
func (u _UnsafeContext) GetPaired() bool {
44+
func (u _UnsafeContext) GetPaired() *atomic.Bool {
4945
return u.getPaired()
5046
}
5147

runtime.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func (rt *RuntimeBehavior) init(rtCtx runtime.Context, options RuntimeOptions) {
158158
exception.Panicf("%w: %w: rtCtx is nil", ErrRuntime, ErrArgs)
159159
}
160160

161-
if !ictx.UnsafeContext(rtCtx).SetPaired(true) {
161+
if !ictx.UnsafeContext(rtCtx).GetPaired().CompareAndSwap(false, true) {
162162
exception.Panicf("%w: context already paired", ErrRuntime)
163163
}
164164

service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func (svc *ServiceBehavior) init(svcCtx service.Context, options ServiceOptions)
9191
exception.Panicf("%w: %w: svcCtx is nil", ErrService, ErrArgs)
9292
}
9393

94-
if !ictx.UnsafeContext(svcCtx).SetPaired(true) {
94+
if !ictx.UnsafeContext(svcCtx).GetPaired().CompareAndSwap(false, true) {
9595
exception.Panicf("%w: context already paired", ErrService)
9696
}
9797

0 commit comments

Comments
 (0)