aboutsummaryrefslogtreecommitdiff
path: root/src/gb
diff options
context:
space:
mode:
authorZac Pierson <zacpiersonhehe@gmail.com>2017-02-08 11:50:33 -0600
committerZac Pierson <zacpiersonhehe@gmail.com>2017-02-08 11:50:33 -0600
commit72d4bfb32aae5890cbf60d7d2f038ece098e31dc (patch)
treed689876ceb55bec2247a04daa4d8cc1c5b6e5d9b /src/gb
parent37f7630a9eab8476199229e26b5b628cf73ff11d (diff)
parent454d0b5cf5b109fda01b3380b1fab0434d7ff51d (diff)
Merge https://github.com/gingerBill/Odin
Diffstat (limited to 'src/gb')
-rw-r--r--src/gb/gb.h57
1 files changed, 31 insertions, 26 deletions
diff --git a/src/gb/gb.h b/src/gb/gb.h
index 8ff378ae0..9f9e850fc 100644
--- a/src/gb/gb.h
+++ b/src/gb/gb.h
@@ -58,6 +58,7 @@ TODOS
- More date & time functions
VERSION HISTORY
+ 0.27 - OSX fixes and Linux gbAffinity
0.26d - Minor changes to how gbFile works
0.26c - gb_str_to_f* fix
0.26b - Minor fixes
@@ -4990,16 +4991,13 @@ isize gb_affinity_thread_count_for_core(gbAffinity *a, isize core) {
}
#elif defined(GB_SYSTEM_LINUX)
-#warning gbAffinity is mostly mostly untested on Linux. All I know is that it compiles and runs.
-#warning TODO(bill): gb_affinity_set on Linux is a stub
-
-// I have to read /proc/cpuinfo to get the number of threads per core.
+// IMPORTANT TODO(bill): This gbAffinity stuff for linux needs be improved a lot!
+// NOTE(zangent): I have to read /proc/cpuinfo to get the number of threads per core.
#include <stdio.h>
void gb_affinity_init(gbAffinity *a) {
- usize count, count_size = gb_size_of(count);
-
- b32 accurate = true;
+ b32 accurate = true;
+ isize threads = 0;
a->thread_count = 1;
a->core_count = sysconf(_SC_NPROCESSORS_ONLN);
@@ -5012,37 +5010,43 @@ void gb_affinity_init(gbAffinity *a) {
}
// Parsing /proc/cpuinfo to get the number of threads per core.
- // NOTE: This calls the CPU's threads "cores", although the wording
- // is kind of weird. This should be right, though.
- FILE* cpu_info = fopen("/proc/cpuinfo", "r");
-
- int threads = 0;
-
- if(cpu_info) {
- while(1) {
+ // NOTE(zangent): This calls the CPU's threads "cores", although the wording
+ // is kind of weird. This should be right, though.
+ if (fopen("/proc/cpuinfo", "r") != NULL) {
+ for (;;) {
// The 'temporary char'. Everything goes into this char,
// so that we can check against EOF at the end of this loop.
char c;
- #define check(letter) ((c = getc(cpu_info)) == letter)
- if(check('c') && check('p') && check('u') && check(' ') &&
- check('c') && check('o') && check('r') && check('e') && check('s')) {
+#define AF__CHECK(letter) ((c = getc(cpu_info)) == letter)
+ if (AF__CHECK('c') && AF__CHECK('p') && AF__CHECK('u') && AF__CHECK(' ') &&
+ AF__CHECK('c') && AF__CHECK('o') && AF__CHECK('r') && AF__CHECK('e') && AF__CHECK('s')) {
// We're on a CPU info line.
- while(!check(EOF)) {
- if(c == '\n') break;
- else if(c < '0' || c > '9') continue;
+ while (!AF__CHECK(EOF)) {
+ if (c == '\n') {
+ break;
+ } else if (c < '0' || '9' > c) {
+ continue;
+ }
threads = threads * 10 + (c - '0');
}
break;
} else {
- while(!check('\n')) {if(c==EOF) break;}
+ while (!AF__CHECK('\n')) {
+ if (c==EOF) {
+ break;
+ }
+ }
}
- if(c == EOF) break;
+ if (c == EOF) {
+ break;
+ }
+#undef AF__CHECK
}
}
- if(threads == 0) {
- threads = 1;
+ if (threads == 0) {
+ threads = 1;
accurate = false;
}
@@ -5062,7 +5066,8 @@ b32 gb_affinity_set(gbAffinity *a, isize core, isize thread_index) {
}
isize gb_affinity_thread_count_for_core(gbAffinity *a, isize core) {
- GB_ASSERT(core >= 0 && core < a->core_count);
+
+ GB_ASSERT(0 <= core && core < a->core_count);
return a->threads_per_core;
}
#else