github.com/moontrade/unsafe@v0.9.1/cgo/stub.go (about)

     1  package cgo
     2  
     3  import (
     4  	"github.com/moontrade/unsafe/cgo/internal/trampoline"
     5  	"time"
     6  )
     7  
     8  // BlockingSleep invokes C++ std::thread sleep utilizing the safe CGO trampoline.
     9  // It is preferable to use time.Sleep in likely all circumstances.
    10  func BlockingSleep(nanos time.Duration) {
    11  	Blocking((*byte)(trampoline.Sleep), uintptr(nanos), 0)
    12  }
    13  
    14  // NonBlockingSleep invokes C++ std::thread sleep using Assembly Trampoline.
    15  // It is only acceptable to do this  after runtime.LockOSThread() and only
    16  // used when absolutely certain.
    17  //
    18  // WARNING!!! You should probably never use this
    19  func NonBlockingSleep(nanos time.Duration) {
    20  	NonBlocking((*byte)(trampoline.Sleep), uintptr(nanos), 0)
    21  }
    22  
    23  // NonBlockingNoop can be used for benchmarking Assembly Trampoline/CGO trampoline overhead.
    24  // The C function is empty and returns void.
    25  func NonBlockingNoop() {
    26  	NonBlocking((*byte)(trampoline.Stub), 0, 0)
    27  }
    28  
    29  // BlockingNoop can be used for benchmarking CGO Trampoline overhead.
    30  // The C function is empty and returns void.
    31  func BlockingNoop() {
    32  	Blocking((*byte)(trampoline.Stub), 0, 0)
    33  }
    34  
    35  // CGONoop can be used for benchmarking CGO overhead.
    36  // The C function is empty and returns void.
    37  func CGONoop() {
    38  	trampoline.CGO()
    39  }