Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uniset2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UniSet project repositories
uniset2
Commits
0a6482cc
Commit
0a6482cc
authored
Nov 29, 2020
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(unet): minor optimizations
parent
0f03d9b7
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
38 deletions
+39
-38
UNetReceiver.cc
extensions/UNetUDP/UNetReceiver.cc
+37
-36
UNetReceiver.h
extensions/UNetUDP/UNetReceiver.h
+2
-2
No files found.
extensions/UNetUDP/UNetReceiver.cc
View file @
0a6482cc
...
@@ -28,6 +28,7 @@ using namespace uniset;
...
@@ -28,6 +28,7 @@ using namespace uniset;
using
namespace
uniset
::
extensions
;
using
namespace
uniset
::
extensions
;
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
CommonEventLoop
UNetReceiver
::
loop
;
CommonEventLoop
UNetReceiver
::
loop
;
static
UniSetUDP
::
UDPAData
emptyAData
;
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
/*
/*
bool UNetReceiver::PacketCompare::operator()(const UniSetUDP::UDPMessage& lhs,
bool UNetReceiver::PacketCompare::operator()(const UniSetUDP::UDPMessage& lhs,
...
@@ -371,6 +372,10 @@ void UNetReceiver::initEvent( ev::timer& tmr, int revents ) noexcept
...
@@ -371,6 +372,10 @@ void UNetReceiver::initEvent( ev::timer& tmr, int revents ) noexcept
void
UNetReceiver
::
update
()
noexcept
void
UNetReceiver
::
update
()
noexcept
{
{
UniSetUDP
::
UDPMessage
p
;
UniSetUDP
::
UDPMessage
p
;
CacheItem
*
c_it
=
nullptr
;
UniSetUDP
::
UDPAData
*
dat
=
nullptr
;
long
s_id
;
// обрабатываем, пока очередь либо не опустеет,
// обрабатываем, пока очередь либо не опустеет,
// либо обнаружится "дырка" в последовательности,
// либо обнаружится "дырка" в последовательности,
// но при этом обрабатываем не больше maxProcessingCount
// но при этом обрабатываем не больше maxProcessingCount
...
@@ -447,37 +452,29 @@ void UNetReceiver::update() noexcept
...
@@ -447,37 +452,29 @@ void UNetReceiver::update() noexcept
}
// unlock qpack
}
// unlock qpack
k
--
;
k
--
;
upCount
++
;
upCount
++
;
// cerr << myname << "(update): " << p.msg.header << endl;
initDCache
(
p
,
!
d_cache_init_ok
);
initACache
(
p
,
!
a_cache_init_ok
);
// Обработка дискретных
// Обработка дискретных
CacheInfo
&
d_iv
=
d_icache_map
[
p
.
getDataID
()];
auto
d_iv
=
getDCache
(
p
,
!
d_cache_init_ok
);
for
(
size_t
i
=
0
;
i
<
p
.
dcount
;
i
++
)
for
(
size_t
i
=
0
;
i
<
p
.
dcount
;
i
++
)
{
{
try
try
{
{
long
id
=
p
.
dID
(
i
);
s_
id
=
p
.
dID
(
i
);
bool
val
=
p
.
dValue
(
i
)
;
c_it
=
&
d_iv
.
cache
[
i
]
;
CacheItem
&
ii
(
d_iv
.
cache
[
i
]);
if
(
c_it
->
id
!=
s_id
)
if
(
ii
.
id
!=
id
)
{
{
unetwarn
<<
myname
<<
"(update): reinit
cache for sid="
<<
id
<<
endl
;
unetwarn
<<
myname
<<
"(update): reinit
dcache for sid="
<<
s_
id
<<
endl
;
ii
.
id
=
id
;
c_it
->
id
=
s_
id
;
shm
->
initIterator
(
ii
.
ioit
);
shm
->
initIterator
(
c_it
->
ioit
);
}
}
// обновление данных в SM (блокировано)
// обновление данных в SM (блокировано)
if
(
lockUpdate
)
if
(
lockUpdate
)
continue
;
continue
;
shm
->
localSetValue
(
ii
.
ioit
,
id
,
val
,
shm
->
ID
());
shm
->
localSetValue
(
c_it
->
ioit
,
s_id
,
p
.
dValue
(
i
)
,
shm
->
ID
());
}
}
catch
(
const
uniset
::
Exception
&
ex
)
catch
(
const
uniset
::
Exception
&
ex
)
{
{
...
@@ -490,28 +487,26 @@ void UNetReceiver::update() noexcept
...
@@ -490,28 +487,26 @@ void UNetReceiver::update() noexcept
}
}
// Обработка аналоговых
// Обработка аналоговых
CacheInfo
&
a_iv
=
a_icache_map
[
p
.
getDataID
()];
auto
a_iv
=
getACache
(
p
,
!
a_cache_init_ok
);
for
(
size_t
i
=
0
;
i
<
p
.
acount
;
i
++
)
for
(
size_t
i
=
0
;
i
<
p
.
acount
;
i
++
)
{
{
try
try
{
{
UniSetUDP
::
UDPAData
&
d
=
p
.
a_dat
[
i
];
dat
=
&
p
.
a_dat
[
i
];
c_it
=
&
a_iv
.
cache
[
i
];
CacheItem
&
ii
(
a_iv
.
cache
[
i
]);
if
(
ii
.
id
!=
d
.
id
)
if
(
c_it
->
id
!=
dat
->
id
)
{
{
unetwarn
<<
myname
<<
"(update): reinit
cache for sid="
<<
d
.
id
<<
endl
;
unetwarn
<<
myname
<<
"(update): reinit
acache for sid="
<<
dat
->
id
<<
endl
;
ii
.
id
=
d
.
id
;
c_it
->
id
=
dat
->
id
;
shm
->
initIterator
(
ii
.
ioit
);
shm
->
initIterator
(
c_it
->
ioit
);
}
}
// обновление данных в SM (блокировано)
// обновление данных в SM (блокировано)
if
(
lockUpdate
)
if
(
lockUpdate
)
continue
;
continue
;
shm
->
localSetValue
(
ii
.
ioit
,
d
.
id
,
d
.
val
,
shm
->
ID
());
shm
->
localSetValue
(
c_it
->
ioit
,
dat
->
id
,
dat
->
val
,
shm
->
ID
());
}
}
catch
(
const
uniset
::
Exception
&
ex
)
catch
(
const
uniset
::
Exception
&
ex
)
{
{
...
@@ -850,12 +845,13 @@ void UNetReceiver::initIterators() noexcept
...
@@ -850,12 +845,13 @@ void UNetReceiver::initIterators() noexcept
}
}
}
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
void
UNetReceiver
::
ini
tDCache
(
UniSetUDP
::
UDPMessage
&
pack
,
bool
force
)
noexcept
UNetReceiver
::
CacheInfo
&
UNetReceiver
::
ge
tDCache
(
UniSetUDP
::
UDPMessage
&
pack
,
bool
force
)
noexcept
{
{
CacheInfo
&
d_info
(
d_icache_map
[
pack
.
getDataID
()]);
// если элемента нет, он будет создан
CacheInfo
&
d_info
=
d_icache_map
[
pack
.
getDataID
()];
if
(
!
force
&&
pack
.
dcount
==
d_info
.
cache
.
size
()
)
if
(
!
force
&&
pack
.
dcount
==
d_info
.
cache
.
size
()
)
return
;
return
d_info
;
if
(
d_info
.
cache_init_ok
&&
pack
.
dcount
==
d_info
.
cache
.
size
()
)
if
(
d_info
.
cache_init_ok
&&
pack
.
dcount
==
d_info
.
cache
.
size
()
)
{
{
...
@@ -864,14 +860,14 @@ void UNetReceiver::initDCache( UniSetUDP::UDPMessage& pack, bool force ) noexcep
...
@@ -864,14 +860,14 @@ void UNetReceiver::initDCache( UniSetUDP::UDPMessage& pack, bool force ) noexcep
for
(
;
it
!=
d_icache_map
.
end
();
++
it
)
for
(
;
it
!=
d_icache_map
.
end
();
++
it
)
{
{
CacheInfo
&
d_info
(
it
->
second
)
;
d_info
=
it
->
second
;
d_cache_init_ok
=
d_cache_init_ok
&&
d_info
.
cache_init_ok
;
d_cache_init_ok
=
d_cache_init_ok
&&
d_info
.
cache_init_ok
;
if
(
d_cache_init_ok
==
false
)
if
(
d_cache_init_ok
==
false
)
break
;
break
;
}
}
return
;
return
d_info
;
}
}
unetinfo
<<
myname
<<
": init dcache for "
<<
pack
.
getDataID
()
<<
endl
;
unetinfo
<<
myname
<<
": init dcache for "
<<
pack
.
getDataID
()
<<
endl
;
...
@@ -892,14 +888,17 @@ void UNetReceiver::initDCache( UniSetUDP::UDPMessage& pack, bool force ) noexcep
...
@@ -892,14 +888,17 @@ void UNetReceiver::initDCache( UniSetUDP::UDPMessage& pack, bool force ) noexcep
shm
->
initIterator
(
d
.
ioit
);
shm
->
initIterator
(
d
.
ioit
);
}
}
}
}
return
d_info
;
}
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
void
UNetReceiver
::
ini
tACache
(
UniSetUDP
::
UDPMessage
&
pack
,
bool
force
)
noexcept
UNetReceiver
::
CacheInfo
&
UNetReceiver
::
ge
tACache
(
UniSetUDP
::
UDPMessage
&
pack
,
bool
force
)
noexcept
{
{
CacheInfo
&
a_info
(
a_icache_map
[
pack
.
getDataID
()]);
// если элемента нет, он будет создан
CacheInfo
&
a_info
=
a_icache_map
[
pack
.
getDataID
()];
if
(
!
force
&&
pack
.
acount
==
a_info
.
cache
.
size
()
)
if
(
!
force
&&
pack
.
acount
==
a_info
.
cache
.
size
()
)
return
;
return
a_info
;
if
(
a_info
.
cache_init_ok
&&
pack
.
acount
==
a_info
.
cache
.
size
()
)
if
(
a_info
.
cache_init_ok
&&
pack
.
acount
==
a_info
.
cache
.
size
()
)
{
{
...
@@ -908,14 +907,14 @@ void UNetReceiver::initACache( UniSetUDP::UDPMessage& pack, bool force ) noexcep
...
@@ -908,14 +907,14 @@ void UNetReceiver::initACache( UniSetUDP::UDPMessage& pack, bool force ) noexcep
for
(
;
it
!=
a_icache_map
.
end
();
++
it
)
for
(
;
it
!=
a_icache_map
.
end
();
++
it
)
{
{
CacheInfo
&
a_info
(
it
->
second
)
;
a_info
=
it
->
second
;
a_cache_init_ok
=
a_cache_init_ok
&&
a_info
.
cache_init_ok
;
a_cache_init_ok
=
a_cache_init_ok
&&
a_info
.
cache_init_ok
;
if
(
a_cache_init_ok
==
false
)
if
(
a_cache_init_ok
==
false
)
break
;
break
;
}
}
return
;
return
a_info
;
}
}
unetinfo
<<
myname
<<
": init icache for "
<<
pack
.
getDataID
()
<<
endl
;
unetinfo
<<
myname
<<
": init icache for "
<<
pack
.
getDataID
()
<<
endl
;
...
@@ -936,6 +935,8 @@ void UNetReceiver::initACache( UniSetUDP::UDPMessage& pack, bool force ) noexcep
...
@@ -936,6 +935,8 @@ void UNetReceiver::initACache( UniSetUDP::UDPMessage& pack, bool force ) noexcep
shm
->
initIterator
(
d
.
ioit
);
shm
->
initIterator
(
d
.
ioit
);
}
}
}
}
return
a_info
;
}
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
void
UNetReceiver
::
connectEvent
(
UNetReceiver
::
EventSlot
sl
)
noexcept
void
UNetReceiver
::
connectEvent
(
UNetReceiver
::
EventSlot
sl
)
noexcept
...
...
extensions/UNetUDP/UNetReceiver.h
View file @
0a6482cc
...
@@ -344,8 +344,8 @@ namespace uniset
...
@@ -344,8 +344,8 @@ namespace uniset
bool
d_cache_init_ok
=
{
false
};
bool
d_cache_init_ok
=
{
false
};
bool
a_cache_init_ok
=
{
false
};
bool
a_cache_init_ok
=
{
false
};
void
ini
tDCache
(
UniSetUDP
::
UDPMessage
&
pack
,
bool
force
=
false
)
noexcept
;
CacheInfo
&
ge
tDCache
(
UniSetUDP
::
UDPMessage
&
pack
,
bool
force
=
false
)
noexcept
;
void
ini
tACache
(
UniSetUDP
::
UDPMessage
&
pack
,
bool
force
=
false
)
noexcept
;
CacheInfo
&
ge
tACache
(
UniSetUDP
::
UDPMessage
&
pack
,
bool
force
=
false
)
noexcept
;
};
};
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
}
// end of namespace uniset
}
// end of namespace uniset
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment