4 * Copyright 2004, 2005 Develer S.r.l. (http://www.develer.com/)
5 * This file is part of DevLib - See README.devlib for information.
8 * \brief OS-specific definitions
12 * \author Bernardo Innocenti <bernie@develer.com>
17 *#* Revision 1.9 2006/03/22 13:34:34 bernie
20 *#* Revision 1.8 2006/02/23 09:09:28 bernie
21 *#* Remove Linux specific hack.
23 *#* Revision 1.7 2006/02/20 01:46:59 bernie
26 *#* Revision 1.6 2006/02/15 09:12:33 bernie
27 *#* Don't mask useful user signals on UNIX.
29 *#* Revision 1.5 2005/11/27 23:32:42 bernie
30 *#* Add CPU fallback for OS_ID.
32 *#* Revision 1.4 2005/11/27 03:07:13 bernie
33 *#* IRQ_SAVE_DISABLE(): Really block signals.
35 *#* Revision 1.3 2005/11/27 03:02:40 bernie
36 *#* Add POSIX emulation for IRQ_* macros; Add Qt support.
38 *#* Revision 1.2 2005/11/04 16:20:01 bernie
39 *#* Fix reference to README.devlib in header.
41 *#* Revision 1.1 2005/04/11 19:04:13 bernie
42 *#* Move top-level headers to cfg/ subdir.
44 *#* Revision 1.1 2004/12/31 17:40:24 bernie
45 *#* Add OS detection code.
51 /*! Macro to include OS-specific versions of the headers. */
52 #define OS_HEADER(module) PP_STRINGIZE(PP_CAT3(module, _, OS_ID).h)
53 #define OS_CSOURCE(module) PP_STRINGIZE(PP_CAT3(module, _, OS_ID).c)
56 * OS autodetection (Some systems trigger multiple OS definitions)
62 // FIXME: Maybe disable Win32 exceptions?
63 typedef int cpuflags_t;
64 #define IRQ_DISABLE /* FIXME */
65 #define IRQ_ENABLE /* FIXME */
66 #define IRQ_SAVE_DISABLE(old_sigs) /* FIXME */
67 #define IRQ_RESTORE(old_sigs) /* FIXME */
73 #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
75 #define OS_POSIX 1 /* Not strictly UNIX, but no way to autodetect it. */
79 * The POSIX moral equivalent of disabling IRQs is disabling signals.
82 typedef sigset_t cpuflags_t;
84 #define SET_ALL_SIGNALS(sigs) \
87 sigdelset(&sigs, SIGINT); \
88 sigdelset(&sigs, SIGSTOP); \
89 sigdelset(&sigs, SIGCONT); \
95 SET_ALL_SIGNALS(sigs); \
96 sigprocmask(SIG_BLOCK, &sigs, NULL); \
102 SET_ALL_SIGNALS(sigs); \
103 sigprocmask(SIG_UNBLOCK, &sigs, NULL); \
106 #define IRQ_SAVE_DISABLE(old_sigs) \
109 SET_ALL_SIGNALS(sigs); \
110 sigprocmask(SIG_BLOCK, &sigs, &old_sigs); \
113 #define IRQ_RESTORE(old_sigs) \
115 sigprocmask(SIG_SETMASK, &old_sigs, NULL); \
128 #if defined(__APPLE__) && defined(__MACH__)
135 * We want Qt and other frameworks to look like OSes because you would
136 * tipically want their portable abstractions if you're using one of these.
147 * Summarize hosted environments as OS_HOSTED and embedded
148 * environment with OS_EMBEDDED.
150 #if OS_WIN32 || OS_UNIX || OS_DARWIN
152 #define OS_EMBEDDED 0
155 #define OS_EMBEDDED 1
157 /* Embedded environments fall back to CPU-specific code. */
161 /* Self-check for the detection */
163 #error OS_ID not defined
165 #if OS_HOSTED && OS_EMBEDDED
166 #error Both hosted and embedded OS environment
168 #if !OS_HOSTED && !OS_EMBEDDED
169 #error Neither hosted nor embedded OS environment
172 #endif /* DEVLIB_OS_H */