Skip to content

Commit

Permalink
support force-able gomark marking
Browse files Browse the repository at this point in the history
  • Loading branch information
forrestjgq committed Aug 23, 2022
1 parent 078cca5 commit efebceb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
9 changes: 7 additions & 2 deletions gmi/gmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ import "net/textproto"

// Marker is an interface to provide variable marking.
type Marker interface {
// ForceMark allows caller to set up a force flag, if force is false, the mark could be abandon,
// otherwise gomark should mark it as possible as it could
// return value indicates if mark is abandoned
ForceMark(n int32, force bool) bool
// Mark a number, the number definition is bound to marker itself.
Mark(n int32)
// Stop this marking.
// return value indicates if mark is abandoned
Mark(n int32) bool
// Cancel stops this marking.
Cancel()
}
type Route string
Expand Down
6 changes: 4 additions & 2 deletions internal/gm/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,12 @@ func ServerEnabled() bool {
return srv.disabled
}

func PushStub(s stub) {
if !srv.disabled && len(srv.stubc) < sizeOfQ-1 {
func PushStub(s stub, force bool) bool {
if !srv.disabled && (force || len(srv.stubc) < sizeOfQ-1) {
srv.stubc <- s
return true
}
return false
}

func AddSampler(s sampler) disposer {
Expand Down
9 changes: 7 additions & 2 deletions internal/gm/stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ package gm

type Identity uint32

func (i Identity) Mark(n int32) {
func (i Identity) ForceMark(n int32, force bool) bool {
if i != 0 {
s := makeStub(i, Mark(n))
PushStub(s)
return PushStub(s, force)
}
return false

}
func (i Identity) Mark(n int32) bool {
return i.ForceMark(n, false)
}

func (i Identity) Cancel() {
Expand Down
8 changes: 6 additions & 2 deletions internal/gm/variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,15 @@ func (vb *VarBase) EnablePerf() {
func (vb *VarBase) Marker() gmi.Marker {
return vb.id
}
func (vb *VarBase) Mark(n int32) {
func (vb *VarBase) ForceMark(n int32, force bool) bool {
if vb != nil && vb.Valid() {
s := makeStub(vb.ID(), Mark(n))
PushStub(s)
return PushStub(s, force)
}
return false
}
func (vb *VarBase) Mark(n int32) bool {
return vb.ForceMark(n, false)
}

func (vb *VarBase) Cancel() {
Expand Down

0 comments on commit efebceb

Please sign in to comment.