[Core] Added POSIX support (Experimental)
Thanks to Danman I don't think it actually compile although tried my best to correct code. Former-commit-id: c3366c2c924f7392f4d46824dafca63ecf7f1fea
This commit is contained in:
47
src/Nazara/Core/Posix/ConditionVariableImpl.cpp
Normal file
47
src/Nazara/Core/Posix/ConditionVariableImpl.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
// Copyright (C) 2012 Alexandre Janniaux
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Posix/ConditionVariableImpl.hpp>
|
||||
#include <Nazara/Core/Posix/MutexImpl.hpp>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
NzConditionVariableImpl::NzConditionVariableImpl()
|
||||
{
|
||||
pthread_cond_init(&m_cv, nullptr);
|
||||
}
|
||||
|
||||
NzConditionVariableImpl::~NzConditionVariableImpl()
|
||||
{
|
||||
pthread_cond_destroy(&m_cv);
|
||||
}
|
||||
|
||||
void NzConditionVariableImpl::Signal()
|
||||
{
|
||||
pthread_cond_signal(&m_cv);
|
||||
}
|
||||
|
||||
void NzConditionVariableImpl::SignalAll()
|
||||
{
|
||||
pthread_cond_broadcast(&m_cv);
|
||||
}
|
||||
|
||||
void NzConditionVariableImpl::Wait(NzMutexImpl* mutex)
|
||||
{
|
||||
pthread_cond_wait(&m_cv, mutex);
|
||||
}
|
||||
|
||||
bool NzConditionVariableImpl::Wait(NzMutexImpl* mutex, nzUInt32 timeout)
|
||||
{
|
||||
// get the current time
|
||||
timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
|
||||
// construct the time limit (current time + time to wait)
|
||||
timespec ti;
|
||||
ti.tv_nsec = (tv.tv_usec + (timeout % 1000)) * 1000000;
|
||||
ti.tv_sec = tv.tv_sec + (timeout / 1000) + (ti.tv_nsec / 1000000000);
|
||||
ti.tv_nsec %= 1000000000;
|
||||
|
||||
pthread_cond_timedwait(&m_cv,mutex, &tv);
|
||||
}
|
||||
Reference in New Issue
Block a user