[pan2/rss: 1/2] small fixes



commit 640e595f789efb8516746a2704a318c09ab74601
Author: Heinrich Müller <henmull src gnome org>
Date:   Sat Jun 1 12:07:26 2013 +0200

    small fixes

 pan/general/worker-pool.cc |   45 +++++++++++++++++++++----------------------
 pan/tasks/decoder.cc       |    4 +--
 pan/tasks/encoder.cc       |    6 +---
 pan/tasks/queue.cc         |    5 +--
 pan/tasks/task-upload.cc   |    5 +---
 pan/tasks/task-upload.h    |    2 -
 pan/tasks/task.h           |    7 ++---
 7 files changed, 31 insertions(+), 43 deletions(-)
---
diff --git a/pan/general/worker-pool.cc b/pan/general/worker-pool.cc
index 7ae7271..703ec72 100644
--- a/pan/general/worker-pool.cc
+++ b/pan/general/worker-pool.cc
@@ -29,69 +29,68 @@
 
 using namespace pan;
 
-WorkerPool :: WorkerPool (int n, bool exclusive)
+WorkerPool::WorkerPool(int n, bool exclusive)
 {
-  assert ((!exclusive || n>0) && "can't have unlimited exclusive threads!");
-  tpool = g_thread_pool_new (Worker::worker_thread_func, this, n, exclusive, 0);
+  assert((!exclusive || n>0) && "can't have unlimited exclusive threads!");
+  tpool = g_thread_pool_new(Worker::worker_thread_func, this, n, exclusive, 0);
 }
 
 void
-WorkerPool :: cancel_all_silently ()
+WorkerPool::cancel_all_silently()
 {
-  foreach (WorkerSet, my_workers, it)
-    (*it)->cancel_silently ();
+  foreach (WorkerSet, my_workers, it)(*it)->cancel_silently ();
 }
 
