1// build -gcflags=-l=4
2
3// Copyright 2023 The Go Authors. All rights reserved.
4// Use of this source code is governed by a BSD-style
5// license that can be found in the LICENSE file.
6
7package p
8
9type Interface interface {
10	MonitoredResource() (resType string, labels map[string]string)
11	Done()
12}
13
14func Autodetect(x int) Interface {
15	return func() Interface {
16		func() Interface {
17			x++
18			Do(func() {
19				var ad, gd Interface
20
21				go func() {
22					defer gd.Done()
23					ad = aad()
24				}()
25				go func() {
26					defer ad.Done()
27					gd = aad()
28					defer func() { recover() }()
29				}()
30
31				autoDetected = ad
32				if gd != nil {
33					autoDetected = gd
34				}
35			})
36			return autoDetected
37		}()
38		return nil
39	}()
40}
41
42var autoDetected Interface
43var G int
44
45type If int
46
47func (x If) MonitoredResource() (resType string, labels map[string]string) {
48	return "", nil
49}
50
51//go:noinline
52func (x If) Done() {
53	G++
54}
55
56//go:noinline
57func Do(fn func()) {
58	fn()
59}
60
61//go:noinline
62func aad() Interface {
63	var x If
64	return x
65}
66