synchelper

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chain

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

Chain is a helper to implement internally sequential execution of parallel jobs.

NOTE: Init MUST be called before calling other methods

func NewChain

func NewChain() (c *Chain)

NewChain creates a new Synchain

func (*Chain) Cancel

func (c *Chain) Cancel(err error)

Cancel the sync group with error, wakeup all waiting goroutines

func (*Chain) Done

func (c *Chain) Done()

Done

func (*Chain) Err

func (c *Chain) Err() error

Err returns the last error stored when Cancel called

func (*Chain) Go

func (c *Chain) Go(fn func(t Ticket) error)

Go spawns a new goroutine in the Synchain, user func MUST call Lock with the provided ticket

on error return of user func, it calls Cancel and Done, otherwise, calls Unlock and Done

func (*Chain) Init

func (c *Chain) Init()

Init this sync group

func (*Chain) Lock

func (c *Chain) Lock(t Ticket) bool

Lock waits until this job can be continued

func (*Chain) NewTicket

func (c *Chain) NewTicket() (t Ticket)

NewTicket creates a new sequence handle in this sync group

func (*Chain) Unlock

func (c *Chain) Unlock(t Ticket)

Unlock wakes next waiting goroutine

func (*Chain) Wait

func (c *Chain) Wait()

Wait waits all workers to exit

type SpinLock

type SpinLock atomic.Uint32

SpinLock implements sync.Locker using atomic CAS and runtime.Gosched

func (*SpinLock) Lock

func (l *SpinLock) Lock()

Lock sets l from 0 to 1 by atomic CAS, when l is not 0, wait until it is 0

func (*SpinLock) Locked

func (l *SpinLock) Locked() bool

Locked returns true if the SpinLock is currently locked by other goroutine.

func (*SpinLock) Unlock

func (l *SpinLock) Unlock()

Unlock sets l to 0 immediately

type Ticket

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

Ticket is an opaque type held

Jump to

Keyboard shortcuts

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