-WorkerPool :: ~WorkerPool ()
+WorkerPool::~WorkerPool()
 {
-  foreach (WorkerSet, my_workers, it) {
+  foreach (WorkerSet, my_workers, it){
     (*it)->pool = 0;
     (*it)->cancel ();
   }
 
-  // blocks until *all* workers, both running and queued, have run.
+ // blocks until *all* workers, both running and queued, have run.
   g_thread_pool_free (tpool, false, true);
 }
 
 /***
-****
-***/
+ ****
+ ***/
 
 void
-WorkerPool :: push_work (Worker *w, Worker::Listener *l, bool delete_worker)
+WorkerPool::push_work(Worker *w, Worker::Listener *l, bool delete_worker)
 {
   w->cancelled = false;
   w->silent = false;
   w->pool = this;
   w->listener = l;
   w->delete_worker = delete_worker;
-  my_workers.insert (w);
-  g_thread_pool_push (tpool, w, 0); // jump to worker_thread_func
+  my_workers.insert(w);
+  g_thread_pool_push(tpool, w, 0); // jump to worker_thread_func
 }
 
 void
-WorkerPool :: Worker :: worker_thread_func (gpointer g, gpointer unused UNUSED)
+WorkerPool::Worker::worker_thread_func(gpointer g, gpointer unused UNUSED)
 {
-  static_cast<Worker*>(g)->do_work ();
-  g_idle_add (main_thread_cleanup_cb, g); // jump to main_thread_cleanup_cb
+  static_cast<Worker*>(g)->do_work();
+  g_idle_add(main_thread_cleanup_cb, g); // jump to main_thread_cleanup_cb
 }
 
 gboolean
-WorkerPool :: Worker :: main_thread_cleanup_cb (gpointer g)
+WorkerPool::Worker::main_thread_cleanup_cb(gpointer g)
 {
-  static_cast<Worker*>(g)->main_thread_cleanup ();
+  static_cast<Worker*>(g)->main_thread_cleanup();
   return false; // tell main loop that we're done
 }
 
 void
-WorkerPool :: Worker :: main_thread_cleanup ()
+WorkerPool::Worker::main_thread_cleanup()
 {
   if (listener && !silent)
-      listener->on_worker_done (was_cancelled());
+    listener->on_worker_done(was_cancelled());
 
   if (pool)
-      pool->my_workers.erase (this);
+    pool->my_workers.erase(this);
 
   if (delete_worker)
-      delete this;
+    delete this;
 }
diff --git a/pan/tasks/decoder.cc b/pan/tasks/decoder.cc
index 18f8107..4b99d57 100644
--- a/pan/tasks/decoder.cc
+++ b/pan/tasks/decoder.cc
@@ -307,12 +307,10 @@ Decoder :: progress_update_timer_func (gpointer decoder)
   Task *task = self->task;
   if (!task || self->was_cancelled()) return false;
 
-  self->mut.lock();
   const double percent (self->percent);
   const std::string f (content_to_utf8 (self->current_file));
-  self->mut.unlock();
 
-  task->set_step(int(percent));
+  task->set_step((int)percent);
   task->set_status_va (_("Decoding %s"), f.c_str());
 
   return true; // keep timer func running
diff --git a/pan/tasks/encoder.cc b/pan/tasks/encoder.cc
index 887ef76..d7f8a49 100644
--- a/pan/tasks/encoder.cc
+++ b/pan/tasks/encoder.cc
@@ -259,10 +259,8 @@ Encoder :: progress_update_timer_func (gpointer decoder)
   Task *task = self->task;
   if (!task || self->was_cancelled()) return false;
 
-  self->mut.lock();
-    const double percent (self->percent);
-    const std::string f (content_to_utf8 (self->current_file));
-  self->mut.unlock();
+  const double percent (self->percent);
+  const std::string f (content_to_utf8 (self->current_file));
 
   task->set_step(int(percent));
   task->set_status_va (_("Encoding %s"), f.c_str());
diff --git a/pan/tasks/queue.cc b/pan/tasks/queue.cc
index a8b5e03..e568b48 100644
--- a/pan/tasks/queue.cc
+++ b/pan/tasks/queue.cc
@@ -320,9 +320,8 @@ Queue :: process_task (Task * task)
   {
     debug ("working");
   }
-  else if (state._work == Task::PAUSED)
+  else if (state._work == Task::INITIAL)
   {
-    debug("paused");
     TaskUpload* t = dynamic_cast<TaskUpload*>(task);
     if (t)
       give_task_an_upload_slot(t);
@@ -685,7 +684,7 @@ Queue :: remove_task (Task * task)
       const tasks_t tmp (_tasks.begin(), _tasks.end());
       foreach_const (tasks_t, tmp, it) {
         Task * task (*it);
-        if (task->get_state()._work == Task::PAUSED)
+        if (task->get_state()._work == Task::INITIAL)
         {
           give_task_an_upload_slot(dynamic_cast<TaskUpload*>(*it));
           break;
diff --git a/pan/tasks/task-upload.cc b/pan/tasks/task-upload.cc
index 27636d6..8aa7231 100644
--- a/pan/tasks/task-upload.cc
+++ b/pan/tasks/task-upload.cc
@@ -105,7 +105,6 @@ TaskUpload :: TaskUpload (const std::string         & filename,
   _queue_pos(0),
   _msg (msg),
   _first(true),
-  _paused(true),
   _groups(get_groups_str(article))
 {
 
@@ -115,8 +114,7 @@ TaskUpload :: TaskUpload (const std::string         & filename,
   struct stat sb;
   stat(filename.c_str(),&sb);
   _bytes = sb.st_size;
-
-  _state.set_paused();
+  _state.set_initial();
 }
 
 namespace
@@ -376,7 +374,6 @@ TaskUpload :: on_nntp_done (NNTP * nntp,
 unsigned long
 TaskUpload :: get_bytes_remaining () const
 {
-  if (_paused) return _bytes*1.15;
   unsigned long bytes (0);
   foreach_const (needed_t, _needed, it)
     bytes += (unsigned long)it->second.bytes;
diff --git a/pan/tasks/task-upload.h b/pan/tasks/task-upload.h
index 2eb9a8a..4096c06 100644
--- a/pan/tasks/task-upload.h
+++ b/pan/tasks/task-upload.h
@@ -151,7 +151,6 @@ namespace pan
       needed_t _needed;
       std::string _references; // original references, not to be touched!
       std::string _first_mid;
-      bool _paused;
       std::set<int> _wanted;
       GMimeMessage * _msg;
       void prepend_headers(GMimeMessage* msg, TaskUpload::Needed * n, std::string& d);
@@ -165,7 +164,6 @@ namespace pan
       void set_encoder_done (bool setme) { _encoder_has_run = setme; }
       needed_t& needed() { return _needed; }
       void build_needed_tasks();
-      void wakeup() { _state.set_working(); _paused=false; update_work(); }
 
   };
 }
diff --git a/pan/tasks/task.h b/pan/tasks/task.h
index a63d832..fe2ad20 100644
--- a/pan/tasks/task.h
+++ b/pan/tasks/task.h
@@ -58,8 +58,7 @@ namespace pan
             NEED_ENCODER = 3,
             /** Task is running */
             WORKING = 5,
-            /** Task is paused, woken up if 'current_connections < max_connections' */
-            PAUSED = 6
+            INITIAL = 6
          };
 
          /**
@@ -84,8 +83,8 @@ namespace pan
                void set_completed () {
                    _work = COMPLETED; _servers.clear(); }
 
-               void set_paused () {
-                   _work = PAUSED; _servers.clear(); }
+               void set_initial () {
+                   _work = INITIAL; _servers.clear(); }
 
                void set_working () {
                   _work = WORKING; _servers.clear(); }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]