Skip to content

Commit

Permalink
Use STL implementation of Timed/RecursiveTimedMutex when MSVC >= 19.36 (
Browse files Browse the repository at this point in the history
#3904)

* Refs #19642: Use STL implementation of Timed/RecursiveTimedMutex in MSVC >= 19.36

Signed-off-by: Mario Dominguez <[email protected]>

* Refs #19642: Linter

Signed-off-by: Mario Dominguez <[email protected]>

---------

Signed-off-by: Mario Dominguez <[email protected]>
  • Loading branch information
Mario-DL committed Oct 9, 2023
1 parent 9e69e26 commit e2137cb
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions include/fastrtps/utils/TimedMutex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,16 @@
#include <iostream>

#if defined(_WIN32)

#if defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 193632528
#include <mutex>
#else
#include <thread>
extern int clock_gettime(
int,
struct timespec* tv);
#endif // if defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 193632528

#elif _GTHREAD_USE_MUTEX_TIMEDLOCK
#include <mutex>
#else
Expand All @@ -38,14 +44,12 @@ namespace fastrtps {

#if defined(_WIN32)

#if defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 193632528
using TimedMutex = std::timed_mutex;
using RecursiveTimedMutex = std::recursive_timed_mutex;
#else
class TimedMutex
{
// On MSVC 19.36.32528.95 `xtime` was changed into `_timespec64`.
// See https://github.com/eProsima/Fast-DDS/issues/3451
// See https://github.com/microsoft/STL/pull/3594
#if defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 193632528
using xtime = _timespec64;
#endif // _MSC_FULL_VER check

public:

Expand Down Expand Up @@ -190,6 +194,8 @@ class RecursiveTimedMutex

_Mtx_t mutex_;
};
#endif // if defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 193632528

#elif _GTHREAD_USE_MUTEX_TIMEDLOCK || !defined(__unix__)
using TimedMutex = std::timed_mutex;
using RecursiveTimedMutex = std::recursive_timed_mutex;
Expand Down

0 comments on commit e2137cb

Please sign in to comment.