Debian Codegraph @

libgo/go/runtime/testdata/testprogcgo/gprof_c.c

raw
1 // Copyright 2021 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 //go:build !gccgo
6 // +build !gccgo
7
8 // The C definitions for gprof.go. That file uses //export so
9 // it can't put function definitions in the "C" import comment.
10
11 #include <stdint.h>
12 #include <stdlib.h>
13
14 // Functions exported from Go.
15 extern void GoSleep();
16
17 struct cgoContextArg {
18 uintptr_t context;
19 };
20
21 void gprofCgoContext(void *arg) {
22 ((struct cgoContextArg*)arg)->context = 1;
23 }
24
25 void gprofCgoTraceback(void *arg) {
26 // spend some time here so the P is more likely to be retaken.
27 volatile int i;
28 for (i = 0; i < 123456789; i++);
29 }
30
31 void CallGoSleep() {
32 GoSleep();
33 }