Commit 07b432db authored by Pavel Vainerman's avatar Pavel Vainerman

добавлен тест rwmutex

parent d4e47234
......@@ -372,8 +372,7 @@ long IOBase::processingAsAO( IOBase* it, const std::shared_ptr<SMInterface>& shm
if( cal && cal->maxRaw != cal->minRaw ) // задана калибровка
{
// Калибруем в обратную сторону!!!
val = UniSetTypes::lcalibrate(val,
cal->minCal, cal->maxCal, cal->minRaw, cal->maxRaw, it->calcrop );
val = UniSetTypes::lcalibrate(val, cal->minCal, cal->maxCal, cal->minRaw, cal->maxRaw, it->calcrop );
}
}
}
......@@ -521,7 +520,7 @@ bool IOBase::initItem( IOBase* b, UniXML::iterator& it, const std::shared_ptr<SM
if( sid == DefaultObjectId )
{
if( dlog && dlog->is_crit() )
dlog->crit() << myname << "(readItem): (" << DefaultObjectId << ") Не удалось получить ID для датчика: "
dlog->crit() << myname << "(readItem): (" << DefaultObjectId << ") Unknown Sensor ID for "
<< sname << endl;
return false;
......@@ -550,7 +549,6 @@ bool IOBase::initItem( IOBase* b, UniXML::iterator& it, const std::shared_ptr<SM
msec = initIntProp(it, "offdelay", prefix, init_prefix_only, UniSetTimer::WaitUpTime);
b->ptOffDelay.setTiming(msec);
b->front = false;
std::string front_t( initProp(it, "iofront", prefix, init_prefix_only) );
......@@ -583,8 +581,8 @@ bool IOBase::initItem( IOBase* b, UniXML::iterator& it, const std::shared_ptr<SM
if( b->stype == UniversalIO::UnknownIOType )
{
if( dlog && dlog->is_crit() )
dlog->crit() << myname << "(IOBase::readItem): неизвестный iotype=: "
<< initProp(it, "iotype", prefix, init_prefix_only) << " для " << sname << endl;
dlog->crit() << myname << "(IOBase::readItem): Unknown iotype=: "
<< initProp(it, "iotype", prefix, init_prefix_only) << " for " << sname << endl;
return false;
}
......
......@@ -123,7 +123,7 @@ namespace UniSetTypes
private:
std::string nm;
friend class uniset_rwmutex_lock;
ost::ThreadLock m;
ost::ThreadLock m; // это рекурсивный mutex (!)
};
std::ostream& operator<<(std::ostream& os, uniset_rwmutex& m );
......
#include <catch.hpp>
// -----------------------------------------------------------------------------
#include <iostream>
#include <thread>
#include <future>
#include "Mutex.h"
#include "UniSetTypes.h"
// -----------------------------------------------------------------------------
using namespace std;
using namespace UniSetTypes;
......@@ -173,3 +176,52 @@ TEST_CASE("uniset_rwmutex_{wr|r}lock", "[mutex][basic]" )
CHECK_FALSE( m.try_lock() );
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
uniset_rwmutex g_mutex;
bool writer_thread( int num )
{
uniset_rwmutex_wrlock l(g_mutex);
msleep(1000);
return true;
}
bool reader_thread( int num )
{
uniset_rwmutex_rlock l(g_mutex);
msleep(50);
return true;
}
// -----------------------------------------------------------------------------
TEST_CASE("uniset_rwmutex_{wr|r} thread lock", "[mutex][threadlock][basic]" )
{
g_mutex.rlock();
std::vector< std::future<bool> > vw(3);
for( int w=0; w<3; w++ )
vw.push_back( std::async(std::launch::async, writer_thread,w) );
std::vector< std::future<bool> > vr(3);
for( int r=0; r<5; r++ )
vr.push_back( std::async(std::launch::async, reader_thread,r) );
msleep(10);
// read захватывают сразу без задержек..
for( auto&& i: vr )
{
if( i.valid() )
REQUIRE( i.get() == true );
}
// теперь отпускаю mutex
g_mutex.unlock();
// проверяем что write-ы завершают работу.
for( auto& i: vw )
{
if( i.valid() )
REQUIRE( i.get() == true );
}
}
// -----------------------------------------------------------------------------
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment