YARP
Yet Another Robot Platform
Thread.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef YARP_OS_THREAD_H
8 #define YARP_OS_THREAD_H
9 
10 #include <yarp/os/api.h>
11 
12 namespace yarp {
13 namespace os {
14 
15 
22 {
23 public:
28  Thread();
29 
33  virtual ~Thread();
34 
47  virtual void run() = 0;
48 
56  virtual void onStop();
57 
67  bool start();
68 
77  bool stop();
78 
79 
84  virtual void beforeStart();
85 
91  virtual void afterStart(bool success);
92 
93 
105  virtual bool threadInit()
106  {
107  return true;
108  }
109 
116  virtual void threadRelease()
117  {
118  }
119 
120 
126  bool isStopping();
127 
133  bool isRunning();
134 
139  static int getCount();
140 
145  long int getKey();
146 
151  static long int getKeyOfCaller();
152 
166  int setPriority(int priority, int policy = -1);
167 
172  int getPriority();
173 
174 
179  int getPolicy();
180 
189  bool join(double seconds = -1);
190 
194  static void yield();
195 
196 
197 #ifndef YARP_NO_DEPRECATED // since YARP 3.0.0
205  YARP_DEPRECATED
206  void setOptions(int stackSize = 0)
207  {
208  }
209 
216  static void setDefaultStackSize(int stackSize)
217  {
218  }
219 #endif // YARP_NO_DEPRECATED
220 
221 
222 #ifndef DOXYGEN_SHOULD_SKIP_THIS
223 private:
224  class Private;
225  Private* const mPriv;
226 #endif
227 };
228 
229 } // namespace os
230 } // namespace yarp
231 
232 #endif // YARP_OS_THREAD_H
An abstraction for a thread of execution.
Definition: Thread.h:22
virtual void threadRelease()
Release method.
Definition: Thread.h:116
void setOptions(int stackSize=0)
Set the stack size for the new thread.
Definition: Thread.h:206
virtual bool threadInit()
Initialization method.
Definition: Thread.h:105
static void setDefaultStackSize(int stackSize)
Set the default stack size for all threads created after this point.
Definition: Thread.h:216
virtual void run()=0
Main body of the new thread.
#define YARP_DEPRECATED
Expands to either the standard [[deprecated]] attribute or a compiler-specific decorator such as __at...
Definition: compiler.h:2884
ContainerT::value_type join(typename ContainerT::const_iterator begin, typename ContainerT::const_iterator end, const typename ContainerT::value_type &separator=", ")
Utility to join the elements in a container to a single string separated by a separator.
Definition: string.h:93
void yield()
The calling thread releases its remaining quantum upon calling this function.
Definition: Time.cpp:138
The main, catch-all namespace for YARP.
Definition: dirs.h:16
#define YARP_os_API
Definition: api.h:18