github.com/liangmanlin/routine@v1.1.0/routine.go (about)

     1  package routine
     2  
     3  import "unsafe"
     4  
     5  func Set(ptr unsafe.Pointer) {
     6  	th := currentThread(true)
     7  	th.val = ptr
     8  }
     9  
    10  func Get[T any]() *T {
    11  	th := currentThread(false)
    12  	if th == nil {
    13  		return nil
    14  	}
    15  	return (*T)(th.val)
    16  }
    17  
    18  func GetPtr() unsafe.Pointer {
    19  	th := currentThread(false)
    20  	if th == nil {
    21  		return nil
    22  	}
    23  	return th.val
    24  }