summaryrefslogtreecommitdiff
path: root/cpus.h
diff options
context:
space:
mode:
authorDaniel Borkmann <dborkman@redhat.com>2013-06-12 12:45:49 +0200
committerDaniel Borkmann <dborkman@redhat.com>2013-06-12 12:45:49 +0200
commitc0d19330c7df0a441545942e7ac87721c718edf4 (patch)
tree4b0a4d844dfbfdeedefbda2bf176c58e1862382e /cpus.h
parent4ee9acd587161df26332fc1e07027b1b527e8100 (diff)
cpus: let it always return an unsigned int and bail out on error
In case of an error, just panic, to make sure we always get a val >= 1. Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Diffstat (limited to 'cpus.h')
-rw-r--r--cpus.h20
1 files changed, 16 insertions, 4 deletions
diff --git a/cpus.h b/cpus.h
index d672daa..0626726 100644
--- a/cpus.h
+++ b/cpus.h
@@ -2,15 +2,27 @@
#define CPUS_H
#include <unistd.h>
+#include "built_in.h"
+#include "die.h"
-static inline int get_number_cpus(void)
+static inline unsigned int get_number_cpus(void)
{
- return sysconf(_SC_NPROCESSORS_CONF);
+ int ret = sysconf(_SC_NPROCESSORS_CONF);
+
+ if (unlikely(ret <= 0))
+ panic("get_number_cpus error!\n");
+
+ return ret;
}
-static inline int get_number_cpus_online(void)
+static inline unsigned int get_number_cpus_online(void)
{
- return sysconf(_SC_NPROCESSORS_ONLN);
+ int ret = sysconf(_SC_NPROCESSORS_ONLN);
+
+ if (unlikely(ret <= 0))
+ panic("get_number_cpus_online error!\n");
+
+ return ret;
}
#endif /* CPUS_H */