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
12namespace yarp::os {
13
14
21{
22public:
27 Thread();
28
32 virtual ~Thread();
33
46 virtual void run() = 0;
47
55 virtual void onStop();
56
66 bool start();
67
76 bool stop();
77
78
83 virtual void beforeStart();
84
90 virtual void afterStart(bool success);
91
92
104 virtual bool threadInit()
105 {
106 return true;
107 }
108
115 virtual void threadRelease()
116 {
117 }
118
119
125 bool isStopping();
126
132 bool isRunning();
133
138 static int getCount();
139
144 long int getKey();
145
150 static long int getKeyOfCaller();
151
165 int setPriority(int priority, int policy = -1);
166
171 int getPriority();
172
173
178 int getPolicy();
179
188 bool join(double seconds = -1);
189
193 static void yield();
194
195
196#ifndef YARP_NO_DEPRECATED // since YARP 3.0.0
204 YARP_DEPRECATED
205 void setOptions(int stackSize = 0)
206 {
207 }
208
215 static void setDefaultStackSize(int stackSize)
216 {
217 }
218#endif // YARP_NO_DEPRECATED
219
220
221#ifndef DOXYGEN_SHOULD_SKIP_THIS
222private:
223 class Private;
224 Private* const mPriv;
225#endif
226};
227
228} // namespace yarp::os
229
230#endif // YARP_OS_THREAD_H
An abstraction for a thread of execution.
Definition: Thread.h:21
virtual void threadRelease()
Release method.
Definition: Thread.h:115
void setOptions(int stackSize=0)
Set the stack size for the new thread.
Definition: Thread.h:205
virtual bool threadInit()
Initialization method.
Definition: Thread.h:104
static void setDefaultStackSize(int stackSize)
Set the default stack size for all threads created after this point.
Definition: Thread.h:215
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:92
void yield()
The calling thread releases its remaining quantum upon calling this function.
Definition: Time.cpp:138
An interface to the operating system, including Port based communication.
#define YARP_os_API
Definition: api.h:18