sync2

package
v0.0.0-...-9a5932e Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2014 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SERVICE_STOPPED = iota
	SERVICE_RUNNING
	SERVICE_SHUTTING_DOWN
)

These are the three predefined states of a service.

Variables

This section is empty.

Functions

This section is empty.

Types

type AtomicDuration

type AtomicDuration int64

func (*AtomicDuration) Add

func (d *AtomicDuration) Add(duration time.Duration) time.Duration

func (*AtomicDuration) CompareAndSwap

func (d *AtomicDuration) CompareAndSwap(oldval, newval time.Duration) (swapped bool)

func (*AtomicDuration) Get

func (d *AtomicDuration) Get() time.Duration

func (*AtomicDuration) Set

func (d *AtomicDuration) Set(duration time.Duration)

type AtomicInt32

type AtomicInt32 int32

func (*AtomicInt32) Add

func (i *AtomicInt32) Add(n int32) int32

func (*AtomicInt32) CompareAndSwap

func (i *AtomicInt32) CompareAndSwap(oldval, newval int32) (swapped bool)

func (*AtomicInt32) Get

func (i *AtomicInt32) Get() int32

func (*AtomicInt32) Set

func (i *AtomicInt32) Set(n int32)

type AtomicInt64

type AtomicInt64 int64

func (*AtomicInt64) Add

func (i *AtomicInt64) Add(n int64) int64

func (*AtomicInt64) CompareAndSwap

func (i *AtomicInt64) CompareAndSwap(oldval, newval int64) (swapped bool)

func (*AtomicInt64) Get

func (i *AtomicInt64) Get() int64

func (*AtomicInt64) Set

func (i *AtomicInt64) Set(n int64)

type AtomicString

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

AtomicString gives you atomic-style APIs for string, but it's only a convenience wrapper that uses a mutex. So, it's not as efficient as the rest of the atomic types.

func (*AtomicString) CompareAndSwap

func (s *AtomicString) CompareAndSwap(oldval, newval string) (swqpped bool)

func (*AtomicString) Get

func (s *AtomicString) Get() string

func (*AtomicString) Set

func (s *AtomicString) Set(str string)

type AtomicUint32

type AtomicUint32 uint32

func (*AtomicUint32) Add

func (i *AtomicUint32) Add(n uint32) uint32

func (*AtomicUint32) CompareAndSwap

func (i *AtomicUint32) CompareAndSwap(oldval, newval uint32) (swapped bool)

func (*AtomicUint32) Get

func (i *AtomicUint32) Get() uint32

func (*AtomicUint32) Set

func (i *AtomicUint32) Set(n uint32)

type Cond

type Cond struct {
	L sync.Locker
	// contains filtered or unexported fields
}

Cond is an alternate implementation of sync.Cond

func NewCond

func NewCond(l sync.Locker) *Cond

func (*Cond) Broadcast

func (c *Cond) Broadcast()

func (*Cond) Signal

func (c *Cond) Signal()

func (*Cond) Wait

func (c *Cond) Wait()

type Semaphore

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

Semaphore is a counting semaphore with the option to specify a timeout.

func NewSemaphore

func NewSemaphore(count int, timeout time.Duration) *Semaphore

NewSemaphore creates a Semaphore. The count parameter must be a positive number. A timeout of zero means that there is no timeout.

func (*Semaphore) Acquire

func (sem *Semaphore) Acquire() bool

Acquire returns true on successful acquisition, and false on a timeout.

func (*Semaphore) Release

func (sem *Semaphore) Release()

Release releases the acquired semaphore. You must not release more than the number of semaphores you've acquired.

type ServiceManager

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

ServiceManager manages the state of a service through its lifecycle.

func (*ServiceManager) Go

func (svm *ServiceManager) Go(service func(svm *ServiceManager)) bool

Go tries to change the state from SERVICE_STOPPED to SERVICE_RUNNING. If the current state is not SERVICE_STOPPED (already running), it returns false immediately. On successful transition, it launches the service as a goroutine and returns true. The service func is required to regularly check the state of the service manager. If the state is not SERVICE_RUNNING, it must treat it as end of service and return. When the service func returns, the state is reverted to SERVICE_STOPPED.

func (*ServiceManager) State

func (svm *ServiceManager) State() int64

State returns the current state of the service. This should only be used to report the current state.

func (*ServiceManager) StateName

func (svm *ServiceManager) StateName() string

StateName returns the name of the current state.

func (*ServiceManager) Stop

func (svm *ServiceManager) Stop() bool

Stop tries to change the state from SERVICE_RUNNING to SERVICE_SHUTTING_DOWN. If the current state is not SERVICE_RUNNING, it returns false immediately. On successul transition, it waits for the service to finish, and returns true. You are allowed to 'Go' again after a Stop.

func (*ServiceManager) Wait

func (svm *ServiceManager) Wait()

Wait waits for the service to terminate if it's currently running.

Jump to

Keyboard shortcuts

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