task

package
v0.38.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2025 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Initial state: the goroutine state is saved on the stack.
	RunStatePaused = iota

	// The goroutine is running right now.
	RunStateRunning

	// The goroutine is running, but already marked as "can resume".
	// The next call to Pause() won't actually pause the goroutine.
	RunStateResuming
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Mutex added in v0.36.0

type Mutex struct {
	// contains filtered or unexported fields
}

func (*Mutex) Lock added in v0.36.0

func (m *Mutex) Lock()

func (*Mutex) TryLock added in v0.36.0

func (m *Mutex) TryLock() bool

TryLock tries to lock m and reports whether it succeeded.

Note that while correct uses of TryLock do exist, they are rare, and use of TryLock is often a sign of a deeper problem in a particular use of mutexes.

func (*Mutex) Unlock added in v0.36.0

func (m *Mutex) Unlock()

type PMutex added in v0.35.0

type PMutex = Mutex

PMutex is a real mutex on systems that can be either preemptive or threaded, and a dummy lock on other (purely cooperative) systems.

It is mainly useful for short operations that need a lock when threading may be involved, but which do not need a lock with a purely cooperative scheduler.

type Queue

type Queue struct {
	// contains filtered or unexported fields
}

Queue is a FIFO container of tasks. The zero value is an empty queue.

func (*Queue) Append

func (q *Queue) Append(other *Queue)

Append pops the contents of another queue and pushes them onto the end of this queue.

func (*Queue) Empty added in v0.14.0

func (q *Queue) Empty() bool

Empty checks if the queue is empty.

func (*Queue) Pop

func (q *Queue) Pop() *Task

Pop a task off of the queue.

func (*Queue) Push

func (q *Queue) Push(t *Task)

Push a task onto the queue.

type Semaphore added in v0.38.0

type Semaphore struct {
	// contains filtered or unexported fields
}

Barebones semaphore implementation. The main limitation is that if there are multiple waiters, a single Post() call won't do anything. Only when Post() has been called to awaken all waiters will the waiters proceed. This limitation is not a problem when there will only be a single waiter.

func (*Semaphore) Post added in v0.38.0

func (s *Semaphore) Post()

Post (unlock) the semaphore, incrementing the value in the semaphore.

func (*Semaphore) Wait added in v0.38.0

func (s *Semaphore) Wait()

Wait (lock) the semaphore, decrementing the value in the semaphore.

type Stack

type Stack struct {
	// contains filtered or unexported fields
}

Stack is a LIFO container of tasks. The zero value is an empty stack. This is slightly cheaper than a queue, so it can be preferable when strict ordering is not necessary.

func (*Stack) Pop

func (s *Stack) Pop() *Task

Pop a task off of the stack.

func (*Stack) Push

func (s *Stack) Push(t *Task)

Push a task onto the stack.

func (*Stack) Queue

func (s *Stack) Queue() Queue

Queue moves the contents of the stack into a queue. Elements can be popped from the queue in the same order that they would be popped from the stack.

type Task

type Task struct {
	// Next is a field which can be used to make a linked list of tasks.
	Next *Task

	// Ptr is a field which can be used for storing a pointer.
	Ptr unsafe.Pointer

	// Data is a field which can be used for storing state information.
	Data uint64

	// This is needed for some crypto packages.
	FipsIndicator uint8

	// State of the goroutine: running, paused, or must-resume-next-pause.
	// This extra field doesn't increase memory usage on 32-bit CPUs and above,
	// since it falls into the padding of the FipsIndicator bit above.
	RunState uint8

	// DeferFrame stores a pointer to the (stack allocated) defer frame of the
	// goroutine that is used for the recover builtin.
	DeferFrame unsafe.Pointer
	// contains filtered or unexported fields
}

Task is a state of goroutine for scheduling purposes.

func (*Task) DataAtomicUint32 added in v0.35.0

func (t *Task) DataAtomicUint32() *Uint32

DataAtomicUint32 returns the Data field as an atomic-if-needed Uint32 value.

func (*Task) DataUint32 added in v0.35.0

func (t *Task) DataUint32() uint32

DataUint32 returns the Data field as a uint32. The value is only valid after setting it through SetDataUint32 or by storing to it using DataAtomicUint32.

func (*Task) SetDataUint32 added in v0.35.0

func (t *Task) SetDataUint32(val uint32)

SetDataUint32 updates the uint32 portion of the Data field (which could be the first 4 or last 4 bytes depending on the architecture endianness).

type Uint32 added in v0.35.0

type Uint32 = atomic.Uint32

type Uint64 added in v0.35.0

type Uint64 = atomic.Uint64

type Uintptr added in v0.35.0

type Uintptr = atomic.Uintptr

Jump to

Keyboard shortcuts

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