mirror of
https://github.com/golang/go
synced 2024-11-24 01:50:11 -07:00
4e2410617d
Change-Id: Ifdb4f4f4fab8d45847ca525198b3960f87799f0c Reviewed-on: https://go-review.googlesource.com/c/go/+/383034 Trust: Keith Randall <khr@golang.org> Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dan Scales <danscales@google.com> Trust: Dan Scales <danscales@google.com>
36 lines
574 B
Go
36 lines
574 B
Go
// compile -G=3 -d=checkptr
|
|
|
|
// Copyright 2022 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package main
|
|
|
|
import (
|
|
"sync/atomic"
|
|
"unsafe"
|
|
)
|
|
|
|
type Node[T any] struct {
|
|
Next *Node[T]
|
|
// Prev *Node[T]
|
|
}
|
|
|
|
func LoadPointer[T any](addr **T) (val *T) {
|
|
return (*T)(
|
|
atomic.LoadPointer(
|
|
(*unsafe.Pointer)(unsafe.Pointer(addr)),
|
|
))
|
|
}
|
|
|
|
func (q *Node[T]) Pop() {
|
|
var tail, head *Node[T]
|
|
if head == LoadPointer(&tail) {
|
|
}
|
|
}
|
|
|
|
func main() {
|
|
ch := Node[uint64]{}
|
|
ch.Pop()
|
|
}
|