From 7ff762e4afcea5668dab3b08e80e330d8a25333c Mon Sep 17 00:00:00 2001 From: Brenden Matthews Date: Mon, 4 Jan 2010 19:20:47 -0800 Subject: [PATCH] Resolve issues with timed_thread rewrite WIP. --- cmake/ConkyBuildOptions.cmake | 2 +- src/c-funcs.c | 48 ----------------------------------- src/c-funcs.h | 45 -------------------------------- src/common.cc | 2 +- src/exec.cc | 4 +-- src/linux.cc | 18 ++++++------- src/mail.cc | 2 +- src/timed_thread.cc | 14 +++++----- src/timed_thread.h | 2 +- 9 files changed, 23 insertions(+), 114 deletions(-) delete mode 100644 src/c-funcs.c delete mode 100644 src/c-funcs.h diff --git a/cmake/ConkyBuildOptions.cmake b/cmake/ConkyBuildOptions.cmake index d7b247f5..3911ef43 100644 --- a/cmake/ConkyBuildOptions.cmake +++ b/cmake/ConkyBuildOptions.cmake @@ -39,7 +39,7 @@ set(CMAKE_CXX_FLAGS "-std=c++0x" CACHE STRING "Flags used by the C++ compiler du if(MAINTAINER_MODE) # some extra debug flags when in 'maintainer mode' set(CMAKE_C_FLAGS_DEBUG "-ggdb -Wall -W -Wextra -Wunused -Wdeclaration-after-statement -Wundef -Wendif-labels -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-qual -Wcast-align -Wwrite-strings -Wstrict-prototypes -Wold-style-definition -Winline -Wmissing-noreturn -Wmissing-format-attribute -Wredundant-decls -pedantic -Werror" CACHE STRING "Flags used by the compiler during debug builds." FORCE) - set(CMAKE_CXX_FLAGS_DEBUG "-ggdb -Wall -W -Wextra -Wunused -pedantic -Werror" CACHE STRING "Flags used by the compiler during debug builds." FORCE) + set(CMAKE_CXX_FLAGS_DEBUG "-ggdb -Wall -W -Wextra -Wunused -pedantic -Werror -Wno-format" CACHE STRING "Flags used by the compiler during debug builds." FORCE) endif(MAINTAINER_MODE) diff --git a/src/c-funcs.c b/src/c-funcs.c deleted file mode 100644 index 987a7c97..00000000 --- a/src/c-funcs.c +++ /dev/null @@ -1,48 +0,0 @@ -/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- - * vim: ts=4 sw=4 noet ai cindent syntax=c - * - * Conky, a system monitor, based on torsmo - * - * Please see COPYING for details - * - * Copyright (c) 2005-2010 Brenden Matthews, et. al. (see AUTHORS) - * All rights reserved. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#include "c-funcs.h" -#include -#include - -int sscanf_c(const char *__restrict s, const char *__restrict format, ...) -{ - int ret; - va_list ap; - va_start(ap, format); - ret = vsscanf(s, format, ap); - va_end(ap); - return ret; -} - -int snprintf_c(char *__restrict s, size_t maxlen, const char *__restrict - format, ...) -{ - int ret; - va_list ap; - va_start(ap, format); - ret = vsnprintf(s, maxlen, format, ap); - va_end(ap); - return ret; -} diff --git a/src/c-funcs.h b/src/c-funcs.h deleted file mode 100644 index a5cf113a..00000000 --- a/src/c-funcs.h +++ /dev/null @@ -1,45 +0,0 @@ -/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- - * vim: ts=4 sw=4 noet ai cindent syntax=c - * - * Conky, a system monitor, based on torsmo - * - * Please see COPYING for details - * - * Copyright (c) 2005-2010 Brenden Matthews, et. al. (see AUTHORS) - * All rights reserved. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#ifndef _c_funcs_h_ -#define _c_funcs_h_ - -#ifdef __cplusplus -extern "C" { -#endif - -/* these functions provide a workaround for a problem in g++ claiming to not - * support long longs with these functions */ - -int sscanf_c(const char *__restrict s, const char *__restrict format, ...); - -int snprintf_c(char *__restrict s, size_t maxlen, const char *__restrict format, - ...); - -#ifdef __cplusplus -} -#endif - -#endif /* _c_funcs_h_ */ - diff --git a/src/common.cc b/src/common.cc index ca6d0e1d..35c044ee 100644 --- a/src/common.cc +++ b/src/common.cc @@ -337,7 +337,7 @@ static void __free_update_callbacks(struct update_cb *uc) sem_destroy(&uc->start_wait); sem_destroy(&uc->end_wait); - free(uc); + delete uc; } /* Free the whole list of update callbacks. */ diff --git a/src/exec.cc b/src/exec.cc index b81cbea2..ad7f79de 100644 --- a/src/exec.cc +++ b/src/exec.cc @@ -48,7 +48,7 @@ struct execi_data { double data; timed_thread_ptr p_timed_thread; float barnum; - execi_data() : last_update(0), interval(0), cmd(0), data(0), barnum(0) {} + execi_data() : last_update(0), interval(0), cmd(0), buffer(0), data(0), barnum(0) {} }; /* FIXME: this will probably not work, since the variable is being reused @@ -408,6 +408,6 @@ void free_execi(struct text_object *obj) free(ed->cmd); if (ed->buffer) free(ed->buffer); - free(obj->data.opaque); + delete ed; obj->data.opaque = NULL; } diff --git a/src/linux.cc b/src/linux.cc index 8e2ba689..234258e5 100644 --- a/src/linux.cc +++ b/src/linux.cc @@ -175,17 +175,17 @@ void update_meminfo(void) } if (strncmp(buf, "MemTotal:", 9) == 0) { - sscanf_c(buf, "%*s %llu", &info.memmax); + sscanf(buf, "%*s %llu", &info.memmax); } else if (strncmp(buf, "MemFree:", 8) == 0) { - sscanf_c(buf, "%*s %llu", &info.memfree); + sscanf(buf, "%*s %llu", &info.memfree); } else if (strncmp(buf, "SwapTotal:", 10) == 0) { - sscanf_c(buf, "%*s %llu", &info.swapmax); + sscanf(buf, "%*s %llu", &info.swapmax); } else if (strncmp(buf, "SwapFree:", 9) == 0) { - sscanf_c(buf, "%*s %llu", &info.swapfree); + sscanf(buf, "%*s %llu", &info.swapfree); } else if (strncmp(buf, "Buffers:", 8) == 0) { - sscanf_c(buf, "%*s %llu", &info.buffers); + sscanf(buf, "%*s %llu", &info.buffers); } else if (strncmp(buf, "Cached:", 7) == 0) { - sscanf_c(buf, "%*s %llu", &info.cached); + sscanf(buf, "%*s %llu", &info.cached); } } @@ -418,7 +418,7 @@ void update_net_stats(void) last_trans = ns->trans; /* bytes packets errs drop fifo frame compressed multicast|bytes ... */ - sscanf_c(p, "%lld %*d %*d %*d %*d %*d %*d %*d %lld", + sscanf(p, "%lld %*d %*d %*d %*d %*d %*d %*d %lld", &r, &t); /* if recv or trans is less than last time, an overflow happened */ @@ -641,7 +641,7 @@ void determine_longstat(char *buf) KFLAG_SETOFF(KFLAG_IS_LONGSTAT); /* scanf will either return -1 or 1 because there is only 1 assignment */ - if (sscanf_c(buf, "%*s %*d %*d %*d %*d %llu", &iowait) > 0) { + if (sscanf(buf, "%*s %*d %*d %*d %*d %llu", &iowait) > 0) { KFLAG_SETON(KFLAG_IS_LONGSTAT); } } @@ -750,7 +750,7 @@ void update_stat(void) } else { idx = 0; } - sscanf_c(buf, stat_template, &(cpu[idx].cpu_user), + sscanf(buf, stat_template, &(cpu[idx].cpu_user), &(cpu[idx].cpu_nice), &(cpu[idx].cpu_system), &(cpu[idx].cpu_idle), &(cpu[idx].cpu_iowait), &(cpu[idx].cpu_irq), &(cpu[idx].cpu_softirq), diff --git a/src/mail.cc b/src/mail.cc index a230b66f..e171e1dd 100644 --- a/src/mail.cc +++ b/src/mail.cc @@ -84,7 +84,7 @@ struct mail_s { // for imap and pop3 user[0] = 0; pass[0] = 0; command[0] = 0; - folder[0] = 0; + memset(folder, 0, 128); /* to satisfy valgrind */ } }; diff --git a/src/timed_thread.cc b/src/timed_thread.cc index d4e7a30f..db91b80c 100644 --- a/src/timed_thread.cc +++ b/src/timed_thread.cc @@ -52,6 +52,7 @@ struct _timed_thread { clk::time_point last_time; /* last time interval */ int pipefd[2]; int die; + _timed_thread() : die(0) {} }; typedef std::list thread_list_t; @@ -90,11 +91,11 @@ timed_thread::timed_thread(const std::function &start_rou } /* destroy a timed thread. */ -void timed_thread::destroy(void) +void timed_thread::destroy(bool deregister_this) { DBGP("destroying thread %ld", (long)p_timed_thread->thread.get()); #ifdef DEBUG - assert(running); + assert(running && p_timed_thread->thread->joinable()); #endif /* DEBUG */ { /* signal thread to stop */ @@ -111,10 +112,11 @@ void timed_thread::destroy(void) close(p_timed_thread->pipefd[0]); close(p_timed_thread->pipefd[1]); - - deregister(this); - + running = false; + + if (deregister_this) deregister(this); + } /* lock a timed thread for critical section activity */ @@ -234,7 +236,7 @@ void timed_thread::deregister(const timed_thread *timed_thread) void timed_thread::destroy_registered_threads(void) { for (thread_list_t::iterator i = thread_list.begin(); i != thread_list.end(); i++) { - (*i)->destroy(); +// (*i)->destroy(false /* don't deregister */); #ifdef DEBUG /* if this assert is ever reached, we have an unreleased shared_ptr * somewhere holding on to this instance */ diff --git a/src/timed_thread.h b/src/timed_thread.h index 23b72b42..0574a545 100644 --- a/src/timed_thread.h +++ b/src/timed_thread.h @@ -101,7 +101,7 @@ class timed_thread { int test(int override_wait_time); /* destroy a timed thread */ - void destroy(void); + void destroy(bool deregister_this = true); /* register a timed thread for destruction */ static int register_(const timed_thread_ptr &timed_thread);