Debian Codegraph @

atomic_go119.go

raw
1 // Copyright 2019 Huan Du. All rights reserved.
2 // Licensed under the MIT license that can be found in the LICENSE file.
3
4 //go:build go1.19
5 // +build go1.19
6
7 package clone
8
9 import (
10 "reflect"
11 "sync/atomic"
12 )
13
14 func init() {
15 SetCustomFunc(reflect.TypeOf(atomic.Bool{}), func(allocator *Allocator, old, new reflect.Value) {
16 if !old.CanAddr() {
17 return
18 }
19
20 // Clone value inside atomic.Bool.
21 oldValue := old.Addr().Interface().(*atomic.Bool)
22 newValue := new.Addr().Interface().(*atomic.Bool)
23 v := oldValue.Load()
24 newValue.Store(v)
25 })
26 SetCustomFunc(reflect.TypeOf(atomic.Int32{}), func(allocator *Allocator, old, new reflect.Value) {
27 if !old.CanAddr() {
28 return
29 }
30
31 // Clone value inside atomic.Int32.
32 oldValue := old.Addr().Interface().(*atomic.Int32)
33 newValue := new.Addr().Interface().(*atomic.Int32)
34 v := oldValue.Load()
35 newValue.Store(v)
36 })
37 SetCustomFunc(reflect.TypeOf(atomic.Int64{}), func(allocator *Allocator, old, new reflect.Value) {
38 if !old.CanAddr() {
39 return
40 }
41
42 // Clone value inside atomic.Int64.
43 oldValue := old.Addr().Interface().(*atomic.Int64)
44 newValue := new.Addr().Interface().(*atomic.Int64)
45 v := oldValue.Load()
46 newValue.Store(v)
47 })
48 SetCustomFunc(reflect.TypeOf(atomic.Uint32{}), func(allocator *Allocator, old, new reflect.Value) {
49 if !old.CanAddr() {
50 return
51 }
52
53 // Clone value inside atomic.Uint32.
54 oldValue := old.Addr().Interface().(*atomic.Uint32)
55 newValue := new.Addr().Interface().(*atomic.Uint32)
56 v := oldValue.Load()
57 newValue.Store(v)
58 })
59 SetCustomFunc(reflect.TypeOf(atomic.Uint64{}), func(allocator *Allocator, old, new reflect.Value) {
60 if !old.CanAddr() {
61 return
62 }
63
64 // Clone value inside atomic.Uint64.
65 oldValue := old.Addr().Interface().(*atomic.Uint64)
66 newValue := new.Addr().Interface().(*atomic.Uint64)
67 v := oldValue.Load()
68 newValue.Store(v)
69 })
70 SetCustomFunc(reflect.TypeOf(atomic.Uintptr{}), func(allocator *Allocator, old, new reflect.Value) {
71 if !old.CanAddr() {
72 return
73 }
74
75 // Clone value inside atomic.Uintptr.
76 oldValue := old.Addr().Interface().(*atomic.Uintptr)
77 newValue := new.Addr().Interface().(*atomic.Uintptr)
78 v := oldValue.Load()
79 newValue.Store(v)
80 })
81 }