Skip to content

Commit

Permalink
Use C++11 synchronization classes under macOS too (#1342)
Browse files Browse the repository at this point in the history
There doesn't seem to be any reason to prefer using Boost libraries to
standard C++ classes under macOS, so use the latter ones unconditionally
on this platform too, just as it was already done for the other Unix
systems.

This notably avoids dependencies on the compiled Boost libraries, which
don't have to be compiled before building C++ REST SDK any more.
  • Loading branch information
vadz authored Feb 23, 2020
1 parent 23e4c61 commit 43f6f34
Showing 1 changed file with 9 additions and 20 deletions.
29 changes: 9 additions & 20 deletions Release/include/pplx/pplxlinux.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,14 @@
#include "pthread.h"
#include <signal.h>

#if defined(__APPLE__)
#include <boost/thread/condition_variable.hpp>
#include <boost/thread/mutex.hpp>
#include <dispatch/dispatch.h>
#else
#include <atomic>
#include <condition_variable>
#include <mutex>
#endif

#include "pplx/pplxinterface.h"

namespace pplx
{
#if defined(__APPLE__)
namespace cpprest_synchronization = ::boost;
#else
namespace cpprest_synchronization = ::std;
#endif
namespace details
{
namespace platform
Expand All @@ -68,8 +57,8 @@ __declspec(noinline) inline static size_t CaptureCallstack(void**, size_t, size_
class event_impl
{
private:
cpprest_synchronization::mutex _lock;
cpprest_synchronization::condition_variable _condition;
std::mutex _lock;
std::condition_variable _condition;
bool _signaled;

public:
Expand All @@ -79,28 +68,28 @@ class event_impl

void set()
{
cpprest_synchronization::lock_guard<cpprest_synchronization::mutex> lock(_lock);
std::lock_guard<std::mutex> lock(_lock);
_signaled = true;
_condition.notify_all();
}

void reset()
{
cpprest_synchronization::lock_guard<cpprest_synchronization::mutex> lock(_lock);
std::lock_guard<std::mutex> lock(_lock);
_signaled = false;
}

unsigned int wait(unsigned int timeout)
{
cpprest_synchronization::unique_lock<cpprest_synchronization::mutex> lock(_lock);
std::unique_lock<std::mutex> lock(_lock);
if (timeout == event_impl::timeout_infinite)
{
_condition.wait(lock, [this]() -> bool { return _signaled; });
return 0;
}
else
{
cpprest_synchronization::chrono::milliseconds period(timeout);
std::chrono::milliseconds period(timeout);
auto status = _condition.wait_for(lock, period, [this]() -> bool { return _signaled; });
_ASSERTE(status == _signaled);
// Return 0 if the wait completed as a result of signaling the event. Otherwise, return timeout_infinite
Expand Down Expand Up @@ -195,7 +184,7 @@ class recursive_lock_impl
}

private:
cpprest_synchronization::mutex _M_cs;
std::mutex _M_cs;
std::atomic<long> _M_owner;
long _M_recursionCount;
};
Expand All @@ -219,7 +208,7 @@ class linux_scheduler : public pplx::scheduler_interface

/// <summary>
/// A generic RAII wrapper for locks that implements the critical_section interface
/// cpprest_synchronization::lock_guard
/// std::lock_guard
/// </summary>
template<class _Lock>
class scoped_lock
Expand All @@ -244,7 +233,7 @@ namespace extensibility
{
typedef ::pplx::details::event_impl event_t;

typedef cpprest_synchronization::mutex critical_section_t;
typedef std::mutex critical_section_t;
typedef scoped_lock<critical_section_t> scoped_critical_section_t;

typedef ::pplx::details::reader_writer_lock_impl reader_writer_lock_t;
Expand Down

0 comments on commit 43f6f34

Please sign in to comment.