# # # patch "file_io.hh" # from [5f5e79a1c9190ef94d51c05910a67972478ef8bd] # to [ed405b7d81a539357342fc4f8d23cc70e1fd9a00] # # patch "threads.hh" # from [9dc14e98f93640539b36ee3fb8e96e21e3aa3dbc] # to [fe09d1a7d4ab8efb3b7e7db539ce2654ddedd11e] # # patch "work.cc" # from [a37b28a92215b30cf8e917350f59ff2bc3ed9b38] # to [f20072cb28b21331f9964e582d5796b425b7f111] # ============================================================ --- file_io.hh 5f5e79a1c9190ef94d51c05910a67972478ef8bd +++ file_io.hh ed405b7d81a539357342fc4f8d23cc70e1fd9a00 @@ -124,7 +124,7 @@ void walk_tree(file_path const & path, // define a thread pool for file identifiers, where the workers take // a file_path as an input, and output a success indicator as well // as a file_id, in case of success. -struct file_hash_calc_task; +class file_hash_calc_task; typedef worker_pool file_ident_pool; bool ident_existing_file(file_ident_pool & pool, ============================================================ --- threads.hh 9dc14e98f93640539b36ee3fb8e96e21e3aa3dbc +++ threads.hh fe09d1a7d4ab8efb3b7e7db539ce2654ddedd11e @@ -19,16 +19,9 @@ public: virtual void operator()() = 0; }; -template -class task_done_callback -{ -public: - virtual void operator()() = 0; -}; - extern void create_thread_for(threaded_task * func); -template +template class worker_pool { std::stack tstack; @@ -36,11 +29,11 @@ public: worker_pool() { }; - void add_job(boost::shared_ptr p1, boost::shared_ptr p2) + void add_job(boost::shared_ptr in, boost::shared_ptr out) { - I(p1); - I(p2); - tstack.push(new TASK(p1, p2)); + I(in); + I(out); + tstack.push(new TASK(in, out)); } void wait(void) ============================================================ --- work.cc a37b28a92215b30cf8e917350f59ff2bc3ed9b38 +++ work.cc f20072cb28b21331f9964e582d5796b425b7f111 @@ -1290,6 +1290,29 @@ workspace::update_current_roster_from_fi update_current_roster_from_filesystem(ros, node_restriction()); } +class file_hash_calc_task +{ +private: + shared_ptr in; + shared_ptr out; + +public: + file_hash_calc_task(shared_ptr in, + shared_ptr out) + : in(in), out(out) + { }; + + virtual void operator()() + { + calculate_ident(*in, *out); + } +}; + +void NoOpDeallocator(file_id *p) +{ + /* no-op */ +} + void workspace::update_current_roster_from_filesystem(roster_t & ros, node_restriction const & mask) @@ -1313,6 +1336,7 @@ workspace::update_current_roster_from_fi return; node_map const & nodes = ros.all_nodes(); + file_ident_pool pool; for (node_map::const_iterator i = nodes.begin(); i != nodes.end(); ++i) { node_id nid = i->first; @@ -1322,21 +1346,21 @@ workspace::update_current_roster_from_fi if (!mask.includes(ros, nid)) continue; - file_path fp; - ros.get_name(nid, fp); + shared_ptr fp(new file_path()); + ros.get_name(nid, *fp); - const path::status status(get_path_status(fp)); + const path::status status(get_path_status(*fp)); if (is_dir_t(node)) { if (status == path::nonexistent) { - W(F("missing directory '%s'") % (fp)); + W(F("missing directory '%s'") % (*fp)); missing_items++; } else if (status != path::directory) { - W(F("not a directory '%s'") % (fp)); + W(F("not a directory '%s'") % (*fp)); missing_items++; } } @@ -1344,35 +1368,30 @@ workspace::update_current_roster_from_fi { // Only analyze changed files (or all files if inodeprints mode // is disabled). - if (inodeprint_unchanged(ipm, fp)) + if (inodeprint_unchanged(ipm, *fp)) continue; if (status == path::nonexistent) { - W(F("missing file '%s'") % (fp)); + W(F("missing file '%s'") % (*fp)); missing_items++; } else if (status != path::file) { - W(F("not a file '%s'") % (fp)); + W(F("not a file '%s'") % (*fp)); missing_items++; } { - file_ident_pool pool; - shared_ptr fid(new file_id()); - shared_ptr fpath(new file_path(fp)); - ident_existing_file(pool, fpath, fid, status); - - // wait until all jobs in the pool are done. - pool.wait(); - file_t file = downcast_to_file_t(node); - file->content = *fid; + shared_ptr fid(&file->content, NoOpDeallocator); + ident_existing_file(pool, fp, fid, status); } } + } - } + // wait until all jobs in the pool are done. + pool.wait(); N(missing_items == 0, F("%d missing items; use '%s ls missing' to view\n"