Fix inifinite recursion in lvar-constants.
[sbcl.git] / src / runtime / runtime.h
blob1c99e02ffa5b78d6d5e578ef5f89a371dc54fc5f
1 /*
2 * This software is part of the SBCL system. See the README file for
3 * more information.
5 * This software is derived from the CMU CL system, which was
6 * written at Carnegie Mellon University and released into the
7 * public domain. The software is in the public domain and is
8 * provided with absolutely no warranty. See the COPYING and CREDITS
9 * files for more information.
12 #ifndef _SBCL_RUNTIME_H_
13 #define _SBCL_RUNTIME_H_
15 #include "lispobj.h"
17 #ifdef LISP_FEATURE_WIN32
18 # include "pthreads_win32.h"
19 #else
20 # include <signal.h>
21 # ifdef LISP_FEATURE_SB_THREAD
22 # include <pthread.h>
23 # endif
24 #endif
26 #include <stdint.h>
27 #include <inttypes.h>
29 #if defined(LISP_FEATURE_SB_THREAD)
31 #ifdef LISP_FEATURE_WIN32
32 #define thread_sigmask sb_pthread_sigmask
33 // wrap CriticalSection operators in a function returning 1 to satisfy assertions
34 static inline int cs_mutex_lock(void* l) { EnterCriticalSection(l); return 1; }
35 static inline int cs_mutex_unlock(void* l) { LeaveCriticalSection(l); return 1; }
36 #define mutex_acquire(l) cs_mutex_lock(l)
37 #define mutex_release(l) cs_mutex_unlock(l)
38 #define CONDITION_VAR_WAIT(x,y) SleepConditionVariableCS(x,y,INFINITE)
39 #define CONDITION_VAR_WAKE_ALL(x) WakeAllConditionVariable(x)
40 #else
41 #define thread_self() pthread_self()
42 #define thread_equal(a,b) pthread_equal(a,b)
43 #define thread_sigmask pthread_sigmask
44 #define mutex_acquire(l) !pthread_mutex_lock(l)
45 #define mutex_release(l) !pthread_mutex_unlock(l)
46 #define TryEnterCriticalSection(l) !pthread_mutex_trylock(l)
47 #define CONDITION_VAR_WAIT(x,y) pthread_cond_wait(x,y)
48 #define CONDITION_VAR_WAKE_ALL(x) pthread_cond_broadcast(x)
49 #endif
51 #else
52 // not SB_THREAD
53 #define thread_self() 0
54 #define thread_equal(a,b) ((a)==(b))
55 #define thread_sigmask sigprocmask
56 #define mutex_acquire(l) 1
57 #define mutex_release(l) 1
58 #define TryEnterCriticalSection(l) 1
59 #endif
61 #if defined(LISP_FEATURE_SB_SAFEPOINT)
63 typedef enum {
64 GC_NONE=0,
65 GC_FLIGHT,
66 GC_MESSAGE,
67 GC_INVOKED,
68 GC_QUIET,
69 GC_SETTLED,
70 GC_COLLECT,
71 GC_NPHASES
72 } gc_phase_t;
74 void map_gc_page();
75 void unmap_gc_page();
76 void gc_state_lock();
77 void gc_state_wait(gc_phase_t);
78 int gc_cycle_active(void);
79 void gc_state_unlock();
81 #define WITH_GC_STATE_LOCK \
82 gc_state_lock(); \
83 RUN_BODY_ONCE(gc_state_lock, gc_state_unlock())
85 #endif
88 * Configuration options end here -- the following defines do not
89 * generally need customization.
92 /* Flags defined in a structure to avoid code duplication between
93 * declaration and definition. */
94 extern struct dyndebug_config {
95 int dyndebug_gencgc_verbose;
96 int dyndebug_safepoints;
97 int dyndebug_seh;
98 int dyndebug_misc;
99 int dyndebug_pagefaults;
100 int dyndebug_backtrace_when_lost;
101 int dyndebug_sleep_when_lost;
102 int dyndebug_io;
103 int dyndebug_runtime_link;
104 } dyndebug_config;
106 void dyndebug_init(void);
108 #include <sys/types.h>
110 #define OBJ_FMTX PRIxPTR
112 #include "align.h"
114 /* KLUDGE: As far as I can tell there's no ANSI C way of saying
115 * "this function never returns". This is the way that you do it
116 * in GCC later than version 2.5 or so. */
117 #if defined(__GNUC__)
118 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5)
119 #define never_returns __attribute__ ((noreturn))
120 #else
121 #define never_returns
122 #endif
123 #else
124 #define never_returns
125 #endif
127 extern void *successful_malloc (size_t size);
128 extern char *copied_string (char *string);
130 void *os_dlsym_default(char *name); // Why not in 'os.h' ?
132 /* Even with just -O1, gcc optimizes the jumps in this "loop" away
133 * entirely, giving the ability to define WITH-FOO-style macros. */
134 #define RUN_BODY_ONCE(prefix, finally_do) \
135 int prefix##done = 0; \
136 for (; !prefix##done; finally_do, prefix##done = 1)
138 // casting to void is no longer enough to suppress a warning about unused
139 // results of libc functions declared with warn_unused_result.
140 // from http://git.savannah.gnu.org/cgit/gnulib.git/tree/lib/ignore-value.h
141 #if 3 < __GNUC__ + (4 <= __GNUC_MINOR__)
142 # define ignore_value(x) \
143 (__extension__ ({ __typeof__ (x) __x = (x); (void) __x; }))
144 #else
145 # define ignore_value(x) ((void) (x))
146 #endif
148 #if defined(__GNUC__) && defined(ADDRESS_SANITIZER)
149 #define NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address))
150 #else
151 #define NO_SANITIZE_ADDRESS
152 #endif
154 #if defined(__GNUC__) && defined(MEMORY_SANITIZER)
155 #define NO_SANITIZE_MEMORY __attribute__((no_sanitize_memory))
156 #else
157 #define NO_SANITIZE_MEMORY
158 #endif
160 #endif /* _SBCL_RUNTIME_H_ */