//----------------------------------------------- // turnstile2.h: shared.h + turnstile //----------------------------------------------- #ifndef turnstile2_h #define turnstile2_h //----------------------------------------------- #include // std::size_t #include // std::binary_semaphore #include // std::shared_mutex //----------------------------------------------- class turnstile2_lock { public: turnstile2_lock(std::size_t) {} void reader_lock() { turnstile.acquire(); turnstile.release(); sm.lock_shared(); } void reader_unlock() { sm.unlock_shared(); } void writer_lock() { turnstile.acquire(); turnstile.release(); sm.lock(); } void writer_unlock() { sm.unlock(); } private: std::binary_semaphore turnstile{1}; std::shared_mutex sm; }; //----------------------------------------------- #endif // turnstile_h