sabotage

package module
v0.0.0-...-1c1fa12 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2022 License: BSD-3-Clause Imports: 7 Imported by: 0

README

SABOTAGE

Build Status GoDoc Go Report

Collection of dirty hacks in Go.

  1. Repeat sync.Once once more.
  2. Check if sync.Mutex/sync.RWMutex is locked.
  3. []byte <-> string conversion without additional allocation.

logo

Cause what you see, you might not get
And we can bet, so don't you get souped yet
Scheming on a thing, that's a mirage
I'm trying to tell you now, it's sabotage

Whhhhhyyyyyy??????

(c) Beastie Boys - Sabotage

Examples

  1. You can repeat sync.Once as much as you want:
var once sync.Once

once.Do(myFunc)

sabotage.ResetSyncOnce(&once) 

or check if it was invoked earlier:

if sabotage.IsOnceDone(&once) {
    println("well-well-well")
}
  1. You can unlock any mutex from anywhere:
var mu sync.Mutex

// let's yolo begins
sabotage.UnlockMutex(&mu)

or check if it's locked:

if sabotage.IsMutexLocked(&mu) {
    for {
        // let's wait a bit
    }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesToString

func BytesToString(bytes []byte) (s string)

BytesToString converts []byte to a string without an allocation.

func GoroutineID

func GoroutineID() uint64

GoroutineID returns the goroutine id of the calling goroutine.

func HasOverlap

func HasOverlap(x, y []byte) bool

HasOverlap reports whether x and y share memory at any index. The memory beyond the slice length is ignored.

Based on golang.org/x/crypto/internal/subtle

func IsMutexLocked

func IsMutexLocked(m *sync.Mutex) bool

IsMutexLocked will return true if sync.Mutex is locked.

func IsOnceDone

func IsOnceDone(once *sync.Once) bool

IsOnceDone will return true if sync.Once.Do was invoked.

func IsRWMutexLocked

func IsRWMutexLocked(m *sync.RWMutex) bool

IsRWMutexLocked will return true if sync.Mutex is locked.

func Pid

func Pid() int

Pid returns the id of a current {}.

func Pin

func Pin() int

Pin the current P, returns pid.

func ResetSyncOnce

func ResetSyncOnce(once *sync.Once)

ResetSyncOnce will reset sync.Once to default state.

func StringToBytes

func StringToBytes(s string) []byte

StringToBytes converts string to []byte without an allocation.

func UnlockMutex

func UnlockMutex(mutex *sync.Mutex)

UnlockMutex will unlock a mutex.

func UnlockRWMutex

func UnlockRWMutex(mutex *sync.RWMutex)

UnlockRWMutex will unlock rwmutex.

func Unpin

func Unpin()

Unpin the current P.

Types

This section is empty.

Jump to

Keyboard shortcuts

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