mirror of
https://github.com/Llewellynvdm/conky.git
synced 2025-01-27 09:08:25 +00:00
Resolve issues with timed_thread rewrite WIP.
This commit is contained in:
parent
620e9876a4
commit
7ff762e4af
@ -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)
|
||||
|
||||
|
||||
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "c-funcs.h"
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
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;
|
||||
}
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#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_ */
|
||||
|
@ -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. */
|
||||
|
@ -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;
|
||||
}
|
||||
|
18
src/linux.cc
18
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),
|
||||
|
@ -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 */
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -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<timed_thread_ptr> thread_list_t;
|
||||
@ -90,11 +91,11 @@ timed_thread::timed_thread(const std::function<void(thread_handle &)> &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 */
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user