Skip to content

Commit

Permalink
Cleanup macro and introduce a no-op free_cpu() function for ALL cpu-r…
Browse files Browse the repository at this point in the history
…elated variables

free_cpu() must be implemented for every OS and on all except macOS its a no-op function.
  • Loading branch information
npyl authored and brndnmtthws committed Aug 7, 2018
1 parent ce06769 commit 03abfc6
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ uint8_t battery_percentage(struct text_object *);
void print_battery_short(struct text_object *, char *, int);
#endif /* !__OpenBSD__ */

void free_cpu(struct text_object *);

void print_blink(struct text_object *, char *, int);
void print_include(struct text_object *, char *, int);

Expand Down
14 changes: 4 additions & 10 deletions src/core.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,6 @@
#include "darwin.h"
#endif

#if defined (__APPLE__) && defined (__MACH__)
#define DARWIN_DEALLOCATE_CPU_SAMPLE obj->callbacks.free = &deallocate_cpu_sample;
#else
#define DARWIN_DEALLOCATE_CPU_SAMPLE
#endif

#include <cctype>
#include <cstring>

Expand Down Expand Up @@ -680,21 +674,21 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
END OBJ(cpu, &update_cpu_usage) get_cpu_count();
SCAN_CPU(arg, obj->data.i);
obj->callbacks.percentage = &cpu_percentage;
DARWIN_DEALLOCATE_CPU_SAMPLE
obj->callbacks.free = &free_cpu;
DBGP2("Adding $cpu for CPU %d", obj->data.i);
#ifdef BUILD_X11
END OBJ(cpugauge, &update_cpu_usage) get_cpu_count();
SCAN_CPU(arg, obj->data.i);
scan_gauge(obj, arg, 1);
obj->callbacks.gaugeval = &cpu_barval;
DARWIN_DEALLOCATE_CPU_SAMPLE
obj->callbacks.free = &free_cpu;
DBGP2("Adding $cpugauge for CPU %d", obj->data.i);
#endif
END OBJ(cpubar, &update_cpu_usage) get_cpu_count();
SCAN_CPU(arg, obj->data.i);
scan_bar(obj, arg, 1);
obj->callbacks.barval = &cpu_barval;
DARWIN_DEALLOCATE_CPU_SAMPLE
obj->callbacks.free = &free_cpu;
DBGP2("Adding $cpubar for CPU %d", obj->data.i);
#ifdef BUILD_X11
END OBJ(cpugraph, &update_cpu_usage) get_cpu_count();
Expand All @@ -704,7 +698,7 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
DBGP2("Adding $cpugraph for CPU %d", obj->data.i);
free_and_zero(buf);
obj->callbacks.graphval = &cpu_barval;
DARWIN_DEALLOCATE_CPU_SAMPLE
obj->callbacks.free = &free_cpu;
END OBJ(loadgraph, &update_load_average) scan_loadgraph_arg(obj, arg);
obj->callbacks.graphval = &loadgraphval;
#endif /* BUILD_X11 */
Expand Down
2 changes: 1 addition & 1 deletion src/darwin.mm
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ void allocate_cpu_sample(struct cpusample **sample) {
sample_handle = *sample; /* use a public handle for deallocating */
}

void deallocate_cpu_sample(struct text_object *obj) {
void free_cpu(struct text_object *) {
if (sample_handle != nullptr) {
free(sample_handle);
sample_handle = nullptr;
Expand Down
3 changes: 3 additions & 0 deletions src/dragonfly.cc
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,9 @@ int update_cpu_usage(void) {
return 0;
}

void free_cpu(struct text_object *) {
}

int update_load_average(void) {
double v[3];

Expand Down
3 changes: 3 additions & 0 deletions src/freebsd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,9 @@ int update_cpu_usage(void) {
return 0;
}

void free_cpu(struct text_object *) {
}

int update_load_average(void) {
double v[3];

Expand Down
3 changes: 3 additions & 0 deletions src/haiku.cc
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ int update_cpu_usage() {
return 1;
}

void free_cpu(struct text_object *) {
}

int update_load_average() {
// TODO
return 1;
Expand Down
3 changes: 3 additions & 0 deletions src/linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,9 @@ int update_cpu_usage(void) {
return 0;
}

void free_cpu(struct text_object *) {
}

// fscanf() that reads floats with points even if you are using a locale where
// floats are with commas
int fscanf_no_i18n(FILE *stream, const char *format, ...) {
Expand Down
3 changes: 3 additions & 0 deletions src/netbsd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ void update_cpu_usage() {
oldtotal = total;
}

void free_cpu(struct text_object *) {
}

void update_load_average() {
double v[3];

Expand Down
3 changes: 3 additions & 0 deletions src/openbsd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,9 @@ void update_cpu_usage() {
#endif
}

void free_cpu(struct text_object *) {
}

void update_load_average() {
double v[3];

Expand Down
3 changes: 3 additions & 0 deletions src/solaris.cc
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,9 @@ int update_cpu_usage(void) {
return 0;
}

void free_cpu(struct text_object *) {
}

void update_proc_entry(struct process *p) {
psinfo_t proc;
int fd;
Expand Down

0 comments on commit 03abfc6

Please sign in to comment.