1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-17 18:45:10 +00:00

update callback objects can now signal termination with a write to a pipe as well

This commit is contained in:
Pavel Labath 2011-02-27 00:17:53 +01:00
parent bcfc90accb
commit 3c7f2192b2
3 changed files with 16 additions and 4 deletions

View File

@ -24,7 +24,7 @@
#ifndef CPPWRAP_HH
#define CPPWRAP_HH
#include <unistd.h>
#include <fcntl.h>
#include <cerrno>
#include <stdexcept>

View File

@ -39,9 +39,15 @@ namespace conky {
if(thread) {
done = true;
sem_start.post();
if(pipefd.second >= 0)
write(pipefd.second, "X", 1);
thread->join();
delete thread;
}
if(pipefd.first >= 0)
close(pipefd.first);
if(pipefd.second >= 0)
close(pipefd.second);
}
inline size_t callback_base::get_hash(const handle &h)

View File

@ -32,6 +32,7 @@
#include <assert.h>
#include "c++wrap.hh"
#include "semaphore.hh"
namespace conky {
@ -55,6 +56,7 @@ namespace conky {
const size_t hash;
uint32_t period;
uint32_t remaining;
std::pair<int, int> pipefd;
const bool wait;
bool done;
uint8_t unused;
@ -83,11 +85,15 @@ namespace conky {
friend void conky::run_all_callbacks();
protected:
callback_base(size_t hash_, uint32_t period_, bool wait_)
: thread(NULL), hash(hash_), period(period_), remaining(0), wait(wait_),
done(false), unused(0)
callback_base(size_t hash_, uint32_t period_, bool wait_, bool use_pipe = false)
: thread(NULL), hash(hash_), period(period_), remaining(0),
pipefd(use_pipe ? pipe2(O_CLOEXEC) : std::pair<int, int>(-1, -1)),
wait(wait_), done(false), unused(0)
{}
int donefd()
{ return pipefd.first; }
// to be implemented by descendant classes
virtual void work() = 0;