| 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 |
// The C definitions for gprof.go. That file uses //export so |
| 6 |
// it can't put function definitions in the "C" import comment. |
| 7 |
|
| 8 |
#include <stdint.h> |
| 9 |
#include <stdlib.h> |
| 10 |
|
| 11 |
// Functions exported from Go. |
| 12 |
extern void GoSleep(); |
| 13 |
|
| 14 |
struct cgoContextArg { |
| 15 |
uintptr_t context; |
| 16 |
}; |
| 17 |
|
| 18 |
void gprofCgoContext(void *arg) { |
| 19 |
((struct cgoContextArg*)arg)->context = 1; |
| 20 |
} |
| 21 |
|
| 22 |
void gprofCgoTraceback(void *arg) { |
| 23 |
// spend some time here so the P is more likely to be retaken. |
| 24 |
volatile int i; |
| 25 |
for (i = 0; i < 123456789; i++); |
| 26 |
} |
| 27 |
|
| 28 |
void CallGoSleep() { |
| 29 |
GoSleep(); |
| 30 |
} |