* src/vm/exceptions.c (exceptions_handle_exception): Use LLNI macro for
[cacao.git] / src / vm / system.c
1 /* src/vm/system.c - system (OS) functions
2
3    Copyright (C) 2007
4    CACAOVM - Verein zu Foerderung der freien virtuellen Machine CACAO
5
6    This file is part of CACAO.
7
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2, or (at
11    your option) any later version.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23 */
24
25
26 #include "config.h"
27
28 #include <stdint.h>
29 #include <unistd.h>
30
31 #if defined(__DARWIN__)
32 # include <mach/mach.h>
33 # include <mach/mach_host.h>
34 # include <mach/host_info.h>
35 #endif
36
37 /* this should work on BSD */
38 /* #include <sys/sysctl.h> */
39
40
41 /* system_processors_online ****************************************************
42
43    Returns the number of online processors in the system.
44
45    RETURN:
46        online processor count
47
48 *******************************************************************************/
49
50 int system_processors_online(void)
51 {
52 #if defined(_SC_NPROC_ONLN)
53
54         return (int) sysconf(_SC_NPROC_ONLN);
55
56 #elif defined(_SC_NPROCESSORS_ONLN)
57
58         return (int) sysconf(_SC_NPROCESSORS_ONLN);
59
60 #elif defined(__DARWIN__)
61
62         host_basic_info_data_t hinfo;
63         mach_msg_type_number_t hinfo_count = HOST_BASIC_INFO_COUNT;
64         kern_return_t rc;
65
66         rc = host_info(mach_host_self(), HOST_BASIC_INFO,
67                                    (host_info_t) &hinfo, &hinfo_count);
68  
69         if (rc != KERN_SUCCESS) {
70                 return -1;
71         }
72
73         /* XXX michi: according to my infos this should be
74            hinfo.max_cpus, can someone please confirm or deny that? */
75         return (int) hinfo.avail_cpus;
76
77 #elif defined(__FREEBSD__)
78 # error IMPLEMENT ME!
79
80         /* this should work in BSD */
81         /*
82         int ncpu, mib[2], rc;
83         size_t len;
84
85         mib[0] = CTL_HW;
86         mib[1] = HW_NCPU;
87         len = sizeof(ncpu);
88         rc = sysctl(mib, 2, &ncpu, &len, NULL, 0);
89
90         return (int32_t) ncpu;
91         */
92
93 #else
94
95         return 1;
96
97 #endif
98 }
99
100
101 /*
102  * These are local overrides for various environment variables in Emacs.
103  * Please do not remove this and leave it at the end of the file, where
104  * Emacs will automagically detect them.
105  * ---------------------------------------------------------------------
106  * Local variables:
107  * mode: c
108  * indent-tabs-mode: t
109  * c-basic-offset: 4
110  * tab-width: 4
111  * End:
112  * vim:noexpandtab:sw=4:ts=4:
113  */