.. _program_listing_file__tmp_ws_src_ecl_core_ecl_threads_include_ecl_threads_threadable.hpp: Program Listing for File threadable.hpp ======================================= |exhale_lsh| :ref:`Return to documentation for file ` (``/tmp/ws/src/ecl_core/ecl_threads/include/ecl/threads/threadable.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp /***************************************************************************** ** Ifdefs *****************************************************************************/ #ifndef ECL_THREADS_THREADABLE_POS_HPP_ #define ECL_THREADS_THREADABLE_POS_HPP_ /***************************************************************************** ** Platform Check *****************************************************************************/ #include #if defined(ECL_IS_POSIX) /***************************************************************************** ** Includes *****************************************************************************/ #include #include #include "thread.hpp" #include "priority.hpp" /***************************************************************************** ** Namespaces *****************************************************************************/ namespace ecl { /***************************************************************************** ** Interface [Threadable] *****************************************************************************/ class ECL_PUBLIC Threadable { public: virtual ~Threadable() {} bool start(const Priority &priority = DefaultPriority) { if ( isRunning() ) { return false; } isRunning(true); // This is not ideal, as it's not perfectly atomic (i.e. someone can query isRunning before this gets set). Thread thread(&Threadable::executeThreadFunction,*this, priority); return true; } Parameter isRunning; protected: Threadable() : isRunning(false) {} virtual void runnable() = 0; private: void executeThreadFunction() { runnable(); isRunning(false); } }; } // namespace ecl #endif /* ECL_IS_POSIX */ #endif /* ECL_THREADS_THREADABLE_POS_HPP_ */