context

package
v0.0.0-...-23e6066 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 3, 2018 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package context defines the sentry's Context type.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context interface {
	log.Logger
	amutex.Sleeper

	// 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)

	// Value returns the value associated with this Context for key, or nil if
	// no value is associated with key. Successive calls to Value with the same
	// key returns the same result.
	//
	// A key identifies a specific value in a Context. Functions that wish to
	// retrieve values from Context typically allocate a key in a global
	// variable then use that key as the argument to Context.Value. A key can
	// be any type that supports equality; packages should define keys as an
	// unexported type to avoid collisions.
	Value(key interface{}) interface{}
}

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.

Users should be wary of using a Background context. Please tag any use with FIXME and a note to remove this use.

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 {
	amutex.NoopSleeper
}

NoopSleeper is a noop implementation of amutex.Sleeper and Context.UninterruptibleSleep* methods for anonymous embedding in other types that do not want to notify kernel.Task about sleeps.

func (NoopSleeper) UninterruptibleSleepFinish

func (NoopSleeper) UninterruptibleSleepFinish(bool)

UninterruptibleSleepFinish does nothing.

func (NoopSleeper) UninterruptibleSleepStart

func (NoopSleeper) UninterruptibleSleepStart(bool)

UninterruptibleSleepStart does nothing.

Directories

Path Synopsis
Package contexttest builds a test context.Context.
Package contexttest builds a test context.Context.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL