Skip to content

Commit 5c9a5f1

Browse files
authored
Merge pull request #3039 from randaz81/cpp_20
C++20 support
2 parents bd943af + 08ce351 commit 5c9a5f1

File tree

4 files changed

+72
-57
lines changed

4 files changed

+72
-57
lines changed

cmake/YarpSystemCheck.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ include(GNUInstallDirs)
2121
# These variables are used by try_compile, so they must be set here
2222

2323
set(CMAKE_CXX_EXTENSIONS OFF)
24-
set(CMAKE_CXX_STANDARD 17)
24+
set(CMAKE_CXX_STANDARD 20)
2525
set(CMAKE_CXX_STANDARD_REQUIRED ON)
2626

2727

extern/catch2/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ project(YARP_catch2)
66
add_library(YARP_catch2 STATIC)
77
add_library(YARP::YARP_catch2 ALIAS YARP_catch2)
88

9+
if(MSVC)
10+
#This is required because of https://github.com/catchorg/Catch2/issues/2174
11+
if(CMAKE_GENERATOR MATCHES "Visual Studio")
12+
target_compile_options(YARP_catch2 PRIVATE "/Zc:hiddenFriend-")
13+
endif()
14+
if(CMAKE_GENERATOR MATCHES "Ninja")
15+
target_compile_options(YARP_catch2 PRIVATE "/Zc:hiddenFriend-")
16+
endif()
17+
endif(MSVC)
18+
919
set(YARP_catch2_SRCS
1020
catch2/catch_amalgamated.cpp
1121
)

src/devices/VirtualAnalogWrapper/VirtualAnalogWrapper.h

Lines changed: 50 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,55 @@
4343
// TODO add IVirtualAnalogSensor interface to have Channels number and status??
4444

4545

46-
class AnalogSubDevice;
46+
class AnalogSubDevice
47+
{
48+
public:
49+
AnalogSubDevice();
50+
~AnalogSubDevice();
51+
52+
bool attach(yarp::dev::PolyDriver* driver, const std::string& key);
53+
void detach();
54+
55+
bool configure(int map0, int map1, const std::string& key);
56+
57+
bool isAttached() { return mIsAttached; }
58+
59+
void setTorque(int joint, double torque)
60+
{
61+
if (joint < mMap0 || mMap1 < joint) {
62+
return;
63+
}
64+
65+
mTorques[joint - mMap0] = torque;
66+
}
67+
68+
void resetTorque()
69+
{
70+
mTorques.zero();
71+
}
72+
73+
void flushTorques()
74+
{
75+
if (mpSensor) {
76+
mpSensor->updateVirtualAnalogSensorMeasure(mTorques);
77+
}
78+
}
79+
80+
const std::string& getKey() { return mKey; }
81+
82+
protected:
83+
std::string mKey;
84+
85+
int mMap0, mMap1;
86+
87+
yarp::sig::Vector mTorques;
88+
89+
bool mIsConfigured;
90+
bool mIsAttached;
91+
double lastRecvMsg{ 0.0 };
92+
yarp::dev::PolyDriver* mpDevice;
93+
yarp::dev::IVirtualAnalogSensor* mpSensor;
94+
};
4795

4896
/**
4997
* @ingroup dev_impl_wrapper
@@ -68,7 +116,7 @@ class VirtualAnalogWrapper :
68116
VirtualAnalogWrapper& operator=(const VirtualAnalogWrapper&) = delete;
69117
VirtualAnalogWrapper& operator=(VirtualAnalogWrapper&&) = delete;
70118

71-
~VirtualAnalogWrapper() override
119+
~VirtualAnalogWrapper()
72120
{
73121
close();
74122
}
@@ -106,56 +154,4 @@ class VirtualAnalogWrapper :
106154
yarp::os::BufferedPort<yarp::os::Bottle> mPortInputTorques;
107155
};
108156

109-
110-
class AnalogSubDevice
111-
{
112-
public:
113-
AnalogSubDevice();
114-
~AnalogSubDevice();
115-
116-
bool attach(yarp::dev::PolyDriver *driver, const std::string &key);
117-
void detach();
118-
119-
bool configure(int map0, int map1, const std::string &key);
120-
121-
bool isAttached(){ return mIsAttached; }
122-
123-
void setTorque(int joint,double torque)
124-
{
125-
if (joint < mMap0 || mMap1 < joint) {
126-
return;
127-
}
128-
129-
mTorques[joint-mMap0]=torque;
130-
}
131-
132-
void resetTorque()
133-
{
134-
mTorques.zero();
135-
}
136-
137-
void flushTorques()
138-
{
139-
if (mpSensor) {
140-
mpSensor->updateVirtualAnalogSensorMeasure(mTorques);
141-
}
142-
}
143-
144-
const std::string& getKey(){ return mKey; }
145-
146-
protected:
147-
std::string mKey;
148-
149-
int mMap0,mMap1;
150-
151-
yarp::sig::Vector mTorques;
152-
153-
bool mIsConfigured;
154-
bool mIsAttached;
155-
double lastRecvMsg{0.0};
156-
yarp::dev::PolyDriver *mpDevice;
157-
yarp::dev::IVirtualAnalogSensor *mpSensor;
158-
};
159-
160-
161157
#endif // YARP_DEV_VIRTUALANALOGWRAPPER_VIRTUALANALOGWRAPPER_H

src/libYARP_os/src/yarp/os/Log.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ class YARP_os_API Log
9797
LogTypeReserved = 0xFF
9898
};
9999

100+
static std::mutex* getLogMutex()
101+
{
102+
static std::mutex m;
103+
return &m;
104+
}
105+
100106
void trace(const char* msg, ...) const YARP_ATTRIBUTE_FORMAT(printf, 2, 3);
101107
void debug(const char* msg, ...) const YARP_ATTRIBUTE_FORMAT(printf, 2, 3);
102108
void info(const char* msg, ...) const YARP_ATTRIBUTE_FORMAT(printf, 2, 3);
@@ -191,11 +197,14 @@ class YARP_os_API Log
191197
return !flag.test_and_set(); \
192198
}
193199

200+
//The mutex definition was initially placed inside the lambda function below.
201+
//It was moved outside because it seems that the destruction of the
202+
//static mutex leads to a segfault on Windows platform when executing CI (LogTest.cpp).
194203
#define YARP_THROTTLE_CALLBACK(period) \
195204
[](){ \
196205
static double last = -period; \
197-
static std::mutex mutex; \
198-
std::lock_guard<std::mutex> lock(mutex); \
206+
std::mutex* mutex_throttle_callback = yarp::os::Log::getLogMutex(); \
207+
std::lock_guard<std::mutex> lock(*mutex_throttle_callback);\
199208
double now = yarp::os::SystemClock::nowSystem(); \
200209
if (now >= last + period) { \
201210
last = now; \

0 commit comments

Comments
 (0)