You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pkg/timing/timing.go
+35Lines changed: 35 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -86,6 +86,10 @@ type Timeline struct {
86
86
// children is a list of forked timelines that are children of this one.
87
87
// Note that children do not necessarily need to end before the parent does.
88
88
children []*Timeline
89
+
90
+
// invalidReason, if non-empty, is the reason why this Timeline is invalid.
91
+
// A Timeline is also invalid if any of its children are invalid.
92
+
invalidReasonstring
89
93
}
90
94
91
95
// MidPoint is a named point in time on a Timeline.
@@ -243,6 +247,18 @@ func (s *Timeline) End() {
243
247
}
244
248
}
245
249
250
+
// Invalidate marks the Timeline as invalid.
251
+
func (s*Timeline) Invalidate(reasonstring) {
252
+
ifs==nil {
253
+
return
254
+
}
255
+
ifs.invalidReason!="" {
256
+
log.Warningf("Timer for %s: Timeline %s was already invalid (%v), but tried to invalidate again (%v)", s.timer.root.name, s.fullName, s.invalidReason, reason)
257
+
return
258
+
}
259
+
s.invalidReason=reason
260
+
}
261
+
246
262
// A Lease is a reference to a Timeline that is valid until the Lease is
247
263
// canceled. After calling Lease on a Timeline, the caller should no longer
248
264
// use the Timeline directly, and should instead use the Lease exclusively.
@@ -342,6 +358,15 @@ func (l *Lease) End() {
342
358
l.timeline.End()
343
359
}
344
360
361
+
// Invalidate invalidates the Timeline if the Lease is valid.
362
+
// See `Timeline.Invalidate` for more details.
363
+
func (l*Lease) Invalidate(reasonstring) {
364
+
ifl==nil||!l.valid {
365
+
return
366
+
}
367
+
l.timeline.Invalidate(reason)
368
+
}
369
+
345
370
// Transfer invalidates the current Lease and returns the underlying Timeline.
346
371
// Typically useful when transferring ownership of a Timeline to a different
347
372
// goroutine while giving up ownership in the current one.
0 commit comments