TaskRunnerInterface.hh

00001 //********************************************************************
00002 //*** Thread/ThreadRunnerInterfacehh
00003 //*** Copyright (c) 2003-2009 by Markus Winand <mws@fatalmind.com>
00004 //*** $Id: TaskRunnerInterface.hh,v 1.7 2009-03-02 14:16:47 mws Exp $
00005 //********************************************************************
00006 /*
00007 This file is part of ResourcePool.
00008 
00009 ResourcePool is free software; you can redistribute it
00010 and/or modify it under the terms of the GNU General Public License
00011 as published by the Free Software Foundation; either version 2 of
00012 the License, or (at your option) any later version.
00013 
00014 ResourcePool is distributed in the hope that it will be
00015 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
00016 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 GNU General Public License for more details.
00018 
00019 You should have received a copy of the GNU General Public License
00020 along with ResourcePool; if not, write to the Free Software
00021 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00022 02111-1307  USA */
00023 
00024 #ifndef THREAD_TASKRUNNERINTERFACE_HH
00025 #define THREAD_TASKRUNNERINTERFACE_HH
00026 
00027 #include "Thread/Task.hh"
00028 
00029 #include "mm/gc_ptr.hh"
00030 #include "mm/CommonPtr.hh"
00031 
00032 namespace fatalmind {
00033 
00034 class WaitObject;
00035 
00036 class TaskRunnerInterface {
00037     public:
00038         class ID {
00039             public:
00040                 ID();
00041                 ID(const ID&);
00042                 ID(gc_ptr<WaitObject, MultiThreadedModel<> >&);
00043                 ~ID() throw();
00044 
00045                 ID& operator=(const ID&);
00046                 void wait();
00047                 void detach();
00048             private:
00049                 gc_ptr<WaitObject, MultiThreadedModel<> > _wo;
00050         };
00051 
00052 
00053         template<class D>
00054         inline void runDetached(std::auto_ptr<D> a) {
00055             runDetached(std::auto_ptr<Task>(a));
00056         }
00057         template<class D>
00058         inline void runDetached(gc_ptr<D, MultiThreadedModel<> > a) {
00059             runDetached(gc_ptr<Task, MultiThreadedModel<> >(a));
00060         }
00061         inline void runDetached(std::auto_ptr<Task> a) {
00062             CommonPtr<Task, MultiThreadedModel<> > c(a);
00063             runDetached(c);
00064         }
00065         inline void runDetached(gc_ptr<Task, MultiThreadedModel<> > a) {
00066             CommonPtr<Task, MultiThreadedModel<> > c(a);
00067             runDetached(c);
00068         }
00069 
00070 
00071         template<class D>
00072         inline ID run(std::auto_ptr<D> a) {
00073             return run(std::auto_ptr<Task>(a));
00074         }
00075         template<class D>
00076         inline ID run(gc_ptr<D, MultiThreadedModel<> > a) {
00077             return run(gc_ptr<Task, MultiThreadedModel<> >(a));
00078         }
00079         inline ID run(std::auto_ptr<Task> a) {
00080             CommonPtr<Task, MultiThreadedModel<> > c(a);
00081             return run(c);
00082         }
00083         inline ID run(gc_ptr<Task, MultiThreadedModel<> > a) {
00084             CommonPtr<Task, MultiThreadedModel<> > c(a);
00085             return run(c);
00086         }
00087 
00088     protected:
00089         virtual void runDetached(CommonPtr<Task, MultiThreadedModel<> >) = 0;
00090         virtual ID run(CommonPtr<Task, MultiThreadedModel<> >) = 0;
00091 
00092         virtual ~TaskRunnerInterface() {
00093         }
00094 };
00095 
00096 } // namespace fatalmind
00097 #endif

Generated on Mon Nov 9 16:21:24 2009 for ResourcePool by  doxygen 1.5.3