[Aptitude-svn-commit] r4042 - in branches/aptitude-0.3/aptitude: .
src src/cmdline
Daniel Burrows
dburrows at costa.debian.org
Sat Sep 3 18:36:44 UTC 2005
Author: dburrows
Date: Sat Sep 3 18:36:41 2005
New Revision: 4042
Modified:
branches/aptitude-0.3/aptitude/ChangeLog
branches/aptitude-0.3/aptitude/src/cmdline/cmdline_update.cc
branches/aptitude-0.3/aptitude/src/download.cc
branches/aptitude-0.3/aptitude/src/download.h
branches/aptitude-0.3/aptitude/src/download_thread.cc
branches/aptitude-0.3/aptitude/src/download_thread.h
branches/aptitude-0.3/aptitude/src/ui.cc
Log:
Move list updates into a background thread.
Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog (original)
+++ branches/aptitude-0.3/aptitude/ChangeLog Sat Sep 3 18:36:41 2005
@@ -1,3 +1,10 @@
+2005-09-03 Daniel Burrows <dburrows at debian.org>
+
+ * src/cmdline/cmdline_update.cc, src/download.cc, src/download.h, src/download_thread.cc, src/download_thread.h, src/ui.cc:
+
+ Use the download_thread class to run list updates in the
+ background.
+
2005-09-02 Daniel Burrows <dburrows at debian.org>
* src/Makefile.am, src/download_thread.cc, src/download_thread.h:
Modified: branches/aptitude-0.3/aptitude/src/cmdline/cmdline_update.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/cmdline/cmdline_update.cc (original)
+++ branches/aptitude-0.3/aptitude/src/cmdline/cmdline_update.cc Sat Sep 3 18:36:41 2005
@@ -3,6 +3,7 @@
// Copyright 2004 Daniel Burrows
#include "../download.h"
+#include "../download_manager.h"
#include "cmdline_progress.h"
Modified: branches/aptitude-0.3/aptitude/src/download.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/download.cc (original)
+++ branches/aptitude-0.3/aptitude/src/download.cc Sat Sep 3 18:36:41 2005
@@ -77,7 +77,7 @@
pkgAcquire * prepare_pkglist_update(OpProgress *load_progress,
bool text_download,
- download_manager *manager)
+ pkgAcquireStatus *log)
{
pkgSourceList src_list;
@@ -105,7 +105,7 @@
}
}
- pkgAcquire *fetcher = new pkgAcquire(manager);
+ pkgAcquire *fetcher = new pkgAcquire(log);
if(!src_list.GetIndexes(fetcher))
{
@@ -118,11 +118,11 @@
bool finish_pkglist_update(OpProgress *load_progress,
bool text_download,
- download_manager *manager,
+ download_manager *m,
pkgAcquire *fetcher,
pkgAcquire::RunResult res)
{
- manager->Complete();
+ m->Complete();
if(res != pkgAcquire::Continue)
{
Modified: branches/aptitude-0.3/aptitude/src/download.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/download.h (original)
+++ branches/aptitude-0.3/aptitude/src/download.h Sat Sep 3 18:36:41 2005
@@ -24,7 +24,7 @@
*/
pkgAcquire *prepare_pkglist_update(OpProgress *load_progress,
bool text_download,
- download_manager *manager);
+ pkgAcquireStatus *log);
/** Finish updating the package lists given that the download returned
* res.
Modified: branches/aptitude-0.3/aptitude/src/download_thread.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/download_thread.cc (original)
+++ branches/aptitude-0.3/aptitude/src/download_thread.cc Sat Sep 3 18:36:41 2005
@@ -154,7 +154,29 @@
do_foreground_execute(real_status, &pkgAcquireStatus::Stop);
}
+class download_thread_complete_event : public vscreen_event
+{
+ download_thread *t;
+ pkgAcquire::RunResult res;
+
+ sigc::slot2<void, download_thread *, pkgAcquire::RunResult> continuation;
+public:
+ download_thread_complete_event(download_thread *_t,
+ pkgAcquire::RunResult _res,
+ sigc::slot2<void, download_thread *, pkgAcquire::RunResult> &_continuation)
+ :t(_t), res(_res), continuation(_continuation)
+ {
+ }
+
+ void dispatch()
+ {
+ t->join();
+ continuation(t, res);
+ }
+};
+
void download_thread::operator()()
{
- continuation(this, acq->Run());
+ vscreen_post_event(new download_thread_complete_event(this, acq->Run(),
+ continuation));
}
Modified: branches/aptitude-0.3/aptitude/src/download_thread.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/download_thread.h (original)
+++ branches/aptitude-0.3/aptitude/src/download_thread.h Sat Sep 3 18:36:41 2005
@@ -39,15 +39,16 @@
{
pkgAcquireStatus *real_status;
public:
- virtual void Fetched(unsigned long Size, unsigned long ResumePoint);
- virtual bool MediaChange(std::string Media, std::string Drive);
- virtual void IMSHit(pkgAcquire::ItemDesc &);
- virtual void Fetch(pkgAcquire::ItemDesc &);
- virtual void Done(pkgAcquire::ItemDesc &);
- virtual void Fail(pkgAcquire::ItemDesc &);
- virtual bool Pulse(pkgAcquire *Owner);
- virtual void Start();
- virtual void Stop();
+ void Fetched(unsigned long Size, unsigned long ResumePoint);
+ bool MediaChange(std::string Media, std::string Drive);
+ void IMSHit(pkgAcquire::ItemDesc &);
+ void Fetch(pkgAcquire::ItemDesc &);
+ void Done(pkgAcquire::ItemDesc &);
+ void Fail(pkgAcquire::ItemDesc &);
+ bool Pulse(pkgAcquire *Owner);
+ void Start();
+ void Stop();
+ void Complete();
background_status(pkgAcquireStatus *_real_status)
:real_status(_real_status)
@@ -66,8 +67,10 @@
*/
pkgAcquire *acq;
- /** The continuation of this download, called with this thread and
- * the result of the run as parameters.
+ /** The continuation of this download, invoked in the main thread
+ * with this thread and the result of the run as parameters. The
+ * thread will be automatically join()ed before the continuation is
+ * deleted.
*/
sigc::slot2<void, download_thread *, pkgAcquire::RunResult> continuation;
Modified: branches/aptitude-0.3/aptitude/src/ui.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/ui.cc (original)
+++ branches/aptitude-0.3/aptitude/src/ui.cc Sat Sep 3 18:36:41 2005
@@ -85,13 +85,14 @@
#include "dep_item.h"
#include "download.h"
-#include "download_screen.h"
#include "download_bar.h"
#include "download_list.h"
#include "download_manager.h"
+#include "download_screen.h"
+#include "download_thread.h"
#include "pkg_columnizer.h"
-#include "pkg_info_screen.h"
#include "pkg_grouppolicy.h"
+#include "pkg_info_screen.h"
#include "pkg_tree.h"
#include "pkg_ver_item.h"
#include "pkg_view.h"
@@ -1123,6 +1124,12 @@
}
}
+static void finish_update_lists(download_thread *t,
+ pkgAcquire::RunResult res,
+ pkgAcquire *acq,
+ download_manager *m,
+ background_status *st);
+
static void really_do_update_lists()
{
active_download = true;
@@ -1134,16 +1141,32 @@
_("List Update"),
NULL);
- pkgAcquire *acq = prepare_pkglist_update(p.unsafe_get_ref(), false, m);
+ background_status *st = new background_status(m);
+
+ pkgAcquire *acq = prepare_pkglist_update(p.unsafe_get_ref(), false,
+ st);
if(acq != NULL)
- {
- pkgAcquire::RunResult res = acq->Run(aptcfg->FindI(PACKAGE "::UI::Download-Poll-Interval", 50000));
- finish_pkglist_update(p.unsafe_get_ref(), false, m, acq, res);
- }
+ (new download_thread(acq, sigc::bind(sigc::ptr_fun(&finish_update_lists),
+ acq, m, st)))->start();
+
+ p->destroy();
+}
+
+static void finish_update_lists(download_thread *t,
+ pkgAcquire::RunResult res,
+ pkgAcquire *acq,
+ download_manager *m,
+ background_status *st)
+{
+ vs_progress_ref p = gen_progress_bar();
+
+ finish_pkglist_update(p.unsafe_get_ref(), false, m, acq, res);
+ delete t;
delete acq;
delete m;
+ delete st;
p->destroy();
More information about the Aptitude-svn-commit
mailing list