1
0
mirror of https://github.com/Mrs4s/MiraiGo.git synced 2025-05-04 11:07:40 +08:00
MiraiGo/utils/sys.go
2020-12-14 16:30:47 +08:00

18 lines
415 B
Go

package utils
import (
"reflect"
"unsafe"
)
func IsChanClosed(ch interface{}) bool {
if reflect.TypeOf(ch).Kind() != reflect.Chan {
panic("object is not a channel.")
}
ptr := *(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&ch)) + unsafe.Sizeof(uint(0))))
ptr += unsafe.Sizeof(uint(0)) * 2
ptr += unsafe.Sizeof(uintptr(0))
ptr += unsafe.Sizeof(uint16(0))
return *(*uint32)(unsafe.Pointer(ptr)) > 0
}