18#if defined(YARP_HAS_ACE)
19# include <ace/Thread.h>
27# include <sys/syscall.h>
63 bool success = thread->threadInit();
64 thread->notify(success);
65 thread->notifyOpened(success);
66 thread->synchroPost();
71 thread->id = std::this_thread::get_id();
77 thread->tid =
static_cast<long int>(std::hash<std::thread::id>()(thread->id));
80 thread->setPriority();
82 thread->threadRelease();
88 thread->notify(
false);
89 thread->synchroPost();
110#if defined(__linux__)
115 return static_cast<long int>(std::hash<std::thread::id>()(std::this_thread::get_id()));
125 if (!initWasSuccessful) {
137 if (thread.joinable()) {
144 while (synchro.
check()) {
188 initWasSuccessful =
false;
191 int result = thread.joinable() ? 0 : 1;
199 initWasSuccessful =
true;
248 if (priority == -1) {
249 priority = defaultPriority;
250 policy = defaultPolicy;
252 defaultPriority = priority;
253 defaultPolicy = policy;
255 if (active && priority != -1) {
256#if defined(YARP_HAS_ACE)
257 if (std::is_same<std::thread::native_handle_type, ACE_hthread_t>::value) {
258 return ACE_Thread::setprio(thread.native_handle(), priority, policy);
260 yCError(
THREADIMPL,
"Cannot set priority as std::thread::native_handle_type is not ACE_hthread_t");
261#elif defined(__unix__) || defined(__APPLE__)
262 if (std::is_same<std::thread::native_handle_type, pthread_t>::value) {
266 return (
ret != 0) ? -1 : 0;
268 yCError(
THREADIMPL,
"Cannot set priority as std::thread::native_handle_type is not pthread_t");
279 int prio = defaultPriority;
281#if defined(YARP_HAS_ACE)
282 if (std::is_same<std::thread::native_handle_type, ACE_hthread_t>::value) {
283 ACE_Thread::getprio(thread.native_handle(),
prio);
287#elif defined(__unix__) || defined(__APPLE__)
288 if (std::is_same<std::thread::native_handle_type, pthread_t>::value) {
306 int policy = defaultPolicy;
308#if defined(YARP_HAS_ACE)
309 if (std::is_same<std::thread::native_handle_type, ACE_hthread_t>::value) {
311 ACE_Thread::getprio(thread.native_handle(),
prio, policy);
315#elif defined(__unix__) || defined(__APPLE__)
316 if (std::is_same<std::thread::native_handle_type, pthread_t>::value) {
319 policy = defaultPolicy;
338 std::this_thread::yield();
static std::atomic< int > threadCount
void theExecutiveBranch(void *args)
A mini-server for performing network communication in the background.
bool waitWithTimeout(double timeoutInSeconds)
Try to decrement the counter, even if we must wait - but don't wait forever.
void wait()
Decrement the counter, even if we must wait to do that.
bool check()
Decrement the counter, unless that would require waiting.
void post()
Increment the counter.
An abstraction for a thread of execution.
virtual bool threadInit()
virtual void threadRelease()
int join(double seconds=-1)
virtual void afterStart(bool success)
virtual void beforeStart()
static long int getKeyOfCaller()
int setPriority(int priority=-1, int policy=-1)
#define yCError(component,...)
#define yCDebug(component,...)
#define YARP_OS_LOG_COMPONENT(name, name_string)
The components from which ports and connections are built.