salhelper: change oslCondition to osl::Condition

Condition is deprecated already, but there is no need for the
us to use the low-level C-API, when in fact there is a C++ fascade
that calls on this via the C++ abstraction, osl::Condition.

This will make it much easier to switch to using std::condition_variable

Change-Id: Ia362666ff241293e143de0fa1dc0bc3a990bef82
Reviewed-on: https://gerrit.libreoffice.org/35388
Reviewed-by: Chris Sherlock <chris.sherlock79@gmail.com>
Tested-by: Chris Sherlock <chris.sherlock79@gmail.com>
This commit is contained in:
Chris Sherlock 2017-03-18 18:32:13 +11:00
parent 5ec1713ae5
commit 3961387192
2 changed files with 11 additions and 12 deletions

View file

@ -22,7 +22,7 @@
#define INCLUDED_SALHELPER_CONDITION_HXX
#include <osl/conditn.h>
#include <osl/conditn.hxx>
#include <osl/mutex.hxx>
#include <salhelper/salhelperdllapi.h>
@ -53,8 +53,8 @@ namespace salhelper
Condition(Condition &) SAL_DELETED_FUNCTION;
void operator =(Condition &) SAL_DELETED_FUNCTION;
osl::Mutex& m_aMutex;
oslCondition m_aCondition;
osl::Mutex& m_aMutex;
osl::Condition m_aCondition;
};

View file

@ -33,14 +33,13 @@ using namespace salhelper;
Condition::Condition(osl::Mutex& aMutex)
: m_aMutex(aMutex),
m_aCondition(osl_createCondition())
m_aCondition()
{
}
Condition::~Condition()
{
osl_destroyCondition(m_aCondition);
}
@ -60,7 +59,7 @@ ConditionModifier::ConditionModifier(Condition& aCond)
ConditionModifier::~ConditionModifier()
{
if(m_aCond.applies())
osl_setCondition(m_aCond.m_aCondition);
m_aCond.m_aCondition.set();
m_aCond.m_aMutex.release();
}
@ -85,13 +84,13 @@ ConditionWaiter::ConditionWaiter(Condition& aCond)
: m_aCond(aCond)
{
while(true) {
osl_waitCondition(m_aCond.m_aCondition,nullptr);
m_aCond.m_aCondition.wait();
m_aCond.m_aMutex.acquire();
if(m_aCond.applies())
break;
else {
osl_resetCondition(m_aCond.m_aCondition);
m_aCond.m_aCondition.reset();
m_aCond.m_aMutex.release();
}
}
@ -106,8 +105,8 @@ ConditionWaiter::ConditionWaiter(Condition& aCond,sal_uInt32 milliSec)
aTime.Nanosec = 1000000 * ( milliSec % 1000 );
while(true) {
if( osl_waitCondition(m_aCond.m_aCondition,&aTime) ==
osl_cond_result_timeout )
if( m_aCond.m_aCondition.wait(&aTime) ==
osl::Condition::result_timeout )
throw timedout();
m_aCond.m_aMutex.acquire();
@ -115,7 +114,7 @@ ConditionWaiter::ConditionWaiter(Condition& aCond,sal_uInt32 milliSec)
if(m_aCond.applies())
break;
else {
osl_resetCondition(m_aCond.m_aCondition);
m_aCond.m_aCondition.reset();
m_aCond.m_aMutex.release();
}
}
@ -125,7 +124,7 @@ ConditionWaiter::ConditionWaiter(Condition& aCond,sal_uInt32 milliSec)
ConditionWaiter::~ConditionWaiter()
{
if(! m_aCond.applies())
osl_resetCondition(m_aCond.m_aCondition);
m_aCond.m_aCondition.reset();
m_aCond.m_aMutex.release();
}