threadable.hpp
Go to the documentation of this file.
00001 
00011 /*****************************************************************************
00012 ** Ifdefs
00013 *****************************************************************************/
00014 
00015 #ifndef ECL_THREADS_THREADABLE_POS_HPP_
00016 #define ECL_THREADS_THREADABLE_POS_HPP_
00017 
00018 /*****************************************************************************
00019 ** Platform Check
00020 *****************************************************************************/
00021 
00022 #include <ecl/config/ecl.hpp>
00023 #if defined(ECL_IS_POSIX)
00024 
00025 /*****************************************************************************
00026 ** Includes
00027 *****************************************************************************/
00028 
00029 #include <ecl/utilities/parameter.hpp>
00030 #include <ecl/config/macros.hpp>
00031 #include "thread.hpp"
00032 #include "priority.hpp"
00033 
00034 /*****************************************************************************
00035 ** Namespaces
00036 *****************************************************************************/
00037 
00038 namespace ecl {
00039 
00040 /*****************************************************************************
00041 ** Interface [Threadable]
00042 *****************************************************************************/
00066 class ECL_PUBLIC Threadable {
00067 public:
00068         virtual ~Threadable() {}
00069 
00079         bool start(const Priority &priority = DefaultPriority) {
00080                 if ( isRunning() ) { return false; }
00081                 isRunning(true); // This is not ideal, as it's not perfectly atomic (i.e. someone can query isRunning before this gets set).
00082                 Thread thread(&Threadable::executeThreadFunction,*this, priority);
00083                 return true;
00084         }
00090         Parameter<bool> isRunning;
00091 
00092 protected:
00093         Threadable() : isRunning(false) {}
00094 
00095         virtual void runnable() = 0;
00096 
00097 private:
00098         void executeThreadFunction() {
00099                 runnable();
00100                 isRunning(false);
00101         }
00102 };
00103 
00104 } // namespace ecl
00105 
00106 #endif /* ECL_IS_POSIX */
00107 #endif /* ECL_THREADS_THREADABLE_POS_HPP_ */


ecl_threads
Author(s): Daniel Stonier
autogenerated on Sun Oct 5 2014 23:35:37