Documentation ¶
Overview ¶
Package context defines an internal context type.
The given Context conforms to the standard Go context, but mandates additional methods that are specific to the kernel internals. Note however, that the Context described by this package carries additional constraints regarding concurrent access and retaining beyond the scope of a call.
See the Context type for complete details.
Index ¶
- Constants
- func ThreadGroupIDFromContext(ctx Context) (tgid int32, ok bool)
- type ChannelSleeper
- type Context
- type NoopSleeper
- func (NoopSleeper) Deadline() (time.Time, bool)
- func (NoopSleeper) Done() <-chan struct{}
- func (NoopSleeper) Err() error
- func (NoopSleeper) Interrupted() bool
- func (NoopSleeper) SleepFinish(success bool)
- func (NoopSleeper) SleepStart() <-chan struct{}
- func (NoopSleeper) UninterruptibleSleepFinish(activate bool)
- func (NoopSleeper) UninterruptibleSleepStart(deactivate bool)
Constants ¶
const ( // CtxThreadGroupID is the current thread group ID when a context represents // a task context. The value is represented as an int32. CtxThreadGroupID contextID = iota )
Globally accessible values from a context. These keys are defined in the context package to resolve dependency cycles by not requiring the caller to import packages usually required to get these information.
Variables ¶
This section is empty.
Functions ¶
func ThreadGroupIDFromContext ¶
ThreadGroupIDFromContext returns the current thread group ID when ctx represents a task context.
Types ¶
type ChannelSleeper ¶
type ChannelSleeper interface { // SleepStart is called before going to sleep interruptibly. If SleepStart // returns a non-nil channel and that channel becomes ready for receiving // while the goroutine is sleeping, the goroutine should be woken, and // SleepFinish(false) should be called. Otherwise, SleepFinish(true) should // be called after the goroutine stops sleeping. SleepStart() <-chan struct{} // SleepFinish is called after an interruptibly-sleeping goroutine stops // sleeping, as documented by SleepStart. SleepFinish(success bool) // Interrupted returns true if the channel returned by SleepStart is // ready for receiving. Interrupted() bool }
A ChannelSleeper represents a goroutine that may sleep interruptibly, where interruption is indicated by a channel becoming readable.
type Context ¶
type Context interface { log.Logger context.Context ChannelSleeper // UninterruptibleSleepStart indicates the beginning of an uninterruptible // sleep state (equivalent to Linux's TASK_UNINTERRUPTIBLE). If deactivate // is true and the Context represents a Task, the Task's AddressSpace is // deactivated. UninterruptibleSleepStart(deactivate bool) // UninterruptibleSleepFinish indicates the end of an uninterruptible sleep // state that was begun by a previous call to UninterruptibleSleepStart. If // activate is true and the Context represents a Task, the Task's // AddressSpace is activated. Normally activate is the same value as the // deactivate parameter passed to UninterruptibleSleepStart. UninterruptibleSleepFinish(activate bool) }
A Context represents a thread of execution (hereafter "goroutine" to reflect Go idiosyncrasy). It carries state associated with the goroutine across API boundaries.
While Context exists for essentially the same reasons as Go's standard context.Context, the standard type represents the state of an operation rather than that of a goroutine. This is a critical distinction:
- Unlike context.Context, which "may be passed to functions running in different goroutines", it is *not safe* to use the same Context in multiple concurrent goroutines.
- It is *not safe* to retain a Context passed to a function beyond the scope of that function call.
In both cases, values extracted from the Context should be used instead.
func Background ¶
func Background() Context
Background returns an empty context using the default logger. Generally, one should use the Task as their context when available, or avoid having to use a context in places where a Task is unavailable.
Using a Background context for tests is fine, as long as no values are needed from the context in the tested code paths.
type NoopSleeper ¶
type NoopSleeper struct{}
NoopSleeper is a noop implementation of ChannelSleeper and Context.UninterruptibleSleep* methods for anonymous embedding in other types that do not implement special behavior around sleeps.
func (NoopSleeper) Deadline ¶
func (NoopSleeper) Deadline() (time.Time, bool)
Deadline implements context.Context.Deadline.
func (NoopSleeper) Done ¶
func (NoopSleeper) Done() <-chan struct{}
Done implements context.Context.Done.
func (NoopSleeper) Interrupted ¶
func (NoopSleeper) Interrupted() bool
Interrupted implements ChannelSleeper.Interrupted.
func (NoopSleeper) SleepFinish ¶
func (NoopSleeper) SleepFinish(success bool)
SleepFinish implements ChannelSleeper.SleepFinish.
func (NoopSleeper) SleepStart ¶
func (NoopSleeper) SleepStart() <-chan struct{}
SleepStart implements ChannelSleeper.SleepStart.
func (NoopSleeper) UninterruptibleSleepFinish ¶
func (NoopSleeper) UninterruptibleSleepFinish(activate bool)
UninterruptibleSleepFinish implements Context.UninterruptibleSleepFinish.
func (NoopSleeper) UninterruptibleSleepStart ¶
func (NoopSleeper) UninterruptibleSleepStart(deactivate bool)
UninterruptibleSleepStart implements Context.UninterruptibleSleepStart.