Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
17592949
"vscode:/vscode.git/clone" did not exist on "310478521be031afd7d972d29895c75ad0e82a15"
Commit
17592949
authored
Feb 01, 2013
by
Davis King
Browse files
Added a pipe test that catches the bug I just fixed.
parent
04360d7a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
82 additions
and
0 deletions
+82
-0
dlib/test/pipe.cpp
dlib/test/pipe.cpp
+82
-0
No files found.
dlib/test/pipe.cpp
View file @
17592949
...
...
@@ -160,7 +160,87 @@ namespace
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
typename
in_type
,
typename
out_type
>
class
PipelineProcessor
:
private
dlib
::
threaded_object
{
public:
PipelineProcessor
(
dlib
::
pipe
<
in_type
>
&
in
,
dlib
::
pipe
<
out_type
>
&
out
)
:
InPipe
(
in
),
OutPipe
(
out
),
InMsg
(),
OutMsg
()
{
start
();
}
~
PipelineProcessor
()
{
// signal the thread to stop
stop
();
wait
();
}
private:
dlib
::
pipe
<
in_type
>
&
InPipe
;
dlib
::
pipe
<
out_type
>
&
OutPipe
;
in_type
InMsg
;
out_type
OutMsg
;
void
thread
()
{
while
(
!
should_stop
())
{
if
(
InPipe
.
dequeue_or_timeout
(
InMsg
,
100
))
{
// if function signals ready to send OutMsg
while
(
!
OutPipe
.
enqueue_or_timeout
(
OutMsg
,
100
))
{
// try to send until should stop
if
(
should_stop
())
{
return
;
}
}
}
}
};
};
void
do_zero_size_test_with_timeouts
()
{
dlog
<<
LINFO
<<
"in do_zero_size_test_with_timeouts()"
;
// make sure we can get though this without deadlocking
for
(
int
k
=
0
;
k
<
10
;
++
k
)
{
dlib
::
pipe
<
int
>
in_pipe
(
10
);
dlib
::
pipe
<
float
>
out_pipe
(
0
);
{
PipelineProcessor
<
int
,
float
>
pp
(
in_pipe
,
out_pipe
);
int
in
=
1
;
in_pipe
.
enqueue
(
in
);
in
=
2
;
in_pipe
.
enqueue
(
in
);
in
=
3
;
in_pipe
.
enqueue
(
in
);
// sleep to make sure thread enqueued
dlib
::
sleep
(
100
);
float
out
=
1.0
f
;
out_pipe
.
dequeue
(
out
);
dlib
::
sleep
(
100
);
}
print_spinner
();
}
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
typename
pipe
...
...
@@ -598,6 +678,8 @@ namespace
)
{
pipe_kernel_test
<
dlib
::
pipe
<
int
>
>
();
do_zero_size_test_with_timeouts
();
}
}
a
;
...
...
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