thread_pool.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) Sergey P. Derevyago, 2008.
00003  *
00004  * Permission to copy, use, modify, sell and distribute this software is granted
00005  * provided this copyright notice appears in all copies.
00006  * This software is provided "as is" without express or implied warranty, and
00007  * with no claim as to its suitability for any purpose.
00008  *
00009  */
00010 
00015 #include <ders/thread_pool.hpp>
00016 
00017 namespace {
00018 
00019 using namespace ders;
00020 using namespace std;
00021 
00022 struct st_thrpl : thread_pool, task_opers {
00023        bool stp;
00024 
00025        st_thrpl() {}
00026 
00027        virtual void destroy(mem_pool& mp2) { destroy_this(this, mp2); }
00028        virtual void exec(task& tk, const dq_vec& dv);
00029        virtual void invoke(void (*fun)(void*), void* arg);
00030 };
00031 
00032 void st_thrpl::exec(task& tk, const dq_vec& dv)
00033 {
00034  mem_pool mp;
00035  try { tk.proc(mp, dv, tk.proc_arg(), *this); }
00036  catch (...) { hard_assert(false); }
00037 }
00038 
00039 void st_thrpl::invoke(void (*fun)(void*), void* arg)
00040 {
00041  fun(arg);
00042 }
00043 
00044 }  // unnamed
00045 
00046 namespace ders {  // ::ders
00047 
00048 sh_thread_pool new_thread_pool(mem_pool& mp)
00049 {
00050  mp_newbuf<st_thrpl> buf(mp);
00051  return sh_thread_pool(buf.pool(), buf.rls(::new(buf.get()) st_thrpl));
00052 }
00053 
00054 }  // namespace ::ders
00055 

Generated on Tue Dec 8 11:35:32 2009 for derslib by  doxygen 1.5.5