YARP
Yet Another Robot Platform
ThreadImpl.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_IMPL_THREADIMPL_H
8#define YARP_OS_IMPL_THREADIMPL_H
9
10#include <yarp/os/Semaphore.h>
11
12#include <atomic>
13#include <thread>
14
15namespace yarp::os::impl {
16
21{
22public:
23 virtual ~ThreadImpl();
24
25 int join(double seconds = -1);
26 virtual void run();
27 virtual void close();
28
29 // similar to close, but it does not call join (does not wait for thread termination)
30 void askToClose();
31
32 // should throw if no success
33 virtual bool start();
34
35 bool isClosing();
36 bool isRunning();
37
38 virtual void beforeStart();
39 virtual void afterStart(bool success);
40
41 virtual bool threadInit();
42 virtual void threadRelease();
43
44 static int getCount();
45
46 // get a unique key
47 long int getKey();
48 static long int getKeyOfCaller();
49
50 //should become private, when the thread is friend
51 void notify(bool s);
52 void notifyOpened(bool s)
53 {
54 opened = s;
55 }
56 void synchroWait();
57 void synchroPost();
58
59 int setPriority(int priority = -1, int policy = -1);
60 int getPriority();
61 int getPolicy();
62 long getTid();
63
64 long tid{-1};
66
67 static void yield();
68
69private:
70 int defaultPriority{-1};
71 int defaultPolicy{-1};
73 YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::atomic<bool>) active{false};
74 bool opened{false};
75 bool closing{false};
76 bool needJoin{false};
77
78 yarp::os::Semaphore synchro{0};
79
80 bool initWasSuccessful{false};
81};
82
83} // namespace yarp::os::impl
84
85#endif // YARP_OS_IMPL_THREADIMPL_H
A class for thread synchronization and mutual exclusion.
Definition: Semaphore.h:25
An abstraction for a thread of execution.
Definition: ThreadImpl.h:21
void notifyOpened(bool s)
Definition: ThreadImpl.h:52
std::thread::id id
Definition: ThreadImpl.h:65
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
The components from which ports and connections are built.
#define YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(x)
Suppress MSVC C4251 warning for the declaration.
Definition: system.h:338
#define YARP_os_impl_API
Definition: api.h:46