MCPcopy
hub / github.com/google/gvisor / BlockWithTimeout

Method BlockWithTimeout

pkg/sentry/kernel/task_block.go:31–57  ·  view source on GitHub ↗

BlockWithTimeout implements context.Context.BlockWithTimeout. Preconditions: The caller must be running on the task goroutine.

(C chan struct{}, haveTimeout bool, timeout time.Duration)

Source from the content-addressed store, hash-verified

29//
30// Preconditions: The caller must be running on the task goroutine.
31func (t *Task) BlockWithTimeout(C chan struct{}, haveTimeout bool, timeout time.Duration) (time.Duration, error) {
32 if !haveTimeout {
33 return timeout, t.block(C, nil)
34 }
35
36 clock := t.Kernel().MonotonicClock()
37 start := clock.Now()
38 deadline := start.Add(timeout)
39 err := t.blockWithDeadlineFromSampledClock(C, clock, deadline)
40
41 // Timeout, explicitly return a remaining duration of 0.
42 if linuxerr.Equals(linuxerr.ETIMEDOUT, err) {
43 return 0, err
44 }
45
46 // Compute the remaining timeout. Note that even if block() above didn't
47 // return due to a timeout, we may have used up any of the remaining time
48 // since then. We cap the remaining timeout to 0 to make it easier to
49 // directly use the returned duration.
50 end := clock.Now()
51 remainingTimeout := timeout - end.Sub(start)
52 if remainingTimeout < 0 {
53 remainingTimeout = 0
54 }
55
56 return remainingTimeout, err
57}
58
59// BlockWithTimeoutOn implements context.Context.BlockWithTimeoutOn.
60//

Callers 2

SigtimedwaitMethod · 0.95
BlockWithTimeoutOnMethod · 0.95

Calls 8

blockMethod · 0.95
KernelMethod · 0.95
EqualsFunction · 0.92
MonotonicClockMethod · 0.80
NowMethod · 0.65
AddMethod · 0.65
SubMethod · 0.45

Tested by

no test coverage detected