2 * This software is part of the SBCL system. See the README file for
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_
17 #ifdef LISP_FEATURE_WIN32
18 # include "pthreads_win32.h"
21 # ifdef LISP_FEATURE_SB_THREAD
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)
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)
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
61 #if defined(LISP_FEATURE_SB_SAFEPOINT)
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 \
83 RUN_BODY_ONCE(gc_state_lock, gc_state_unlock())
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
;
99 int dyndebug_pagefaults
;
100 int dyndebug_backtrace_when_lost
;
101 int dyndebug_sleep_when_lost
;
103 int dyndebug_runtime_link
;
106 void dyndebug_init(void);
108 #include <sys/types.h>
110 #define OBJ_FMTX PRIxPTR
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))
121 #define never_returns
124 #define never_returns
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; }))
145 # define ignore_value(x) ((void) (x))
148 #if defined(__GNUC__) && defined(ADDRESS_SANITIZER)
149 #define NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address))
151 #define NO_SANITIZE_ADDRESS
154 #if defined(__GNUC__) && defined(MEMORY_SANITIZER)
155 #define NO_SANITIZE_MEMORY __attribute__((no_sanitize_memory))
157 #define NO_SANITIZE_MEMORY
160 #endif /* _SBCL_RUNTIME_H_ */