//----------------------------------------------- // turnstile.h: shared.h + turnstile //----------------------------------------------- #ifndef turnstile_h #define turnstile_h //----------------------------------------------- #include // std::size_t #include // std::binary_semaphore #include // std::shared_mutex //----------------------------------------------- class turnstile_lock { public: turnstile_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(); sm.lock(); } void writer_unlock() { turnstile.release(); sm.unlock(); } private: std::binary_semaphore turnstile{1}; std::shared_mutex sm; }; //----------------------------------------------- #endif // turnstile_h