Merge branch 'master' into c++11

This commit is contained in:
Jari Sundell
2011-12-27 15:50:01 +09:00
10 changed files with 35 additions and 60 deletions
+4 -3
View File
@@ -29,9 +29,10 @@ TORRENT_WITHOUT_NCURSESW()
TORRENT_WITHOUT_STATVFS() TORRENT_WITHOUT_STATVFS()
TORRENT_WITHOUT_STATFS() TORRENT_WITHOUT_STATFS()
ACX_PTHREAD(CXXFLAGS="$CXXFLAGS $PTHREAD_CFLAGS"; ACX_PTHREAD()
LIBS="$PTHREAD_LIBS $LIBS" CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
) CXXFLAGS="$CXXFLAGS $PTHREAD_CFLAGS"
LIBS="$PTHREAD_LIBS $LIBS"
PKG_CHECK_MODULES(sigc, sigc++-2.0, PKG_CHECK_MODULES(sigc, sigc++-2.0,
CXXFLAGS="$CXXFLAGS $sigc_CFLAGS"; CXXFLAGS="$CXXFLAGS $sigc_CFLAGS";
+2 -2
View File
@@ -849,8 +849,8 @@ initialize_command_download() {
// std::bind(&core::Download::main, std::placeholders::_1)), // std::bind(&core::Download::main, std::placeholders::_1)),
// CG_GROUP_INDEX())); // CG_GROUP_INDEX()));
CMD2_DL ("d.group", std::bind(&cg_d_group, std::placeholders::_1));; CMD2_DL ("d.group", std::bind(&cg_d_group, std::placeholders::_1));
CMD2_DL ("d.group.name", std::bind(&cg_d_group, std::placeholders::_1));; CMD2_DL ("d.group.name", std::bind(&cg_d_group, std::placeholders::_1));
CMD2_DL_V ("d.group.set", std::bind(&cg_d_group_set, std::placeholders::_1, std::placeholders::_2)); CMD2_DL_V ("d.group.set", std::bind(&cg_d_group_set, std::placeholders::_1, std::placeholders::_2));
CMD2_DL ("d.initialize_logs", std::bind(&cmd_d_initialize_logs, std::placeholders::_1)); CMD2_DL ("d.initialize_logs", std::bind(&cmd_d_initialize_logs, std::placeholders::_1));
+2 -2
View File
@@ -38,7 +38,7 @@
#include <stdexcept> #include <stdexcept>
#include <unistd.h> #include <unistd.h>
#include <rak/error_number.h> #include <torrent/exceptions.h>
#include <torrent/poll_epoll.h> #include <torrent/poll_epoll.h>
#include <torrent/poll_kqueue.h> #include <torrent/poll_kqueue.h>
#include <torrent/poll_select.h> #include <torrent/poll_select.h>
@@ -85,7 +85,7 @@ create_poll() {
log->push_front("Using 'select' based polling."); log->push_front("Using 'select' based polling.");
else else
throw std::runtime_error("Could not create any Poll object."); throw torrent::internal_error("Could not create any Poll object.");
return poll; return poll;
} }
+4 -4
View File
@@ -37,12 +37,12 @@
#ifndef RTORRENT_CORE_POLL_MANAGER_H #ifndef RTORRENT_CORE_POLL_MANAGER_H
#define RTORRENT_CORE_POLL_MANAGER_H #define RTORRENT_CORE_POLL_MANAGER_H
#include <rak/timer.h>
#include <sigc++/signal.h>
#include <torrent/poll.h>
#include "curl_stack.h" #include "curl_stack.h"
namespace torrent {
class Poll;
}
namespace core { namespace core {
torrent::Poll* create_poll(); torrent::Poll* create_poll();
+1 -1
View File
@@ -112,7 +112,7 @@ TextElementValueBase::print(char* first, char* last, Canvas::attributes_list* at
if (u == NULL) if (u == NULL)
return first; return first;
first += std::min<ptrdiff_t>(std::max(snprintf(first, last - first + 1, "%02u/%02u/%04u", u->tm_mday, (u->tm_mon + 1), (1900 + u->tm_year)), 0), last - first + 1);; first += std::min<ptrdiff_t>(std::max(snprintf(first, last - first + 1, "%02u/%02u/%04u", u->tm_mday, (u->tm_mon + 1), (1900 + u->tm_year)), 0), last - first + 1);
} else if (m_flags & flag_time) { } else if (m_flags & flag_time) {
time_t t = val; time_t t = val;
+2
View File
@@ -46,6 +46,7 @@
#include <torrent/http.h> #include <torrent/http.h>
#include <torrent/torrent.h> #include <torrent/torrent.h>
#include <torrent/exceptions.h> #include <torrent/exceptions.h>
#include <torrent/poll.h>
#include <torrent/data/chunk_utils.h> #include <torrent/data/chunk_utils.h>
#include <torrent/utils/log.h> #include <torrent/utils/log.h>
#include <rak/functional.h> #include <rak/functional.h>
@@ -193,6 +194,7 @@ main(int argc, char** argv) {
// to process new non-socket events. // to process new non-socket events.
SignalHandler::set_handler(SIGUSR1, sigc::ptr_fun(&do_nothing)); SignalHandler::set_handler(SIGUSR1, sigc::ptr_fun(&do_nothing));
torrent::Poll::slot_create_poll() = std::tr1::bind(&core::create_poll);
torrent::initialize(main_thread->poll()); torrent::initialize(main_thread->poll());
// Initialize option handlers after libtorrent to ensure // Initialize option handlers after libtorrent to ensure
+1 -1
View File
@@ -63,7 +63,7 @@ public:
static fixed_key_type from_string(const std::string& str) { fixed_key_type k; k.set_c_str(str.c_str(), str.size()); return k; } static fixed_key_type from_string(const std::string& str) { fixed_key_type k; k.set_c_str(str.c_str(), str.size()); return k; }
static fixed_key_type from_raw_string(const torrent::raw_string& str) { fixed_key_type k; k.set_data(str.data(), str.size()); return k; } static fixed_key_type from_raw_string(const torrent::raw_string& str) { fixed_key_type k; k.set_data(str.data(), str.size()); return k; }
bool empty() const { return m_size == 0;; } bool empty() const { return m_size == 0; }
size_type size() const { return m_size; } size_type size() const { return m_size; }
iterator begin() const { return m_data; } iterator begin() const { return m_data; }
+15 -40
View File
@@ -82,7 +82,7 @@ public:
throw torrent::internal_error("Overflowed thread_queue."); throw torrent::internal_error("Overflowed thread_queue.");
__sync_bool_compare_and_swap(itr, NULL, v); __sync_bool_compare_and_swap(itr, NULL, v);
__sync_bool_compare_and_swap(&m_lock, 1, 0); unlock();
} }
value_type* copy_and_clear(value_type* dest) { value_type* copy_and_clear(value_type* dest) {
@@ -117,55 +117,21 @@ ThreadBase::~ThreadBase() {
delete m_threadQueue; delete m_threadQueue;
} }
void // Move to libtorrent...
ThreadBase::start_thread() {
if (m_state != STATE_INITIALIZED ||
pthread_create(&m_thread, NULL, (pthread_func)&ThreadBase::event_loop, this))
throw torrent::internal_error("Failed to create thread.");
}
void void
ThreadBase::stop_thread(ThreadBase* thread) { ThreadBase::stop_thread(ThreadBase* thread) {
if (!thread->m_taskShutdown.is_queued()) if (!thread->m_taskShutdown.is_queued())
priority_queue_insert(&thread->m_taskScheduler, &thread->m_taskShutdown, cachedTime); priority_queue_insert(&thread->m_taskScheduler, &thread->m_taskShutdown, cachedTime);
} }
inline rak::timer int64_t
ThreadBase::client_next_timeout() { ThreadBase::next_timeout_usec() {
if (m_taskScheduler.empty()) if (m_taskScheduler.empty())
return rak::timer::from_seconds(600); return rak::timer::from_seconds(600).usec();
else if (m_taskScheduler.top()->time() <= cachedTime) else if (m_taskScheduler.top()->time() <= cachedTime)
return 0; return 0;
else else
return m_taskScheduler.top()->time() - cachedTime; return (m_taskScheduler.top()->time() - cachedTime).usec();
}
void*
ThreadBase::event_loop(ThreadBase* thread) {
thread->m_state = STATE_ACTIVE;
try {
while (true) {
// Check for new queued items set by other threads.
if (!thread->m_threadQueue->empty())
thread->call_queued_items();
rak::priority_queue_perform(&thread->m_taskScheduler, cachedTime);
thread->m_poll->do_poll(thread->client_next_timeout().usec(), torrent::Poll::poll_worker_thread);
}
} catch (torrent::shutdown_exception& e) {
acquire_global_lock();
lt_log_print(torrent::LOG_THREAD_NOTICE, "Shutting down thread.");
release_global_lock();
}
thread->m_state = STATE_INACTIVE;
__sync_synchronize();
return NULL;
} }
void void
@@ -178,6 +144,15 @@ ThreadBase::call_queued_items() {
(*first++)(this); (*first++)(this);
} }
void
ThreadBase::call_events() {
// Check for new queued items set by other threads.
if (!m_threadQueue->empty())
call_queued_items();
rak::priority_queue_perform(&m_taskScheduler, cachedTime);
}
void void
ThreadBase::queue_item(thread_base_func newFunc) { ThreadBase::queue_item(thread_base_func newFunc) {
m_threadQueue->push_back(newFunc); m_threadQueue->push_back(newFunc);
+3 -7
View File
@@ -54,16 +54,13 @@ class ThreadBase : public torrent::thread_base {
public: public:
typedef rak::priority_queue_default priority_queue; typedef rak::priority_queue_default priority_queue;
typedef void (*thread_base_func)(ThreadBase*); typedef void (*thread_base_func)(ThreadBase*);
typedef void* (*pthread_func)(void*);
ThreadBase(); ThreadBase();
virtual ~ThreadBase(); virtual ~ThreadBase();
priority_queue& task_scheduler() { return m_taskScheduler; } priority_queue& task_scheduler() { return m_taskScheduler; }
virtual void init_thread() = 0; // Throw torrent::shutdown_exception to stop the thread.
void start_thread();
static void stop_thread(ThreadBase* thread); static void stop_thread(ThreadBase* thread);
// ATM, only interaction with a thread's allowed by other threads is // ATM, only interaction with a thread's allowed by other threads is
@@ -71,8 +68,6 @@ public:
void queue_item(thread_base_func newFunc); void queue_item(thread_base_func newFunc);
static void* event_loop(ThreadBase* thread);
// Only call this when global lock has been acquired, as it checks // Only call this when global lock has been acquired, as it checks
// ThreadBase::is_main_polling() which is only guaranteed to remain // ThreadBase::is_main_polling() which is only guaranteed to remain
// 'false' if global lock keeps main thread from entering polling // 'false' if global lock keeps main thread from entering polling
@@ -82,9 +77,10 @@ public:
static void interrupt_main_polling(); static void interrupt_main_polling();
protected: protected:
inline rak::timer client_next_timeout(); int64_t next_timeout_usec();
void call_queued_items(); void call_queued_items();
virtual void call_events();
// TODO: Add thread name. // TODO: Add thread name.
+1
View File
@@ -40,6 +40,7 @@
#include "globals.h" #include "globals.h"
#include <torrent/exceptions.h> #include <torrent/exceptions.h>
#include <torrent/poll.h>
ThreadMain::~ThreadMain() { ThreadMain::~ThreadMain() {
} }