ADTF  3.18.2
kernel_thread.h
Go to the documentation of this file.
1 
7 #pragma once
8 #include "services/kernel_intf.h"
9 
10 namespace adtf
11 {
12 
13 namespace system
14 {
15 
21 {
22  private:
23  friend class cKernelThreadHelperRunnable;
24  struct ImplBase;
25  typedef std::shared_ptr<ImplBase> shared_base_type;
26 
27  struct ImplBase
28  {
30  shared_base_type pThisPtr;
31  inline virtual ~ImplBase() {}
32  virtual void Run() = 0;
33  };
34 
35  template<typename Callable>
36  struct Impl : public ImplBase
37  {
38  Callable pFunc;
39 
40  Impl(Callable&& pFunc) : pFunc(std::forward<Callable>(pFunc))
41  {
42  }
43 
44  void Run()
45  {
46  pFunc();
47  }
48  };
49 
50  template<typename Callable>
51  std::shared_ptr<Impl<Callable>> MakeCallable(Callable&& pFunc)
52  {
53  return std::make_shared<Impl<Callable>>(std::forward<Callable>(pFunc));
54  }
55 
56  shared_base_type m_pCallable;
57 
58  public:
64 
65  kernel_thread(const kernel_thread&) = delete;
66 
71 
75  template<typename Callable, typename ...Args>
76  kernel_thread(const adtf::services::IKernel::tSchedulingInfo& sScheduling, const char* strName,
77  Callable&& pFunc, Args&&... args): kernel_thread()
78  {
79  m_pCallable = MakeCallable(std::bind(std::forward<Callable>(pFunc),
80  std::forward<Args>(args)...));
81  Create(strName, sScheduling);
82  }
83 
87  template<typename Callable, typename ...Args>
88  kernel_thread(const char* strName, Callable&& pFunc, Args&&... args):
89  kernel_thread(adtf::services::IKernel::tSchedulingInfo(), strName,
90  std::forward<Callable>(pFunc),
91  std::forward<Args>(args)...)
92  {
93  }
94 
99 
106 
111  void Swap(kernel_thread& oOther);
112 
117  bool Joinable() const;
118 
126  tResult Join(tTimeStamp nTimeout = -1);
127 
134 
141 
148 
153  bool IsCurrentThread() const;
154 
155  private:
156  tResult Create(const char* strName, const adtf::services::IKernel::tSchedulingInfo& sScheduling);
157 };
158 
159 }
160 
161 }
Class that manages a kernel thread.
Definition: kernel_thread.h:21
kernel_thread(kernel_thread &&)
Move constructor.
tResult SetScheduling(const adtf::services::IKernel::tSchedulingInfo &sScheduling)
Changes the scheduling parameters of the thread.
kernel_thread(const adtf::services::IKernel::tSchedulingInfo &sScheduling, const char *strName, Callable &&pFunc, Args &&... args)
Constructor that allows the definition of scheduling parameters.
Definition: kernel_thread.h:76
tResult Detach()
Detaches from the underlying kernel thread.
bool IsCurrentThread() const
Check if the executing thread is managed by this thread object.
kernel_thread(const char *strName, Callable &&pFunc, Args &&... args)
Constructor that creates a new thread.
Definition: kernel_thread.h:88
bool Joinable() const
Whether or not the thread is joinable.
tResult GetScheduling(adtf::services::IKernel::tSchedulingInfo &sScheduling) const
Retrieves the scheduling parameters of the thread.
kernel_thread & operator=(kernel_thread &&oOther)
Move assignment operator.
void Swap(kernel_thread &oOther)
Swaps two threads.
kernel_thread()
Default constructor.
tResult Join(tTimeStamp nTimeout=-1)
Join the thread.
Object pointer implementation used for reference counting on objects of type IObject.
Definition: object_ptr.h:163
Copyright © Audi Electronics Venture GmbH.
Namespace for entire ADTF SDK.
Struct for defining scheduling settings of a thread or timer.
Definition: kernel_intf.h:82