16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-22 06:59:18 +02:00

Merge branch 'tmj-dev' into milek-dev

This commit is contained in:
milek7
2018-10-01 21:00:27 +02:00
47 changed files with 1674 additions and 972 deletions

View File

@@ -313,3 +313,62 @@ glm::dvec3 LoadPoint( class cParser &Input );
// extracts a group of tokens from provided data stream
std::string
deserialize_random_set( cParser &Input, char const *Break = "\n\r\t ;" );
namespace threading {
// simple POD pairing of a data item and a mutex
// NOTE: doesn't do any locking itself, it's merely for cleaner argument arrangement and passing
template <typename Type_>
struct lockable {
Type_ data;
std::mutex mutex;
};
// basic wrapper simplifying use of std::condition_variable for most typical cases.
// has its own mutex and secondary variable to ignore spurious wakeups
class condition_variable {
public:
// methods
void
wait() {
std::unique_lock<std::mutex> lock( m_mutex );
m_condition.wait(
lock,
[ this ]() {
return m_spurious == false; } ); }
template< class Rep_, class Period_ >
void
wait_for( const std::chrono::duration<Rep_, Period_> &Time ) {
std::unique_lock<std::mutex> lock( m_mutex );
m_condition.wait_for(
lock,
Time,
[ this ]() {
return m_spurious == false; } ); }
void
notify_one() {
spurious( false );
m_condition.notify_one();
}
void
notify_all() {
spurious( false );
m_condition.notify_all();
}
void
spurious( bool const Spurious ) {
std::lock_guard<std::mutex> lock( m_mutex );
m_spurious = Spurious; }
private:
// members
mutable std::mutex m_mutex;
std::condition_variable m_condition;
bool m_spurious { true };
};
} // threading
//---------------------------------------------------------------------------