helpers.h
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // Copyright 2022 FZI Forschungszentrum Informatik
5 // Created on behalf of Universal Robots A/S
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 // -- END LICENSE BLOCK ------------------------------------------------
19 
20 //----------------------------------------------------------------------
27 //----------------------------------------------------------------------
28 
29 #ifndef UR_CLIENT_LIBRARY_HELPERS_H_INCLUDED
30 #define UR_CLIENT_LIBRARY_HELPERS_H_INCLUDED
31 
32 #include <chrono>
33 #include <functional>
34 #ifdef _WIN32
35 
36 # define NOMINMAX
37 # define WIN32_LEAN_AND_MEAN
38 # include <Windows.h>
39 
40 # ifdef ERROR
41 # undef ERROR
42 # endif // ERROR
43 
44 # define SCHED_FIFO (1)
45 
46 typedef HANDLE pthread_t;
47 
48 static inline pthread_t pthread_self()
49 {
50  return ::GetCurrentThread();
51 }
52 
53 static inline int sched_get_priority_max(int policy)
54 {
55  (void)policy;
56  return THREAD_PRIORITY_TIME_CRITICAL;
57 }
58 
59 #else // _WIN32
60 
61 # include <pthread.h>
62 
63 #endif // _WIN32
64 
65 namespace urcl
66 {
67 bool setFiFoScheduling(pthread_t& thread, const int priority);
68 
79 void waitFor(std::function<bool()> condition, const std::chrono::milliseconds timeout,
80  const std::chrono::milliseconds check_interval = std::chrono::milliseconds(50));
81 } // namespace urcl
82 #endif // ifndef UR_CLIENT_LIBRARY_HELPERS_H_INCLUDED
urcl::setFiFoScheduling
bool setFiFoScheduling(pthread_t &thread, const int priority)
Definition: helpers.cpp:46
urcl::waitFor
void waitFor(std::function< bool()> condition, const std::chrono::milliseconds timeout, const std::chrono::milliseconds check_interval=std::chrono::milliseconds(50))
Wait for a condition to be true.
Definition: helpers.cpp:105
urcl
Definition: bin_parser.h:36


ur_client_library
Author(s): Thomas Timm Andersen, Simon Rasmussen, Felix Exner, Lea Steffen, Tristan Schnell
autogenerated on Mon May 26 2025 02:35:58