Create init method on provider interface
This commit is contained in:
parent
b2a57ca1f3
commit
027093a5a5
52 changed files with 2760 additions and 131 deletions
45
vendor/github.com/Microsoft/ApplicationInsights-Go/appinsights/concurrentrandom.go
generated
vendored
Normal file
45
vendor/github.com/Microsoft/ApplicationInsights-Go/appinsights/concurrentrandom.go
generated
vendored
Normal file
|
@ -0,0 +1,45 @@
|
|||
package appinsights
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"math/rand"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
type concurrentRandom struct {
|
||||
channel chan string
|
||||
random *rand.Rand
|
||||
}
|
||||
|
||||
var randomGenerator *concurrentRandom
|
||||
|
||||
func newConcurrentRandom() *concurrentRandom {
|
||||
source := rand.NewSource(time.Now().UnixNano())
|
||||
return &concurrentRandom{
|
||||
channel: make(chan string, 4),
|
||||
random: rand.New(source),
|
||||
}
|
||||
}
|
||||
|
||||
func (generator *concurrentRandom) run() {
|
||||
buf := make([]byte, 8)
|
||||
for {
|
||||
generator.random.Read(buf)
|
||||
generator.channel <- base64.StdEncoding.EncodeToString(buf)
|
||||
}
|
||||
}
|
||||
|
||||
func randomId() string {
|
||||
if randomGenerator == nil {
|
||||
r := newConcurrentRandom()
|
||||
if atomic.CompareAndSwapPointer((*unsafe.Pointer)(unsafe.Pointer(&randomGenerator)), unsafe.Pointer(nil), unsafe.Pointer(r)) {
|
||||
go r.run()
|
||||
} else {
|
||||
close(r.channel)
|
||||
}
|
||||
}
|
||||
|
||||
return <-randomGenerator.channel
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue