Commit 448e9baa authored by Pavel Vainerman's avatar Pavel Vainerman

backported to p9 as 2.8.1-alt0.M90P.1 (with rpmbph script)

parents 8136d52b 2febeb01
...@@ -49,9 +49,7 @@ UNetReceiver::UNetReceiver(const std::string& s_host, int _port ...@@ -49,9 +49,7 @@ UNetReceiver::UNetReceiver(const std::string& s_host, int _port
activated(false), activated(false),
cbuf(cbufSize), cbuf(cbufSize),
maxDifferens(20), maxDifferens(20),
lockUpdate(false), lockUpdate(false)
d_cache_init_ok(false),
a_cache_init_ok(false)
{ {
{ {
ostringstream s; ostringstream s;
...@@ -87,8 +85,11 @@ UNetReceiver::~UNetReceiver() ...@@ -87,8 +85,11 @@ UNetReceiver::~UNetReceiver()
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void UNetReceiver::setBufferSize( size_t sz ) noexcept void UNetReceiver::setBufferSize( size_t sz ) noexcept
{ {
cbufSize = sz; if( sz > 0 )
cbuf.resize(sz); {
cbufSize = sz;
cbuf.resize(sz);
}
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void UNetReceiver::setReceiveTimeout( timeout_t msec ) noexcept void UNetReceiver::setReceiveTimeout( timeout_t msec ) noexcept
...@@ -398,14 +399,14 @@ void UNetReceiver::update() noexcept ...@@ -398,14 +399,14 @@ void UNetReceiver::update() noexcept
upCount++; upCount++;
// Обработка дискретных // Обработка дискретных
auto d_iv = getDCache(p, !d_cache_init_ok); auto d_iv = getDCache(p);
for( size_t i = 0; i < p->dcount; i++ ) for( size_t i = 0; i < p->dcount; i++ )
{ {
try try
{ {
s_id = p->dID(i); s_id = p->dID(i);
c_it = &d_iv.cache[i]; c_it = &(*d_iv)[i];
if( c_it->id != s_id ) if( c_it->id != s_id )
{ {
...@@ -439,14 +440,14 @@ void UNetReceiver::update() noexcept ...@@ -439,14 +440,14 @@ void UNetReceiver::update() noexcept
} }
// Обработка аналоговых // Обработка аналоговых
auto a_iv = getACache(p, !a_cache_init_ok); auto a_iv = getACache(p);
for( size_t i = 0; i < p->acount; i++ ) for( size_t i = 0; i < p->acount; i++ )
{ {
try try
{ {
dat = &p->a_dat[i]; dat = &p->a_dat[i];
c_it = &a_iv.cache[i]; c_it = &(*a_iv)[i];
if( c_it->id != dat->id ) if( c_it->id != dat->id )
{ {
...@@ -719,7 +720,7 @@ void UNetReceiver::initIterators() noexcept ...@@ -719,7 +720,7 @@ void UNetReceiver::initIterators() noexcept
{ {
for( auto mit = d_icache_map.begin(); mit != d_icache_map.end(); ++mit ) for( auto mit = d_icache_map.begin(); mit != d_icache_map.end(); ++mit )
{ {
CacheVec& d_icache(mit->second.cache); CacheVec& d_icache = mit->second;
for( auto&& it : d_icache ) for( auto&& it : d_icache )
shm->initIterator(it.ioit); shm->initIterator(it.ioit);
...@@ -727,49 +728,35 @@ void UNetReceiver::initIterators() noexcept ...@@ -727,49 +728,35 @@ void UNetReceiver::initIterators() noexcept
for( auto mit = a_icache_map.begin(); mit != a_icache_map.end(); ++mit ) for( auto mit = a_icache_map.begin(); mit != a_icache_map.end(); ++mit )
{ {
CacheVec& a_icache(mit->second.cache); CacheVec& a_icache = mit->second;
for( auto&& it : a_icache ) for( auto&& it : a_icache )
shm->initIterator(it.ioit); shm->initIterator(it.ioit);
} }
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
UNetReceiver::CacheInfo& UNetReceiver::getDCache( UniSetUDP::UDPMessage* pack, bool force ) noexcept UNetReceiver::CacheVec* UNetReceiver::getDCache( UniSetUDP::UDPMessage* pack ) noexcept
{ {
// если элемента нет, он будет создан auto dit = d_icache_map.find(pack->getDataID());
CacheInfo& d_info = d_icache_map[pack->getDataID()];
if( !force && pack->dcount == d_info.cache.size() ) if( dit == d_icache_map.end() )
return d_info;
if( d_info.cache_init_ok && pack->dcount == d_info.cache.size() )
{ {
d_cache_init_ok = true; auto p = d_icache_map.emplace(pack->getDataID(), UNetReceiver::CacheVec());
auto it = d_icache_map.begin(); dit = p.first;
}
for( ; it != d_icache_map.end(); ++it )
{
d_info = it->second;
d_cache_init_ok = d_cache_init_ok && d_info.cache_init_ok;
if(d_cache_init_ok == false) CacheVec* d_info = &dit->second;
break;
}
if( pack->dcount == d_info->size() )
return d_info; return d_info;
}
unetinfo << myname << ": init dcache for " << pack->getDataID() << endl; unetinfo << myname << ": init dcache for " << pack->getDataID() << endl;
d_info.cache_init_ok = true; d_info->resize(pack->dcount);
d_info.cache.resize(pack->dcount);
size_t sz = d_info.cache.size();
auto conf = uniset_conf();
for( size_t i = 0; i < sz; i++ ) for( size_t i = 0; i < pack->dcount; i++ )
{ {
CacheItem& d(d_info.cache[i]); CacheItem& d = (*d_info)[i];
if( d.id != pack->d_id[i] ) if( d.id != pack->d_id[i] )
{ {
...@@ -781,42 +768,28 @@ UNetReceiver::CacheInfo& UNetReceiver::getDCache( UniSetUDP::UDPMessage* pack, b ...@@ -781,42 +768,28 @@ UNetReceiver::CacheInfo& UNetReceiver::getDCache( UniSetUDP::UDPMessage* pack, b
return d_info; return d_info;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
UNetReceiver::CacheInfo& UNetReceiver::getACache( UniSetUDP::UDPMessage* pack, bool force ) noexcept UNetReceiver::CacheVec* UNetReceiver::getACache( UniSetUDP::UDPMessage* pack ) noexcept
{ {
// если элемента нет, он будет создан auto ait = a_icache_map.find(pack->getDataID());
CacheInfo& a_info = a_icache_map[pack->getDataID()];
if( !force && pack->acount == a_info.cache.size() )
return a_info;
if( a_info.cache_init_ok && pack->acount == a_info.cache.size() ) if( ait == a_icache_map.end() )
{ {
a_cache_init_ok = true; auto p = a_icache_map.emplace(pack->getDataID(), UNetReceiver::CacheVec());
auto it = a_icache_map.begin(); ait = p.first;
}
for( ; it != a_icache_map.end(); ++it )
{
a_info = it->second;
a_cache_init_ok = a_cache_init_ok && a_info.cache_init_ok;
if(a_cache_init_ok == false) CacheVec* a_info = &ait->second;
break;
}
if( pack->acount == a_info->size() )
return a_info; return a_info;
}
unetinfo << myname << ": init icache for " << pack->getDataID() << endl;
a_info.cache_init_ok = true;
auto conf = uniset_conf();
a_info.cache.resize(pack->acount); unetinfo << myname << ": init acache for " << pack->getDataID() << endl;
size_t sz = a_info.cache.size(); a_info->resize(pack->acount);
for( size_t i = 0; i < sz; i++ ) for( size_t i = 0; i < pack->acount; i++ )
{ {
CacheItem& d(a_info.cache[i]); CacheItem& d = (*a_info)[i];
if( d.id != pack->a_dat[i].id ) if( d.id != pack->a_dat[i].id )
{ {
......
...@@ -20,8 +20,7 @@ ...@@ -20,8 +20,7 @@
#include <ostream> #include <ostream>
#include <memory> #include <memory>
#include <string> #include <string>
#include <queue> #include <vector>
#include <deque>
#include <unordered_map> #include <unordered_map>
#include <sigc++/sigc++.h> #include <sigc++/sigc++.h>
#include <ev++.h> #include <ev++.h>
...@@ -269,25 +268,14 @@ namespace uniset ...@@ -269,25 +268,14 @@ namespace uniset
}; };
typedef std::vector<CacheItem> CacheVec; typedef std::vector<CacheItem> CacheVec;
struct CacheInfo
{
CacheInfo():
cache_init_ok(false) {}
bool cache_init_ok = { false };
CacheVec cache;
};
// ключом является UDPMessage::getDataID() // ключом является UDPMessage::getDataID()
typedef std::unordered_map<long, CacheInfo> CacheMap; typedef std::unordered_map<long, CacheVec> CacheMap;
CacheMap d_icache_map; /*!< кэш итераторов для булевых */ CacheMap d_icache_map; /*!< кэш итераторов для булевых */
CacheMap a_icache_map; /*!< кэш итераторов для аналоговых */ CacheMap a_icache_map; /*!< кэш итераторов для аналоговых */
bool d_cache_init_ok = { false }; CacheVec* getDCache( UniSetUDP::UDPMessage* pack ) noexcept;
bool a_cache_init_ok = { false }; CacheVec* getACache( UniSetUDP::UDPMessage* pack ) noexcept;
CacheInfo& getDCache( UniSetUDP::UDPMessage* pack, bool force = false ) noexcept;
CacheInfo& getACache( UniSetUDP::UDPMessage* pack, bool force = false ) noexcept;
}; };
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
} // end of namespace uniset } // end of namespace uniset
......
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