RISC-V: Disable Zba optimization pattern if XTheadMemIdx is enabled
[official-gcc.git] / libgo / misc / cgo / test / callback_c.c
blob8921b7306c6b148f13611ecaca6da4b47dcbfb98
1 // Copyright 2011 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.
5 #include <string.h>
6 #include <sys/types.h>
7 #include <unistd.h>
8 #include "_cgo_export.h"
10 void
11 callback(void *f)
13 // use some stack space
14 volatile char data[64*1024];
16 data[0] = 0;
17 goCallback(f);
18 data[sizeof(data)-1] = 0;
21 void
22 callGoFoo(void)
24 extern void goFoo(void);
25 goFoo();
28 void
29 IntoC(void)
31 BackIntoGo();
34 #ifdef WIN32
35 #include <windows.h>
36 long long
37 mysleep(int seconds) {
38 long long st = GetTickCount();
39 Sleep(1000 * seconds);
40 return st;
42 #else
43 #include <sys/time.h>
44 long long
45 mysleep(int seconds) {
46 long long st;
47 struct timeval tv;
48 gettimeofday(&tv, NULL);
49 st = tv.tv_sec * 1000 + tv.tv_usec / 1000;
50 sleep(seconds);
51 return st;
53 #endif
55 long long
56 twoSleep(int n)
58 BackgroundSleep(n);
59 return mysleep(n);
62 void
63 callGoStackCheck(void)
65 extern void goStackCheck(void);
66 goStackCheck();
69 int
70 returnAfterGrow(void)
72 extern int goReturnVal(void);
73 goReturnVal();
74 return 123456;
77 int
78 returnAfterGrowFromGo(void)
80 extern int goReturnVal(void);
81 return goReturnVal();
84 void
85 callGoWithString(void)
87 extern void goWithString(GoString);
88 const char *str = "string passed from C to Go";
89 goWithString((GoString){str, strlen(str)});