src.dualinventive.com/jjacobs/dinetrpcll-sniffer/libdipp/include/di/Semaphore.h

49 lines
923 B
C++

/**
* @file include/di/Semaphore.h
* @brief Counting semaphore implementation
* @date March 31, 2016
* @author R.W.A. van der Heijden
* @copyright 2016 Dual Inventive Technology Centre B.V.
*
* Counting semaphore implementation using C++ STL
*/
#ifndef INCLUDE_DI_SEMAPHORE_H_
#define INCLUDE_DI_SEMAPHORE_H_
#include <memory>
#include <mutex>
#include <condition_variable>
namespace Di {
/**
* @class Semaphore
*
* Counting semaphore implementation using C++ STL
*/
class Semaphore {
public:
/**
* Constructor, initialized the counter
*/
Semaphore();
/**
* Notify the waiting process
*/
void notify(void);
/**
* Wait for a notification
*/
void wait(void);
private:
std::mutex __mutex; //!< Mutex used for condition
std::condition_variable __condition; //!< Condition for waiting
uint64_t __count; //!< Semaphore counter
};
} // namespace Di
#endif // INCLUDE_DI_SEMAPHORE_H_