Botan  1.11.15
src/lib/utils/semaphore.h
Go to the documentation of this file.
00001 /*
00002 * Semaphore
00003 * (C) 2013 Joel Low
00004 *
00005 * Botan is released under the Simplified BSD License (see license.txt)
00006 */
00007 
00008 #ifndef BOTAN_SEMAPHORE_H__
00009 #define BOTAN_SEMAPHORE_H__
00010 
00011 #include <mutex>
00012 #include <condition_variable>
00013 
00014 namespace Botan {
00015 
00016 class Semaphore
00017    {
00018    public:
00019       Semaphore(int value = 0) : m_value(value), m_wakeups(0) {}
00020 
00021       void acquire();
00022 
00023       void release(size_t n = 1);
00024 
00025    private:
00026       int m_value;
00027       int m_wakeups;
00028       std::mutex m_mutex;
00029       std::condition_variable m_cond;
00030    };
00031 
00032 }
00033 
00034 #endif