Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
ftl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nicolas Pope
ftl
Commits
f208a1a8
Commit
f208a1a8
authored
5 years ago
by
Nicolas Pope
Browse files
Options
Downloads
Patches
Plain Diff
Switch to atomics
parent
4df44401
No related branches found
No related tags found
1 merge request
!37
Resolves #83 net performance, partially
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
components/rgbd-sources/include/ftl/rgbd/streamer.hpp
+3
-2
3 additions, 2 deletions
components/rgbd-sources/include/ftl/rgbd/streamer.hpp
components/rgbd-sources/src/streamer.cpp
+52
-37
52 additions, 37 deletions
components/rgbd-sources/src/streamer.cpp
with
55 additions
and
39 deletions
components/rgbd-sources/include/ftl/rgbd/streamer.hpp
+
3
−
2
View file @
f208a1a8
...
...
@@ -11,6 +11,7 @@
#include
<vector>
#include
<map>
#include
<shared_mutex>
#include
<atomic>
namespace
ftl
{
namespace
rgbd
{
...
...
@@ -29,7 +30,7 @@ static const unsigned int kTransmitted = 0x2;
struct
StreamSource
{
ftl
::
rgbd
::
Source
*
src
;
unsigned
int
state
;
// Busy or ready to swap?
std
::
atomic
<
unsigned
int
>
state
;
// Busy or ready to swap?
cv
::
Mat
rgb
;
// Tx buffer
cv
::
Mat
depth
;
// Tx buffer
std
::
vector
<
detail
::
StreamClient
>
clients
[
10
];
// One list per bitrate
...
...
@@ -104,7 +105,7 @@ class Streamer : public ftl::Configurable {
bool
late_
;
std
::
mutex
job_mtx_
;
std
::
condition_variable
job_cv_
;
int
jobs_
;
std
::
atomic
<
int
>
jobs_
;
void
_schedule
();
void
_swap
(
detail
::
StreamSource
&
);
...
...
This diff is collapsed.
Click to expand it.
components/rgbd-sources/src/streamer.cpp
+
52
−
37
View file @
f208a1a8
...
...
@@ -106,6 +106,9 @@ void Streamer::add(Source *src) {
}
void
Streamer
::
_addClient
(
const
string
&
source
,
int
N
,
int
rate
,
const
ftl
::
UUID
&
peer
,
const
string
&
dest
)
{
StreamSource
*
s
=
nullptr
;
{
UNIQUE_LOCK
(
mutex_
,
slk
);
if
(
sources_
.
find
(
source
)
==
sources_
.
end
())
return
;
...
...
@@ -114,7 +117,12 @@ void Streamer::_addClient(const string &source, int N, int rate, const ftl::UUID
DLOG
(
INFO
)
<<
"Adding Stream Peer: "
<<
peer
.
to_string
();
StreamSource
*
s
=
sources_
[
source
];
s
=
sources_
[
source
];
}
if
(
!
s
)
return
;
UNIQUE_LOCK
(
s
->
mutex
,
lk2
);
for
(
int
i
=
0
;
i
<
s
->
clients
[
rate
].
size
();
i
++
)
{
if
(
s
->
clients
[
rate
][
i
].
peerid
==
peer
)
{
StreamClient
&
c
=
s
->
clients
[
rate
][
i
];
...
...
@@ -221,26 +229,29 @@ void Streamer::_schedule() {
}
// There will be two jobs for this source...
UNIQUE_LOCK
(
job_mtx_
,
lk
);
//
UNIQUE_LOCK(job_mtx_,lk);
jobs_
+=
2
;
lk
.
unlock
();
//
lk.unlock();
// Grab job
pool_
.
push
([
this
,
uri
](
int
id
)
{
StreamSource
*
src
=
sources_
[
uri
];
if
(
src
==
nullptr
||
src
->
state
!=
0
)
continue
;
// Grab job
pool_
.
push
([
this
,
src
](
int
id
)
{
//StreamSource *src = sources_[uri];
src
->
src
->
grab
();
// CHECK (Nick) Can state be an atomic instead?
UNIQUE_LOCK
(
src
->
mutex
,
lk
);
//
UNIQUE_LOCK(src->mutex, lk);
src
->
state
|=
ftl
::
rgbd
::
detail
::
kGrabbed
;
_swap
(
*
src
);
lk
.
unlock
();
//
lk.unlock();
// Mark job as finished
UNIQUE_LOCK
(
job_mtx_
,
ulk
);
jobs_
--
;
ulk
.
unlock
();
//UNIQUE_LOCK(job_mtx_, ulk);
//jobs_--;
//ulk.unlock();
--
jobs_
;
job_cv_
.
notify_one
();
});
...
...
@@ -249,8 +260,8 @@ void Streamer::_schedule() {
// meaning that no lock is required here since outer shared_lock
// prevents addition of new clients.
// TODO, could do one for each bitrate...
pool_
.
push
([
this
,
uri
](
int
id
)
{
StreamSource
*
src
=
sources_
[
uri
];
pool_
.
push
([
this
,
src
](
int
id
)
{
//
StreamSource *src = sources_[uri];
try
{
if
(
src
&&
src
->
rgb
.
rows
>
0
&&
src
->
depth
.
rows
>
0
&&
src
->
clients
[
0
].
size
()
>
0
)
{
...
...
@@ -270,6 +281,8 @@ void Streamer::_schedule() {
//LOG(INFO) << "Data size: " << ((rgb_buf.size() + d_buf.size()) / 1024) << "kb";
{
UNIQUE_LOCK
(
src
->
mutex
,
lk
);
auto
i
=
src
->
clients
[
0
].
begin
();
while
(
i
!=
src
->
clients
[
0
].
end
())
{
try
{
...
...
@@ -289,6 +302,7 @@ void Streamer::_schedule() {
}
}
}
}
}
catch
(...)
{
LOG
(
ERROR
)
<<
"Error in transmission loop"
;
}
...
...
@@ -298,16 +312,17 @@ void Streamer::_schedule() {
LOG(INFO) << "Stream Elapsed: " << elapsed.count();*/
// CHECK (Nick) Could state be an atomic?
UNIQUE_LOCK
(
src
->
mutex
,
lk
);
//
UNIQUE_LOCK(src->mutex,lk);
//LOG(INFO) << "Tx Frame: " << uri;
src
->
state
|=
ftl
::
rgbd
::
detail
::
kTransmitted
;
_swap
(
*
src
);
lk
.
unlock
();
//
lk.unlock();
// Mark job as finished
UNIQUE_LOCK
(
job_mtx_
,
ulk
);
jobs_
--
;
ulk
.
unlock
();
//UNIQUE_LOCK(job_mtx_,ulk);
//jobs_--;
//ulk.unlock();
--
jobs_
;
job_cv_
.
notify_one
();
});
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment