Permalink
Browse files

Remove timed_thread code as it is no longer used.

  • Loading branch information...
1 parent f3dfb21 commit 75e147fa254b3a59e6385bdd1a45459527cf829e @labath labath committed Mar 26, 2011
Showing with 3 additions and 397 deletions.
  1. +1 −1 COPYING
  2. +2 −3 doc/docs.xml
  3. +0 −4 src/CMakeLists.txt
  4. +0 −3 src/conky.cc
  5. +0 −1 src/mail.cc
  6. +0 −1 src/moc.cc
  7. +0 −1 src/mpd.cc
  8. +0 −262 src/timed-thread.cc
  9. +0 −121 src/timed-thread.h
View
@@ -2,7 +2,7 @@ Any original torsmo code is licensed under the BSD license (see LICENSE.BSD
for a copy)
All code written since the fork of torsmo is licensed under the GPL (see
-LICENSE.GPL for a copy), except where noted differently (such as in portmon code, timed thread code, and audacious code which are LGPL, and prss which is an MIT-style license).
+LICENSE.GPL for a copy), except where noted differently (such as in portmon and audacious code which are LGPL, and prss which is an MIT-style license).
Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
Copyright (c) 2005-2010 Brenden Matthews, Philip Kovacs, et. al. (see AUTHORS)
View
@@ -308,9 +308,8 @@
the BSD license (see LICENSE.BSD for a copy). All code
written since the fork of torsmo is licensed under the GPL
(see LICENSE.GPL for a copy), except where noted
- differently (such as in portmon code, timed thread code,
- and audacious code which are LGPL, and prss which is an
- MIT-style license).</para>
+ differently (such as in portmon and audacious code which are LGPL, and
+ prss which is an MIT-style license).</para>
</refsect1>
<refsect1>
<title>Authors</title>
View
@@ -40,10 +40,6 @@ set(conky_sources c++wrap.cc colours.cc combine.cc common.cc conky.cc core.cc
temphelper.cc text_object.cc timeinfo.cc top.cc algebra.cc prioqueue.cc proc.cc
user.cc luamm.cc data-source.cc lua-config.cc setting.cc llua.cc update-cb.cc)
-# add timed thread library
-add_library(timed-thread timed-thread.cc)
-set(conky_libs ${conky_libs} timed-thread)
-
# Platform specific sources
if(OS_LINUX)
set(linux linux.cc users.cc sony.cc i8k.cc)
View
@@ -32,7 +32,6 @@
#include "text_object.h"
#include "conky.h"
#include "common.h"
-#include "timed-thread.h"
#include <iostream>
#include <algorithm>
#include <sstream>
@@ -2548,8 +2547,6 @@ void clean_up_without_threads(void *memtofree1, void* memtofree2)
free_and_zero(memtofree1);
free_and_zero(memtofree2);
- timed_thread::destroy_registered_threads();
-
free_and_zero(info.cpu_usage);
#ifdef BUILD_X11
if(out_to_x.get(*state))
View
@@ -36,7 +36,6 @@
#include "common.h"
#include "logging.h"
#include "text_object.h"
-#include "timed-thread.h"
#include <errno.h>
#include <stdio.h>
View
@@ -24,7 +24,6 @@
#include "conky.h"
#include "logging.h"
#include "text_object.h"
-#include "timed-thread.h"
#include <stdio.h>
#include <stdlib.h>
View
@@ -31,7 +31,6 @@
#include <mutex>
#include "conky.h"
#include "logging.h"
-#include "timed-thread.h"
#include "timeinfo.h"
#include "libmpdclient.h"
#include "mpd.h"
View
@@ -1,262 +0,0 @@
-/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
- * vim: ts=4 sw=4 noet ai cindent syntax=cpp
- *
- * timed_thread.c: Abstraction layer for timed threads
- *
- * Copyright (C) 2006-2007 Philip Kovacs pkovacs@users.sourceforge.net
- * Copyright (c) 2005-2010 Brenden Matthews, et. al. (see AUTHORS)
- * All rights reserved.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
- * USA.
- *
- */
-
-#include <config.h>
-
-#include <thread>
-#include <list>
-#include <assert.h>
-#include <errno.h>
-#include <stdio.h>
-#include <time.h>
-#include <unistd.h>
-#include "timed-thread.h"
-#include "logging.h"
-
-/*
- * In gcc-4.5 condition_variable::wait_until returns a (strong) enum cv_status.
- * In gcc-4.4 it returns bool.
- * This hack is needed so it can work on both.
- */
-#if __GNUC__*100 + __GNUC_MINOR__ >= 405
-inline bool cv_status_to_bool(std::cv_status s)
-{ return s == std::cv_status::no_timeout; }
-#else
-inline bool cv_status_to_bool(bool s)
-{ return s; }
-#endif
-
-/* Abstraction layer for timed threads */
-
-typedef struct std::chrono::system_clock clk;
-using std::chrono::duration_cast;
-
-/* private */
-struct _timed_thread {
- std::auto_ptr<std::thread> thread; /* thread itself */
- std::mutex cs_mutex; /* critical section mutex */
- std::mutex runnable_mutex; /* runnable section mutex */
- std::condition_variable runnable_cond; /* signalled to stop the 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;
-thread_list_t thread_list;
-
-/* create a timed thread (object creation only) */
-timed_thread::timed_thread(const std::function<void(thread_handle &)> &start_routine,
- std::chrono::microseconds interval_usecs) :
- p_timed_thread(new _timed_thread), p_thread_handle(this),
- interval_usecs(interval_usecs), running(false)
-{
-
-#ifdef DEBUG
- assert(interval_usecs >= std::chrono::microseconds(MINIMUM_INTERVAL_USECS));
-#endif /* DEBUG */
-
- /* create thread pipe (used to tell threads to die) */
- if (pipe(p_timed_thread->pipefd)) {
- throw std::runtime_error("couldn't create pipe");
- }
-
- /* set initialize to current time */
- p_timed_thread->last_time = clk::now();
-
- /* printf("interval_time.tv_sec = %li, .tv_nsec = %li\n",
- p_timed_thread->interval_time.tv_sec,
- p_timed_thread->interval_time.tv_nsec); */
-
- p_timed_thread->thread = std::auto_ptr<std::thread>(
- new std::thread(start_routine, p_thread_handle)
- );
-
- DBGP("created thread %ld", (long)p_timed_thread->thread.get());
-
- running = true;
-}
-
-/* destroy a timed thread. */
-void timed_thread::destroy()
-{
- DBGP("destroying thread %ld", (long)p_timed_thread->thread.get());
-#ifdef DEBUG
- assert(running && p_timed_thread->thread->joinable());
-#endif /* DEBUG */
- {
- /* signal thread to stop */
- std::lock_guard<std::mutex> l(p_timed_thread->runnable_mutex);
- p_timed_thread->runnable_cond.notify_one();
- p_timed_thread->die = 1;
- }
-
- if (write(p_timed_thread->pipefd[1], "die", 3) == -1)
- perror("write()");
-
- /* join the terminating thread */
- p_timed_thread->thread->join();
-
- close(p_timed_thread->pipefd[0]);
- close(p_timed_thread->pipefd[1]);
-
- running = false;
-}
-
-/* lock a timed thread for critical section activity */
-void timed_thread::lock(void)
-{
-#ifdef DEBUG
- assert(running);
-#endif /* DEBUG */
- p_timed_thread->cs_mutex.lock();
-}
-
-/* unlock a timed thread after critical section activity */
-void timed_thread::unlock(void)
-{
-#ifdef DEBUG
- assert(running);
-#endif /* DEBUG */
- p_timed_thread->cs_mutex.unlock();
-}
-
-std::mutex &timed_thread::mutex()
-{
-#ifdef DEBUG
- assert(running);
-#endif /* DEBUG */
- return p_timed_thread->cs_mutex;
-}
-
-int timed_thread::readfd(void) const
-{
-#ifdef DEBUG
- assert(running);
-#endif /* DEBUG */
- return p_timed_thread->pipefd[0];
-}
-
-/* thread waits interval_usecs for runnable_cond to be signaled.
- * returns 1 if signaled, -1 on error, and 0 otherwise.
- * caller should call timed_thread::exit() on any non-zero return value. */
-int timed_thread::test(int override_wait_time)
-{
-#ifdef DEBUG
- assert(running);
-#endif /* DEBUG */
- bool rc = false;
- /* determine when to wait until */
- clk::time_point wait_time = p_timed_thread->last_time + duration_cast<clk::duration>(interval_usecs);
-
- /* acquire runnable_cond mutex */
- {
- std::unique_lock<std::mutex> lock(p_timed_thread->runnable_mutex);
-
- if (p_timed_thread->die) {
- /* if we were kindly asked to die, then die */
- return 1;
- }
-
- if (override_wait_time) {
- wait_time = clk::now();
- }
-
- /* release mutex and wait until future time for runnable_cond to signal */
- rc = cv_status_to_bool( p_timed_thread->runnable_cond.wait_until(lock, wait_time) );
- }
-
- p_timed_thread->last_time = clk::now();
- if (wait_time + duration_cast<clk::duration>(interval_usecs) > p_timed_thread->last_time) {
- p_timed_thread->last_time = wait_time;
- }
-
- /* if runnable_cond was signaled, tell caller to exit thread */
- return rc;
-}
-
-/* register a timed thread for future destruction via
- * timed_thread::destroy_registered_threads() */
-int timed_thread::register_(const timed_thread_ptr &timed_thread)
-{
- thread_list.push_back(timed_thread);
- return 0;
-}
-
-
-void timed_thread::deregister(const timed_thread *timed_thread)
-{
- for (thread_list_t::iterator i = thread_list.begin(); i != thread_list.end(); i++) {
- if (i->get() == timed_thread) {
- thread_list.erase(i);
- break;
- }
- }
-}
-
-/* destroy all registered timed threads */
-void timed_thread::destroy_registered_threads(void)
-{
- for (thread_list_t::iterator i = thread_list.begin(); i != thread_list.end(); i++) {
-// (*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 */
- assert(i->unique());
-#endif /* DEBUG */
- }
- thread_list.clear(); /* that was easy */
-}
-
-int thread_handle::test(int override_wait_time) {
- return thread->test(override_wait_time);
-}
-
-std::mutex &thread_handle::mutex()
-{
-#ifdef DEBUG
- assert(thread->running);
-#endif /* DEBUG */
- return thread->p_timed_thread->cs_mutex;
-}
-
-void thread_handle::lock(void) {
- thread->lock();
-}
-
-void thread_handle::unlock(void) {
- thread->unlock();
-}
-
-int thread_handle::readfd(void) const
-{
-#ifdef DEBUG
- assert(thread->running);
-#endif /* DEBUG */
- return thread->p_timed_thread->pipefd[0];
-}
-
Oops, something went wrong.

0 comments on commit 75e147f

Please sign in to comment.