* g++.dg/pph/c120060625-1.cc: New.
[official-gcc.git] / libgo / runtime / runtime.h
blobbf07c1219bab55436fd10f1a1d8ae0998342505f
1 /* runtime.h -- runtime support for Go.
3 Copyright 2009 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. */
7 #include "config.h"
9 #define _GNU_SOURCE
10 #include "go-assert.h"
11 #include <signal.h>
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include <sys/types.h>
16 #include <sys/stat.h>
17 #include <fcntl.h>
18 #include <pthread.h>
19 #include <semaphore.h>
21 #ifdef HAVE_SYS_MMAN_H
22 #include <sys/mman.h>
23 #endif
25 #include "go-alloc.h"
26 #include "go-panic.h"
27 #include "go-string.h"
29 typedef struct __go_string String;
31 /* This file supports C files copied from the 6g runtime library.
32 This is a version of the 6g runtime.h rewritten for gccgo's version
33 of the code. */
35 typedef signed int int8 __attribute__ ((mode (QI)));
36 typedef unsigned int uint8 __attribute__ ((mode (QI)));
37 typedef signed int int16 __attribute__ ((mode (HI)));
38 typedef unsigned int uint16 __attribute__ ((mode (HI)));
39 typedef signed int int32 __attribute__ ((mode (SI)));
40 typedef unsigned int uint32 __attribute__ ((mode (SI)));
41 typedef signed int int64 __attribute__ ((mode (DI)));
42 typedef unsigned int uint64 __attribute__ ((mode (DI)));
43 typedef float float32 __attribute__ ((mode (SF)));
44 typedef double float64 __attribute__ ((mode (DF)));
45 typedef unsigned int uintptr __attribute__ ((mode (pointer)));
47 /* Defined types. */
49 typedef uint8 bool;
50 typedef uint8 byte;
51 typedef struct M M;
52 typedef struct MCache MCache;
53 typedef struct Lock Lock;
55 /* We use mutexes for locks. 6g uses futexes directly, and perhaps
56 someday we will do that too. */
58 struct Lock
60 uint32 key;
61 sem_t sem;
64 /* A Note. */
66 typedef struct Note Note;
68 struct Note {
69 int32 woken;
72 /* Per CPU declarations. */
74 #ifdef __rtems__
75 #define __thread
76 #endif
78 extern __thread M* m;
80 extern M m0;
82 #ifdef __rtems__
83 #undef __thread
84 #endif
86 /* Constants. */
88 enum
90 true = 1,
91 false = 0,
94 /* Structures. */
96 struct M
98 int32 mallocing;
99 int32 gcing;
100 int32 locks;
101 int32 nomemprof;
102 int32 gcing_for_prof;
103 int32 holds_finlock;
104 int32 gcing_for_finlock;
105 int32 profilehz;
106 MCache *mcache;
108 /* For the list of all threads. */
109 struct __go_thread_id *list_entry;
111 /* For the garbage collector. */
112 void *gc_sp;
113 size_t gc_len;
114 void *gc_next_segment;
115 void *gc_next_sp;
116 void *gc_initial_sp;
117 struct __go_panic_defer_struct *gc_panic_defer;
120 /* Macros. */
121 #define nelem(x) (sizeof(x)/sizeof((x)[0]))
122 #define nil ((void*)0)
123 #define USED(v) ((void) v)
125 /* We map throw to assert. */
126 #define runtime_throw(s) __go_assert(s == 0)
128 void* runtime_mal(uintptr);
129 void runtime_mallocinit(void);
130 void runtime_initfintab(void);
131 void siginit(void);
132 bool __go_sigsend(int32 sig);
133 int64 runtime_nanotime(void);
135 void runtime_stoptheworld(void);
136 void runtime_starttheworld(void);
137 void __go_go(void (*pfn)(void*), void*);
138 void __go_gc_goroutine_init(void*);
139 void __go_enable_gc(void);
140 int __go_run_goroutine_gc(int);
141 void __go_scanstacks(void (*scan)(byte *, int64));
142 void __go_stealcache(void);
143 void __go_cachestats(void);
146 * mutual exclusion locks. in the uncontended case,
147 * as fast as spin locks (just a few user-level instructions),
148 * but on the contention path they sleep in the kernel.
150 void runtime_initlock(Lock*);
151 void runtime_lock(Lock*);
152 void runtime_unlock(Lock*);
153 void runtime_destroylock(Lock*);
155 void semacquire (uint32 *) asm ("libgo_runtime.runtime.Semacquire");
156 void semrelease (uint32 *) asm ("libgo_runtime.runtime.Semrelease");
159 * sleep and wakeup on one-time events.
160 * before any calls to notesleep or notewakeup,
161 * must call noteclear to initialize the Note.
162 * then, any number of threads can call notesleep
163 * and exactly one thread can call notewakeup (once).
164 * once notewakeup has been called, all the notesleeps
165 * will return. future notesleeps will return immediately.
167 void runtime_noteclear(Note*);
168 void runtime_notesleep(Note*);
169 void runtime_notewakeup(Note*);
171 /* Functions. */
172 #define runtime_printf printf
173 #define runtime_malloc(s) __go_alloc(s)
174 #define runtime_free(p) __go_free(p)
175 #define runtime_memclr(buf, size) __builtin_memset((buf), 0, (size))
176 #define runtime_strcmp(s1, s2) __builtin_strcmp((s1), (s2))
177 #define runtime_getenv(s) getenv(s)
178 #define runtime_atoi(s) atoi(s)
179 #define runtime_mcmp(a, b, s) __builtin_memcmp((a), (b), (s))
180 #define runtime_memmove(a, b, s) __builtin_memmove((a), (b), (s))
181 MCache* runtime_allocmcache(void);
182 void free(void *v);
183 struct __go_func_type;
184 void runtime_addfinalizer(void*, void(*fn)(void*), const struct __go_func_type *);
185 void runtime_walkfintab(void (*fn)(void*), void (*scan)(byte *, int64));
186 #define runtime_mmap mmap
187 #define runtime_munmap(p, s) munmap((p), (s))
188 #define runtime_cas(pval, old, new) __sync_bool_compare_and_swap (pval, old, new)
189 #define runtime_casp(pval, old, new) __sync_bool_compare_and_swap (pval, old, new)
191 void runtime_sigprof(uint8 *pc, uint8 *sp, uint8 *lr);
192 void runtime_cpuprofinit(void);
193 void runtime_resetcpuprofiler(int32);
194 void runtime_setcpuprofilerate(void(*)(uintptr*, int32), int32);
196 struct __go_func_type;
197 void reflect_call(const struct __go_func_type *, const void *, _Bool, _Bool,
198 void **, void **)
199 asm ("libgo_reflect.reflect.call");
201 #ifdef __rtems__
202 void __wrap_rtems_task_variable_add(void **);
203 #endif