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.6 2006/02/15 09:12:33 bernie
18 *#* Don't mask useful user signals on UNIX.
20 *#* Revision 1.5 2005/11/27 23:32:42 bernie
21 *#* Add CPU fallback for OS_ID.
23 *#* Revision 1.4 2005/11/27 03:07:13 bernie
24 *#* IRQ_SAVE_DISABLE(): Really block signals.
26 *#* Revision 1.3 2005/11/27 03:02:40 bernie
27 *#* Add POSIX emulation for IRQ_* macros; Add Qt support.
29 *#* Revision 1.2 2005/11/04 16:20:01 bernie
30 *#* Fix reference to README.devlib in header.
32 *#* Revision 1.1 2005/04/11 19:04:13 bernie
33 *#* Move top-level headers to cfg/ subdir.
35 *#* Revision 1.1 2004/12/31 17:40:24 bernie
36 *#* Add OS detection code.
42 /*! Macro to include OS-specific versions of the headers. */
43 #define OS_HEADER(module) PP_STRINGIZE(PP_CAT3(module, _, OS_ID).h)
44 #define OS_CSOURCE(module) PP_STRINGIZE(PP_CAT3(module, _, OS_ID).c)
47 * OS autodetection (Some systems trigger multiple OS definitions)
58 #define OS_POSIX 1 /* Not strictly UNIX, but no way to autodetect it. */
62 * The POSIX moral equivalent of disabling IRQs is disabling signals.
64 // #define _XOPEN_SOURCE 600 /* Avoid BSDish stuff */
65 // #undef _GNU_SOURCE /* This implies _BSD_SOURCE and is predefined on Linux. */
67 typedef sigset_t cpuflags_t;
69 #define SET_ALL_SIGNALS(sigs) \
72 sigdelset(&sigs, SIGINT); \
73 sigdelset(&sigs, SIGSTOP); \
74 sigdelset(&sigs, SIGCONT); \
80 SET_ALL_SIGNALS(sigs); \
81 sigprocmask(SIG_BLOCK, &sigs, NULL); \
87 SET_ALL_SIGNALS(sigs); \
88 sigprocmask(SIG_UNBLOCK, &sigs, NULL); \
91 #define IRQ_SAVE_DISABLE(old_sigs) \
94 SET_ALL_SIGNALS(sigs); \
95 sigprocmask(SIG_BLOCK, &sigs, &old_sigs); \
98 #define IRQ_RESTORE(old_sigs) \
100 sigprocmask(SIG_SETMASK, &old_sigs, NULL); \
113 #if defined(__APPLE__) && defined(__MACH__)
120 * We want Qt and other frameworks to look like OSes because you would
121 * tipically want their portable abstractions if you're using one of these.
132 * Summarize hosted environments as OS_HOSTED and embedded
133 * environment with OS_EMBEDDED.
135 #if OS_WIN32 || OS_UNIX
137 #define OS_EMBEDDED 0
140 #define OS_EMBEDDED 1
142 /* Embedded environments fall back to CPU-specific code. */
146 /* Self-check for the detection */
148 #error OS_ID not defined
150 #if OS_HOSTED && OS_EMBEDDED
151 #error Both hosted and embedded OS environment
153 #if !OS_HOSTED && !OS_EMBEDDED
154 #error Neither hosted nor embedded OS environment
157 #endif /* DEVLIB_OS_H */