--- wmfire-1.2.4/src/wmfire.c.orig 2005-12-04 11:39:16.000000000 +0100 +++ wmfire-1.2.4/src/wmfire.c 2012-02-27 15:48:05.136807354 +0100 @@ -63,6 +63,10 @@ #define FIRE_NET 3 #define FIRE_FILE 4 +/* wbk 20120220 - cleaning up "next cpu" logic */ +#define CPU_AV -1 /* needs to be 1st CPU - 1 */ +#define CPU_NEXT -2 /* arbitrary but must be < CPU_AV */ + #define NET_SPD_PPP 56 #define NET_SPD_ETH 100 @@ -104,7 +108,8 @@ int update_mem(); int update_net(); int update_file(); -int change_cpu(int); +void change_cpu(int); +int more_cpus(); void change_flame(int); GdkCursor *setup_cursor(); void burn_spot(int, int, int); @@ -130,8 +135,7 @@ int monitor = FIRE_CPU; int load = 100; -int cpu_av = 1; -int cpu_id = 0; +int cpu_id = CPU_AV; /* wbk - special value instead of separate flag */ int cpu_nice = 1; char net_dev[16] = "ppp0"; int net_spd = 0; @@ -224,8 +228,15 @@ next = 0; if (!lock) { - if (monitor == FIRE_CPU && change_cpu(-1)) - monitor = FIRE_MEM; + if (monitor == FIRE_CPU) + { + /* First, check if we have more CPU's to monitor. If none, * + * move along to FIRE_MEM. Regardless, after this check, we * + * call change_cpu() to increment or reset CPU number. */ + if (!more_cpus()) + monitor = FIRE_MEM; + change_cpu(CPU_NEXT); + } else if (monitor == FIRE_MEM) monitor = FIRE_NET; else if (monitor == FIRE_NET) @@ -285,7 +296,7 @@ glibtop_get_cpu(&cpu); - if (cpu_av) { + if (cpu_id == CPU_AV) { if (cpu_nice) load = cpu.user + cpu.nice + cpu.sys; else @@ -383,30 +394,46 @@ /* Change CPU monitor */ /******************************************/ -int +void change_cpu(int which) { - glibtop_cpu cpu; + /* wbk 20120221 - Changed return type to void. Use more_cpus() * + * for tests instead. Mixing test logic with changing the CPU * + * was causing CPU's to be skipped in calling function. */ + /* wbk - Even though we never use the cpu struct, I think this * + * call may be necessary to set up glibtop_global_server? */ + glibtop_cpu cpu; glibtop_get_cpu(&cpu); /* This should work, but I have a lonely uniprocessor system */ + /* wbk - tested with a quad core. */ - if (which >= 0) { + if (which != CPU_NEXT) /* was run with command-line CPU specifier */ cpu_id = which; - cpu_av = 0; - } else { - cpu_id++; - cpu_av = 0; - } + else /* negative value "special case" for which */ + cpu_id++; - if (cpu_id >= glibtop_global_server->ncpu || cpu_id >= GLIBTOP_NCPU) { - cpu_id = 0; - cpu_av = 1; - return 1; - } + /* Since we already incremented cpu_id, we are comparing a * + * 1-index with 0-index value essentially. But since GLIBTOP_NCPU * + * is 1-indexed, keep >= for it. (a bit of an oversimplification: * + * cpu_id is still definitely regarded as 0-indexed elsewhere. We * + * index an array with it later, so this is important) */ + if (cpu_id > glibtop_global_server->ncpu || cpu_id >= GLIBTOP_NCPU) + cpu_id = CPU_AV; - return 0; + return; +} + +int +more_cpus() +{ + /* returns positive if next CPU would be valid, Negative if * + * already monitoring highest-numbered CPU or if more cores than * + * glibtop supports. */ + int next_cpu = cpu_id + 1; + return !(next_cpu > glibtop_global_server->ncpu + || next_cpu >= GLIBTOP_NCPU); } /******************************************/ @@ -494,7 +521,7 @@ if (proximity++ > 100) { if (monitor == FIRE_CPU) { - if (cpu_av) { + if (cpu_id == CPU_AV) { /* Horizontal bar for average cpu */ memset(&bm.cmap[27 * XMAX + 20], 255, 16); memset(&bm.cmap[28 * XMAX + 20], 255, 16);