mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-13 13:42:30 +00:00
* Moved Timer to rak/timer.h.
* Added position affinity to ChunkSelector, still needs more work to make it move forward without needing to finish all pieces. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@604 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -8,10 +8,8 @@ libsub_utils_a_SOURCES = \
|
||||
list_focus.h \
|
||||
parse.cc \
|
||||
parse.h \
|
||||
task.h \
|
||||
task_item.h \
|
||||
task_scheduler.cc \
|
||||
task_scheduler.h \
|
||||
timer.h
|
||||
task_scheduler.h
|
||||
|
||||
INCLUDES = -I$(srcdir) -I$(srcdir)/.. -I$(top_srcdir)
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
// rTorrent - BitTorrent library
|
||||
// Copyright (C) 2005, Jari Sundell
|
||||
//
|
||||
// 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 2 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, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// In addition, as a special exception, the copyright holders give
|
||||
// permission to link the code of portions of this program with the
|
||||
// OpenSSL library under certain conditions as described in each
|
||||
// individual source file, and distribute linked combinations
|
||||
// including the two.
|
||||
//
|
||||
// You must obey the GNU General Public License in all respects for
|
||||
// all of the code used other than OpenSSL. If you modify file(s)
|
||||
// with this exception, you may extend this exception to your version
|
||||
// of the file(s), but you are not obligated to do so. If you do not
|
||||
// wish to do so, delete this exception statement from your version.
|
||||
// If you delete this exception statement from all source files in the
|
||||
// program, then also delete it here.
|
||||
//
|
||||
// Contact: Jari Sundell <jaris@ifi.uio.no>
|
||||
//
|
||||
// Skomakerveien 33
|
||||
// 3185 Skoppum, NORWAY
|
||||
|
||||
#ifndef RTORRENT_UTILS_TASK_H
|
||||
#define RTORRENT_UTILS_TASK_H
|
||||
|
||||
#include "task_scheduler.h"
|
||||
|
||||
namespace utils {
|
||||
|
||||
extern TaskScheduler taskScheduler;
|
||||
extern TaskScheduler displayScheduler;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -38,18 +38,17 @@
|
||||
#define RTORRENT_UTILS_TASK_ITEM_H
|
||||
|
||||
#include <list>
|
||||
#include <rak/timer.h>
|
||||
#include <sigc++/slot.h>
|
||||
|
||||
#include "utils/timer.h"
|
||||
|
||||
namespace utils {
|
||||
|
||||
// The user is responsible for removing TaskItem from the TaskScheduler.
|
||||
|
||||
class TaskItem {
|
||||
public:
|
||||
typedef sigc::slot<void> Slot;
|
||||
typedef std::list<std::pair<Timer, TaskItem*> >::iterator iterator;
|
||||
typedef sigc::slot<void> Slot;
|
||||
typedef std::list<std::pair<rak::timer, TaskItem*> >::iterator iterator;
|
||||
|
||||
TaskItem(Slot s = Slot()) : m_slot(s) {}
|
||||
|
||||
@@ -60,7 +59,7 @@ public:
|
||||
const iterator get_iterator() const { return m_iterator; }
|
||||
void set_iterator(iterator itr) { m_iterator = itr; }
|
||||
|
||||
const Timer& get_time() const { return m_iterator->first; }
|
||||
const rak::timer& get_time() const { return m_iterator->first; }
|
||||
|
||||
private:
|
||||
TaskItem(const TaskItem& t);
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
namespace utils {
|
||||
|
||||
void
|
||||
TaskScheduler::insert(TaskItem* task, Timer time) {
|
||||
TaskScheduler::insert(TaskItem* task, rak::timer time) {
|
||||
if (is_scheduled(task))
|
||||
throw std::logic_error("TaskScheduler::insert(...) tried to insert an already inserted or invalid TaskItem");
|
||||
|
||||
@@ -74,7 +74,7 @@ TaskScheduler::erase(TaskItem* task) {
|
||||
}
|
||||
|
||||
void
|
||||
TaskScheduler::execute(Timer time) {
|
||||
TaskScheduler::execute(rak::timer time) {
|
||||
m_entry = std::find_if(begin(), end(), rak::less(time, rak::mem_ptr_ref(&value_type::first)));
|
||||
|
||||
// Since we are always using the front rather than a splice of the
|
||||
|
||||
@@ -41,9 +41,9 @@
|
||||
|
||||
namespace utils {
|
||||
|
||||
class TaskScheduler : private std::list<std::pair<Timer, TaskItem*> > {
|
||||
class TaskScheduler : private std::list<std::pair<rak::timer, TaskItem*> > {
|
||||
public:
|
||||
typedef std::list<std::pair<Timer, TaskItem*> > Base;
|
||||
typedef std::list<std::pair<rak::timer, TaskItem*> > Base;
|
||||
|
||||
using Base::value_type;
|
||||
using Base::reference;
|
||||
@@ -60,14 +60,14 @@ public:
|
||||
|
||||
TaskScheduler() : m_entry(begin()) {}
|
||||
|
||||
void insert(TaskItem* task, Timer time);
|
||||
void insert(TaskItem* task, rak::timer time);
|
||||
void erase(TaskItem* task);
|
||||
|
||||
void execute(Timer time);
|
||||
void execute(rak::timer time);
|
||||
|
||||
bool is_scheduled(const TaskItem* task) const { return task->get_iterator() != end(); }
|
||||
|
||||
Timer get_next_timeout() const { return begin()->first; }
|
||||
rak::timer get_next_timeout() const { return begin()->first; }
|
||||
|
||||
private:
|
||||
iterator m_entry;
|
||||
|
||||
@@ -1,98 +0,0 @@
|
||||
// rTorrent - BitTorrent client
|
||||
// Copyright (C) 2005, Jari Sundell
|
||||
//
|
||||
// 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 2 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, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// In addition, as a special exception, the copyright holders give
|
||||
// permission to link the code of portions of this program with the
|
||||
// OpenSSL library under certain conditions as described in each
|
||||
// individual source file, and distribute linked combinations
|
||||
// including the two.
|
||||
//
|
||||
// You must obey the GNU General Public License in all respects for
|
||||
// all of the code used other than OpenSSL. If you modify file(s)
|
||||
// with this exception, you may extend this exception to your version
|
||||
// of the file(s), but you are not obligated to do so. If you do not
|
||||
// wish to do so, delete this exception statement from your version.
|
||||
// If you delete this exception statement from all source files in the
|
||||
// program, then also delete it here.
|
||||
//
|
||||
// Contact: Jari Sundell <jaris@ifi.uio.no>
|
||||
//
|
||||
// Skomakerveien 33
|
||||
// 3185 Skoppum, NORWAY
|
||||
|
||||
#ifndef RTORRENT_UTILS_TIMER_H
|
||||
#define RTORRENT_UTILS_TIMER_H
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
namespace utils {
|
||||
|
||||
// Don't convert negative Timer to timeval and then back to Timer, that will bork.
|
||||
class Timer {
|
||||
public:
|
||||
Timer() : m_time(0) {}
|
||||
Timer(int64_t usec) : m_time(usec) {}
|
||||
Timer(timeval tv) : m_time((int64_t)(uint32_t)tv.tv_sec * 1000000 + (int64_t)(uint32_t)tv.tv_usec % 1000000) {}
|
||||
|
||||
int32_t seconds() const { return m_time / 1000000; }
|
||||
int64_t usec() const { return m_time; }
|
||||
|
||||
Timer round_seconds() const { return (m_time / 1000000) * 1000000; }
|
||||
|
||||
timeval tval() const { return (timeval) { m_time / 1000000, m_time % 1000000}; }
|
||||
|
||||
static Timer current();
|
||||
|
||||
// Cached time, updated in the beginning of torrent::work call.
|
||||
// Don't use outside socket_base read/write/except or Service::service.
|
||||
static Timer cache() { return Timer(m_cache); }
|
||||
|
||||
static void update() { m_cache = Timer::current().usec(); }
|
||||
|
||||
bool operator < (const Timer& t) const { return m_time < t.m_time; }
|
||||
bool operator > (const Timer& t) const { return m_time > t.m_time; }
|
||||
bool operator <= (const Timer& t) const { return m_time <= t.m_time; }
|
||||
bool operator >= (const Timer& t) const { return m_time >= t.m_time; }
|
||||
|
||||
Timer operator - (const Timer& t) const { return Timer(m_time - t.m_time); }
|
||||
Timer operator + (const Timer& t) const { return Timer(m_time + t.m_time); }
|
||||
|
||||
Timer operator -= (int64_t t) { m_time -= t; return *this; }
|
||||
Timer operator -= (const Timer& t) { m_time -= t.m_time; return *this; }
|
||||
|
||||
Timer operator += (int64_t t) { m_time += t; return *this; }
|
||||
Timer operator += (const Timer& t) { m_time += t.m_time; return *this; }
|
||||
|
||||
private:
|
||||
int64_t m_time;
|
||||
|
||||
// Instantiated in torrent.cc
|
||||
static int64_t m_cache;
|
||||
};
|
||||
|
||||
inline Timer
|
||||
Timer::current() {
|
||||
timeval t;
|
||||
gettimeofday(&t, 0);
|
||||
|
||||
return Timer(t);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user