YARP
Yet Another Robot Platform
Thread.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2019 Istituto Italiano di Tecnologia (IIT)
3  * Copyright (C) 2006-2010 RobotCub Consortium
4  * All rights reserved.
5  *
6  * This software may be modified and distributed under the terms of the
7  * BSD-3-Clause license. See the accompanying LICENSE file for details.
8  */
9 
10 #ifndef YARP_OS_THREAD_H
11 #define YARP_OS_THREAD_H
12 
13 #include <yarp/os/api.h>
14 
15 namespace yarp {
16 namespace os {
17 
18 
25 {
26 public:
31  Thread();
32 
36  virtual ~Thread();
37 
50  virtual void run() = 0;
51 
59  virtual void onStop();
60 
70  bool start();
71 
80  bool stop();
81 
82 
87  virtual void beforeStart();
88 
94  virtual void afterStart(bool success);
95 
96 
108  virtual bool threadInit()
109  {
110  return true;
111  }
112 
119  virtual void threadRelease()
120  {
121  }
122 
123 
129  bool isStopping();
130 
136  bool isRunning();
137 
142  static int getCount();
143 
148  long int getKey();
149 
154  static long int getKeyOfCaller();
155 
169  int setPriority(int priority, int policy = -1);
170 
175  int getPriority();
176 
177 
182  int getPolicy();
183 
192  bool join(double seconds = -1);
193 
197  static void yield();
198 
199 
200 #ifndef YARP_NO_DEPRECATED // since YARP 3.0.0
201 
209  void setOptions(int stackSize = 0)
210  {
211  }
212 
219  static void setDefaultStackSize(int stackSize)
220  {
221  }
222 #endif // YARP_NO_DEPRECATED
223 
224 
225 #ifndef DOXYGEN_SHOULD_SKIP_THIS
226 private:
227  class Private;
228  Private* const mPriv;
229 #endif
230 };
231 
232 } // namespace os
233 } // namespace yarp
234 
235 #endif // YARP_OS_THREAD_H
void setOptions(int stackSize=0)
Set the stack size for the new thread.
Definition: Thread.h:209
#define YARP_OS_API
Definition: api.h:19
The main, catch-all namespace for YARP.
Definition: numeric.h:47
void yield()
The calling thread releases its remaining quantum upon calling this function.
Definition: Time.cpp:138
#define YARP_DEPRECATED
Expands to either the standard [[deprecated]] attribute or a compiler-specific decorator such as __at...
Definition: compiler.h:2851
static void setDefaultStackSize(int stackSize)
Set the default stack size for all threads created after this point.
Definition: Thread.h:219
virtual void threadRelease()
Release method.
Definition: Thread.h:119
An abstraction for a thread of execution.
Definition: Thread.h:24
virtual bool threadInit()
Initialization method.
Definition: Thread.h:108