# # # patch "file_io.cc" # from [b754b2fa192ca610b61f8e7e6533024be0bcf454] # to [046023a08a66429c7f47f607fd2b32fe51341b5c] # # patch "threads.hh" # from [80006806f27cc64ff57db6193ac7ffd97016ce56] # to [9dc14e98f93640539b36ee3fb8e96e21e3aa3dbc] # # patch "unix/threads.cc" # from [ad31b34f7d40748854fdd212a97c3b4fead03985] # to [854ac01d68fe24d60b45134986d3044ea10c1bbd] # ============================================================ --- file_io.cc b754b2fa192ca610b61f8e7e6533024be0bcf454 +++ file_io.cc 046023a08a66429c7f47f607fd2b32fe51341b5c @@ -534,7 +534,7 @@ class file_hash_calc_task } class file_hash_calc_task - : public thread_functor + : public threaded_task { shared_ptr path; shared_ptr ident; ============================================================ --- threads.hh 80006806f27cc64ff57db6193ac7ffd97016ce56 +++ threads.hh 9dc14e98f93640539b36ee3fb8e96e21e3aa3dbc @@ -10,25 +10,28 @@ // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. +#include #include -class thread_functor +class threaded_task { public: virtual void operator()() = 0; }; -struct -thread_context +template +class task_done_callback { - thread_functor * func; +public: + virtual void operator()() = 0; }; -extern void create_thread_for(thread_functor * func); +extern void create_thread_for(threaded_task * func); template class worker_pool { + std::stack tstack; public: worker_pool() { }; @@ -37,16 +40,18 @@ public: { I(p1); I(p2); - thread_functor *func(new TASK(p1, p2)); - func->operator()(); - //create_thread_for(func); - delete func; + tstack.push(new TASK(p1, p2)); } void wait(void) { - // - // sleep(10); + while (!tstack.empty()) + { + threaded_task *task = tstack.top(); + tstack.pop(); + task->operator()(); + //create_thread_for(task); + } } }; ============================================================ --- unix/threads.cc ad31b34f7d40748854fdd212a97c3b4fead03985 +++ unix/threads.cc 854ac01d68fe24d60b45134986d3044ea10c1bbd @@ -26,24 +26,30 @@ #include "sanity.hh" #include "threads.hh" +struct +thread_context +{ + threaded_task * task; +}; + void *threaded_call(void *c) { thread_context * ctx = (thread_context*) c; - (*ctx->func)(); + (*ctx->task)(); pthread_exit(NULL); } void -create_thread_for(thread_functor * func) +create_thread_for(threaded_task * task) { int rc; void *status; pthread_t thread; thread_context * ctx = new thread_context(); - ctx->func = func; + ctx->task = task; rc = pthread_create(&thread, NULL, threaded_call, (void*) &ctx); I(!rc); @@ -52,7 +58,7 @@ create_thread_for(thread_functor * func) I(!rc); delete ctx; - delete func; + delete task; } // Local Variables: