threadable.hpp
Go to the documentation of this file.
1 
11 /*****************************************************************************
12 ** Ifdefs
13 *****************************************************************************/
14 
15 #ifndef ECL_THREADS_THREADABLE_POS_HPP_
16 #define ECL_THREADS_THREADABLE_POS_HPP_
17 
18 /*****************************************************************************
19 ** Platform Check
20 *****************************************************************************/
21 
22 #include <ecl/config/ecl.hpp>
23 #if defined(ECL_IS_POSIX)
24 
25 /*****************************************************************************
26 ** Includes
27 *****************************************************************************/
28 
30 #include <ecl/config/macros.hpp>
31 #include "thread.hpp"
32 #include "priority.hpp"
33 
34 /*****************************************************************************
35 ** Namespaces
36 *****************************************************************************/
37 
38 namespace ecl {
39 
40 /*****************************************************************************
41 ** Interface [Threadable]
42 *****************************************************************************/
66 class ECL_PUBLIC Threadable {
67 public:
68  virtual ~Threadable() {}
69 
79  bool start(const Priority &priority = DefaultPriority) {
80  if ( isRunning() ) { return false; }
81  isRunning(true); // This is not ideal, as it's not perfectly atomic (i.e. someone can query isRunning before this gets set).
82  Thread thread(&Threadable::executeThreadFunction,*this, priority);
83  return true;
84  }
90  Parameter<bool> isRunning;
91 
92 protected:
93  Threadable() : isRunning(false) {}
94 
95  virtual void runnable() = 0;
96 
97 private:
98  void executeThreadFunction() {
99  runnable();
100  isRunning(false);
101  }
102 };
103 
104 } // namespace ecl
105 
106 #endif /* ECL_IS_POSIX */
107 #endif /* ECL_THREADS_THREADABLE_POS_HPP_ */
thread.hpp
Thread interfaces.
ecl::DefaultPriority
@ DefaultPriority
Definition: priority_common.hpp:43
priority.hpp
Priority scheduling for threads.
parameter.hpp
macros.hpp
ecl
Embedded control libraries.
ecl::Priority
Priority
Shared abstraction of the scheduling priorities.
Definition: priority_common.hpp:36
ECL_PUBLIC
#define ECL_PUBLIC


ecl_threads
Author(s): Daniel Stonier
autogenerated on Sun Aug 2 2020 03:12:17