gearmulator

Emulation of classic VA synths of the late 90s/2000s that are based on Motorola 56300 family DSPs
Log | Files | Refs | Submodules | README | LICENSE

semaphore.h (526B)


      1 #pragma once
      2 
      3 #include <mutex>
      4 #include <condition_variable>
      5 #include <cstdint>
      6 
      7 namespace baseLib
      8 {
      9 	class Semaphore
     10 	{
     11 	public:
     12 		explicit Semaphore(const uint32_t _count = 0) : m_count(_count) {}
     13 
     14 		void wait()
     15 		{
     16 			std::unique_lock uLock(m_mutex);
     17 
     18 			m_cv.wait(uLock, [&]{ return m_count > 0; });
     19 
     20 			--m_count;
     21 		}
     22 
     23 		void notify()
     24 		{
     25 			{
     26 				std::lock_guard uLockHalt(m_mutex);
     27 				++m_count;
     28 			}
     29 			m_cv.notify_one();
     30 		}
     31 
     32 	private:
     33 		std::condition_variable m_cv;
     34 		std::mutex m_mutex;
     35 		uint32_t m_count;
     36 	};
     37 }