Skip to content
This repository has been archived by the owner on Oct 10, 2019. It is now read-only.

Commit

Permalink
Andreas Krennmair:
Browse files Browse the repository at this point in the history
	implemented configurability of number of parallel threads when reloading all feeds.
  • Loading branch information
akrennmair committed Nov 15, 2008
1 parent e457c9b commit 56379ce
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Changes for newsbeuter:
Extended macros to enable modification of configuration variables.
Implemented configuration option "feed-sort-order" to sort the feed list by the first tag.
Added ability to toggle read flag from article view (thanks to Isaac Good).
Added ability to configure the number of parallel reload threads (fixes #101).

1.2 (2008-09-02):
Fixed crash in case of invalid color/attribute names in the configuration
Expand Down
1 change: 1 addition & 0 deletions doc/configcommands.dsv
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ proxy-auth|<auth>|n/a|Set the proxy authentication string.|proxy-auth user:passw
refresh-on-startup|[yes/no]|no|If yes, then all feeds will be reloaded when newsbeuter starts up. This is equivalent to the -r commandline option.|refresh-on-startup yes
reload-only-visible-feeds|[yes/no]|no|If yes, then manually reloading all feeds will only reload the currently visible feeds, e.g. if a filter or a tag is set.|reload-only-visible-feeds yes
reload-time|<number>|60|The number of minutes between automatic reloads.|reload-time 120
reload-threads|<number>|1|The number of parallel reload threads that shall be started when all feeds are reloaded.|reload-threads 3
reset-unread-on-update|<url> ...|n/a|With this configuration command, you can provide a list of RSS feed URLs for whose articles the unread flag will be reset if an article has been updated, i.e. its content has been changed. This is especially useful for RSS feeds where single articles are updated after publication, and you want to be notified of the updates.|reset-unread-on-update "http://blog.fefe.de/rss.xml?html"
save-path|<path>|~/|The default path where articles shall be saved to. If an invalid path is specified, the current directory is used.|save-path "~/Saved Articles"
show-keymap-hint|[yes/no]|yes|If no, then the keymap hints on the bottom of screen will not be displayed.|show-keymap-hint no
Expand Down
1 change: 1 addition & 0 deletions include/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace newsbeuter {

void reload_all(bool unattended = false);
void reload_indexes(const std::vector<int>& indexes, bool unattended = false);
void reload_range(unsigned int start, unsigned int end, unsigned int size, bool unattended = false);
void start_reload_all_thread(std::vector<int> * indexes = 0);

std::tr1::shared_ptr<rss_feed> get_feed(unsigned int pos);
Expand Down
12 changes: 12 additions & 0 deletions include/downloadthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ class downloadthread : public thread
std::vector<int> indexes;
};

class reloadrangethread : public thread
{
public:
reloadrangethread(controller * c, unsigned int start, unsigned int end, unsigned int size, bool unattended);
protected:
virtual void run();
private:
controller * ctrl;
unsigned int s, e, ss;
bool u;
};

}

#endif /*DOWNLOADTHREAD_H_*/
2 changes: 1 addition & 1 deletion include/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace newsbeuter {
public:
thread();
virtual ~thread();
void start();
pthread_t start();
void join();

protected:
Expand Down
1 change: 1 addition & 0 deletions src/configcontainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ configcontainer::configcontainer()
config_data["download-timeout"] = configdata("30", configdata::INT);
config_data["download-retries"] = configdata("1", configdata::INT);
config_data["feed-sort-order"] = configdata("none", configdata::STR);
config_data["reload-threads"] = configdata("1", configdata::INT);


/* undocumented: */
Expand Down
32 changes: 28 additions & 4 deletions src/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,16 +566,40 @@ void controller::reload_indexes(const std::vector<int>& indexes, bool unattended
v->set_status("");
}

void controller::reload_range(unsigned int start, unsigned int end, unsigned int size, bool unattended) {
for (unsigned int i=start;i<=end;i++) {
GetLogger().log(LOG_DEBUG, "controller::reload_range: reloading feed #%u", i);
this->reload(i, size, unattended);
}
}

void controller::reload_all(bool unattended) {
GetLogger().log(LOG_DEBUG,"controller::reload_all: starting with reload all...");
unsigned int unread_feeds, unread_articles;
compute_unread_numbers(unread_feeds, unread_articles);
unsigned int num_threads = cfg->get_configvalue_as_int("reload-threads");
time_t t1, t2, dt;

t1 = time(NULL);
for (unsigned int i=0;i<feeds.size();++i) {
GetLogger().log(LOG_DEBUG, "controller::reload_all: reloading feed #%u", i);
this->reload(i,feeds.size(), unattended);

GetLogger().log(LOG_DEBUG,"controller::reload_all: starting with reload all...");
if (num_threads <= 1) {
this->reload_range(0, feeds.size()-1, feeds.size(), unattended);
} else {
std::vector<std::pair<unsigned int, unsigned int> > partitions = utils::partition_indexes(0, feeds.size()-1, num_threads);
std::vector<pthread_t> threads;
GetLogger().log(LOG_DEBUG, "controller::reload_all: starting reload threads...");
for (unsigned int i=0;i<num_threads-1;i++) {
reloadrangethread* t = new reloadrangethread(this, partitions[i].first, partitions[i].second, feeds.size(), unattended);
threads.push_back(t->start());
}
GetLogger().log(LOG_DEBUG, "controller::reload_all: starting my own reload...");
this->reload_range(partitions[num_threads-1].first, partitions[num_threads-1].second, feeds.size(), unattended);
GetLogger().log(LOG_DEBUG, "controller::reload_all: joining other threads...");
for (std::vector<pthread_t>::iterator it=threads.begin();it!=threads.end();it++) {
::pthread_join(*it, NULL);
}
}

t2 = time(NULL);
dt = t2 - t1;
GetLogger().log(LOG_INFO, "controller::reload_all: reload took %d seconds", dt);
Expand Down
8 changes: 8 additions & 0 deletions src/downloadthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,12 @@ void downloadthread::run() {
this->detach();
}

reloadrangethread::reloadrangethread(controller * c, unsigned int start, unsigned int end, unsigned int size, bool unattended) : ctrl(c), s(start), e(end), ss(size), u(unattended)
{
}

void reloadrangethread::run() {
ctrl->reload_range(s, e, ss, u);
}

}
3 changes: 2 additions & 1 deletion src/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ thread::~thread() {

}

void thread::start() {
pthread_t thread::start() {
int rc = pthread_create(&pt, 0, (void *(*)(void*))run_thread, this);
GetLogger().log(LOG_DEBUG, "thread::start: created new thread %d rc = %d", pt, rc);
if (rc != 0) {
throw exception(rc);
}
return pt;
}

void thread::join() {
Expand Down

0 comments on commit 56379ce

Please sign in to comment.