mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2024-11-25 11:05:26 +00:00
58 lines
923 B
Go
58 lines
923 B
Go
package yggdrasil
|
|
|
|
// These are misc. utility functions that didn't really fit anywhere else
|
|
|
|
import "runtime"
|
|
|
|
//import "sync"
|
|
|
|
func util_yield() {
|
|
runtime.Gosched()
|
|
}
|
|
|
|
func util_lockthread() {
|
|
runtime.LockOSThread()
|
|
}
|
|
|
|
func util_unlockthread() {
|
|
runtime.UnlockOSThread()
|
|
}
|
|
|
|
/* Used previously, but removed because casting to an interface{} allocates...
|
|
var byteStore sync.Pool = sync.Pool{
|
|
New: func () interface{} { return []byte(nil) },
|
|
}
|
|
|
|
func util_getBytes() []byte {
|
|
return byteStore.Get().([]byte)[:0]
|
|
}
|
|
|
|
func util_putBytes(bs []byte) {
|
|
byteStore.Put(bs) // This is the part that allocates
|
|
}
|
|
*/
|
|
|
|
var byteStore chan []byte
|
|
|
|
func util_initByteStore() {
|
|
if byteStore == nil {
|
|
byteStore = make(chan []byte, 32)
|
|
}
|
|
}
|
|
|
|
func util_getBytes() []byte {
|
|
select {
|
|
case bs := <-byteStore:
|
|
return bs[:0]
|
|
default:
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func util_putBytes(bs []byte) {
|
|
select {
|
|
case byteStore <- bs:
|
|
default:
|
|
}
|
|
}
|