29 #if (defined(_MSC_VER))
30 #error This file must not be included for Visual Studio
37 #include "cpprest/details/cpprest_compat.h"
39 #if defined(__APPLE__)
40 #include <dispatch/dispatch.h>
41 #include <boost/thread/mutex.hpp>
42 #include <boost/thread/condition_variable.hpp>
45 #include <condition_variable>
48 #include "pplx/pplxinterface.h"
53 #if defined(__APPLE__)
54 namespace cpprest_synchronization = ::boost;
56 namespace cpprest_synchronization = ::std;
65 _PPLXIMP
long _pplx_cdecl GetCurrentThreadId();
70 _PPLXIMP
void _pplx_cdecl YieldExecution();
75 __declspec(noinline) inline static
size_t CaptureCallstack(
void **,
size_t,
size_t)
87 cpprest_synchronization::mutex _lock;
88 cpprest_synchronization::condition_variable _condition;
92 static const unsigned int timeout_infinite = 0xFFFFFFFF;
101 cpprest_synchronization::lock_guard<cpprest_synchronization::mutex> lock(_lock);
103 _condition.notify_all();
108 cpprest_synchronization::lock_guard<cpprest_synchronization::mutex> lock(_lock);
112 unsigned int wait(
unsigned int timeout)
114 cpprest_synchronization::unique_lock<cpprest_synchronization::mutex> lock(_lock);
115 if (timeout == event_impl::timeout_infinite)
117 _condition.wait(lock, [
this]() ->
bool {
return _signaled; });
122 cpprest_synchronization::chrono::milliseconds period(timeout);
123 auto status = _condition.wait_for(lock, period, [
this]() ->
bool {
return _signaled; });
124 _ASSERTE(status == _signaled);
127 return status ? 0: event_impl::timeout_infinite;
133 return wait(event_impl::timeout_infinite);
144 pthread_rwlock_t _M_reader_writer_lock;
153 _M_reader_writer_lock.lock_read();
158 _M_reader_writer_lock.unlock();
169 pthread_rwlock_init(&_M_reader_writer_lock,
nullptr);
174 pthread_rwlock_destroy(&_M_reader_writer_lock);
179 pthread_rwlock_wrlock(&_M_reader_writer_lock);
184 pthread_rwlock_rdlock(&_M_reader_writer_lock);
189 pthread_rwlock_unlock(&_M_reader_writer_lock);
201 : _M_owner(-1), _M_recursionCount(0)
207 _ASSERTE(_M_owner == -1);
208 _ASSERTE(_M_recursionCount == 0);
213 auto id = ::pplx::details::platform::GetCurrentThreadId();
215 if ( _M_owner ==
id )
223 _M_recursionCount = 1;
229 _ASSERTE(_M_owner == ::pplx::details::platform::GetCurrentThreadId());
230 _ASSERTE(_M_recursionCount >= 1);
234 if ( _M_recursionCount == 0 )
242 cpprest_synchronization::mutex _M_cs;
243 volatile long _M_owner;
244 long _M_recursionCount;
247 #if defined(__APPLE__)
248 class apple_scheduler :
public pplx::scheduler_interface
254 _PPLXIMP
virtual void schedule(
TaskProc_t proc, _In_
void* param);
263 template<
class _Lock>
267 explicit scoped_lock(_Lock& _Critical_section) : _M_critical_section(_Critical_section)
269 _M_critical_section.lock();
274 _M_critical_section.unlock();
278 _Lock& _M_critical_section;
285 namespace extensibility
287 typedef ::pplx::details::event_impl event_t;
289 typedef cpprest_synchronization::mutex critical_section_t;
292 typedef ::pplx::details::reader_writer_lock_impl reader_writer_lock_t;
294 typedef ::pplx::extensibility::reader_writer_lock_t::scoped_lock_read scoped_read_lock_t;
296 typedef ::pplx::details::recursive_lock_impl recursive_lock_t;
303 #if defined(__APPLE__)
314 #ifndef _REPORT_PPLTASK_UNOBSERVED_EXCEPTION
315 #define _REPORT_PPLTASK_UNOBSERVED_EXCEPTION() do { \
319 #endif //_REPORT_PPLTASK_UNOBSERVED_EXCEPTION
324 __attribute__ ((always_inline))
325 inline
void* _ReturnAddress() {
return __builtin_return_address(0); }
void(_pplx_cdecl * TaskProc_t)(void *)
An elementary abstraction for a task, defined as void (__cdecl * TaskProc_t)(void *)...
Definition: pplxinterface.h:59
A generic RAII wrapper for locks that implements the critical_section interface cpprest_synchronizati...
Definition: pplxlinux.h:264
Definition: pplxlinux.h:250
The pplx namespace provides classes and functions that give you access to the Concurrency Runtime...
Definition: pplx.h:81
struct __declspec(novtable) scheduler_interface
Scheduler Interface
Definition: pplxinterface.h:64
Definition: pplxlinux.h:148
Recursive mutex
Definition: pplxlinux.h:196
Manual reset event
Definition: pplxlinux.h:84
Reader writer lock
Definition: pplxlinux.h:140
details::linux_scheduler default_scheduler_t
Default scheduler type
Definition: pplxlinux.h:306