Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
30801079
Commit
30801079
authored
Sep 08, 2016
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
decoder/Control: convert error from Error to std::exception_ptr
Prepare full C++ exception support in the decoder thread.
parent
0ce72cbf
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
24 deletions
+35
-24
DecoderControl.cxx
src/decoder/DecoderControl.cxx
+1
-0
DecoderControl.hxx
src/decoder/DecoderControl.hxx
+13
-15
DecoderThread.cxx
src/decoder/DecoderThread.cxx
+16
-6
Thread.cxx
src/player/Thread.cxx
+5
-3
No files found.
src/decoder/DecoderControl.cxx
View file @
30801079
...
@@ -22,6 +22,7 @@
...
@@ -22,6 +22,7 @@
#include "DecoderError.hxx"
#include "DecoderError.hxx"
#include "MusicPipe.hxx"
#include "MusicPipe.hxx"
#include "DetachedSong.hxx"
#include "DetachedSong.hxx"
#include "util/Error.hxx"
#include <assert.h>
#include <assert.h>
...
...
src/decoder/DecoderControl.hxx
View file @
30801079
...
@@ -27,7 +27,8 @@
...
@@ -27,7 +27,8 @@
#include "thread/Cond.hxx"
#include "thread/Cond.hxx"
#include "thread/Thread.hxx"
#include "thread/Thread.hxx"
#include "Chrono.hxx"
#include "Chrono.hxx"
#include "util/Error.hxx"
#include <exception>
#include <utility>
#include <utility>
...
@@ -39,6 +40,7 @@
...
@@ -39,6 +40,7 @@
#undef ERROR
#undef ERROR
#endif
#endif
class
Error
;
class
DetachedSong
;
class
DetachedSong
;
class
MusicBuffer
;
class
MusicBuffer
;
class
MusicPipe
;
class
MusicPipe
;
...
@@ -97,7 +99,7 @@ struct DecoderControl {
...
@@ -97,7 +99,7 @@ struct DecoderControl {
* The object must be freed when this object transitions to
* The object must be freed when this object transitions to
* any other state (usually #DecoderState::START).
* any other state (usually #DecoderState::START).
*/
*/
Erro
r
error
;
std
::
exception_pt
r
error
;
bool
quit
;
bool
quit
;
...
@@ -242,29 +244,25 @@ struct DecoderControl {
...
@@ -242,29 +244,25 @@ struct DecoderControl {
}
}
/**
/**
* Checks whether an error has occurred, and if so, ret
urns a
* Checks whether an error has occurred, and if so, ret
hrows
*
copy of the #Error objec
t.
*
i
t.
*
*
* Caller must lock the object.
* Caller must lock the object.
*/
*/
gcc_pure
void
CheckRethrowError
()
const
{
Error
GetError
()
const
{
assert
(
command
==
DecoderCommand
::
NONE
);
assert
(
command
==
DecoderCommand
::
NONE
);
assert
(
state
!=
DecoderState
::
ERROR
||
error
.
IsDefined
()
);
assert
(
state
!=
DecoderState
::
ERROR
||
error
);
Error
result
;
if
(
state
==
DecoderState
::
ERROR
)
if
(
state
==
DecoderState
::
ERROR
)
result
.
Set
(
error
);
std
::
rethrow_exception
(
error
);
return
result
;
}
}
/**
/**
* Like
Get
Error(), but locks and unlocks the object.
* Like
CheckRethrow
Error(), but locks and unlocks the object.
*/
*/
gcc_pure
void
LockCheckRethrowError
()
const
{
Error
LockGetError
()
const
{
const
ScopeLock
protect
(
mutex
);
const
ScopeLock
protect
(
mutex
);
return
Get
Error
();
CheckRethrow
Error
();
}
}
/**
/**
...
@@ -274,7 +272,7 @@ struct DecoderControl {
...
@@ -274,7 +272,7 @@ struct DecoderControl {
*/
*/
void
ClearError
()
{
void
ClearError
()
{
if
(
state
==
DecoderState
::
ERROR
)
{
if
(
state
==
DecoderState
::
ERROR
)
{
error
.
Clea
r
();
error
=
std
::
exception_pt
r
();
state
=
DecoderState
::
STOP
;
state
=
DecoderState
::
STOP
;
}
}
}
}
...
...
src/decoder/DecoderThread.cxx
View file @
30801079
...
@@ -34,6 +34,7 @@
...
@@ -34,6 +34,7 @@
#include "util/MimeType.hxx"
#include "util/MimeType.hxx"
#include "util/UriUtil.hxx"
#include "util/UriUtil.hxx"
#include "util/Error.hxx"
#include "util/Error.hxx"
#include "util/RuntimeError.hxx"
#include "util/Domain.hxx"
#include "util/Domain.hxx"
#include "thread/Name.hxx"
#include "thread/Name.hxx"
#include "tag/ApeReplayGain.hxx"
#include "tag/ApeReplayGain.hxx"
...
@@ -415,7 +416,7 @@ decoder_run_song(DecoderControl &dc,
...
@@ -415,7 +416,7 @@ decoder_run_song(DecoderControl &dc,
/* copy the Error from struct Decoder to
/* copy the Error from struct Decoder to
DecoderControl */
DecoderControl */
dc
.
state
=
DecoderState
::
ERROR
;
dc
.
state
=
DecoderState
::
ERROR
;
dc
.
error
=
std
::
m
ove
(
decoder
.
error
);
dc
.
error
=
std
::
m
ake_exception_ptr
(
std
::
move
(
decoder
.
error
)
);
}
else
if
(
success
)
}
else
if
(
success
)
dc
.
state
=
DecoderState
::
STOP
;
dc
.
state
=
DecoderState
::
STOP
;
else
{
else
{
...
@@ -426,8 +427,7 @@ decoder_run_song(DecoderControl &dc,
...
@@ -426,8 +427,7 @@ decoder_run_song(DecoderControl &dc,
if
(
!
allocated
.
empty
())
if
(
!
allocated
.
empty
())
error_uri
=
allocated
.
c_str
();
error_uri
=
allocated
.
c_str
();
dc
.
error
.
Format
(
decoder_domain
,
dc
.
error
=
std
::
make_exception_ptr
(
FormatRuntimeError
(
"Failed to decode %s"
,
error_uri
));
"Failed to decode %s"
,
error_uri
);
}
}
dc
.
client_cond
.
signal
();
dc
.
client_cond
.
signal
();
...
@@ -450,9 +450,11 @@ decoder_run(DecoderControl &dc)
...
@@ -450,9 +450,11 @@ decoder_run(DecoderControl &dc)
Path
path_fs
=
Path
::
Null
();
Path
path_fs
=
Path
::
Null
();
AllocatedPath
path_buffer
=
AllocatedPath
::
Null
();
AllocatedPath
path_buffer
=
AllocatedPath
::
Null
();
if
(
PathTraitsUTF8
::
IsAbsolute
(
uri_utf8
))
{
if
(
PathTraitsUTF8
::
IsAbsolute
(
uri_utf8
))
{
path_buffer
=
AllocatedPath
::
FromUTF8
(
uri_utf8
,
dc
.
error
);
Error
error
;
path_buffer
=
AllocatedPath
::
FromUTF8
(
uri_utf8
,
error
);
if
(
path_buffer
.
IsNull
())
{
if
(
path_buffer
.
IsNull
())
{
dc
.
state
=
DecoderState
::
ERROR
;
dc
.
state
=
DecoderState
::
ERROR
;
dc
.
error
=
std
::
make_exception_ptr
(
std
::
move
(
error
));
dc
.
CommandFinishedLocked
();
dc
.
CommandFinishedLocked
();
return
;
return
;
}
}
...
@@ -485,8 +487,16 @@ decoder_task(void *arg)
...
@@ -485,8 +487,16 @@ decoder_task(void *arg)
decoder_run
(
dc
);
decoder_run
(
dc
);
if
(
dc
.
state
==
DecoderState
::
ERROR
)
if
(
dc
.
state
==
DecoderState
::
ERROR
)
{
LogError
(
dc
.
error
);
try
{
std
::
rethrow_exception
(
dc
.
error
);
}
catch
(
const
std
::
exception
&
e
)
{
LogError
(
e
);
}
catch
(
const
Error
&
error
)
{
LogError
(
error
);
}
catch
(...)
{
}
}
break
;
break
;
...
...
src/player/Thread.cxx
View file @
30801079
...
@@ -33,6 +33,7 @@
...
@@ -33,6 +33,7 @@
#include "tag/Tag.hxx"
#include "tag/Tag.hxx"
#include "Idle.hxx"
#include "Idle.hxx"
#include "util/Domain.hxx"
#include "util/Domain.hxx"
#include "util/Error.hxx"
#include "thread/Name.hxx"
#include "thread/Name.hxx"
#include "Log.hxx"
#include "Log.hxx"
...
@@ -372,9 +373,10 @@ Player::StopDecoder()
...
@@ -372,9 +373,10 @@ Player::StopDecoder()
bool
bool
Player
::
ForwardDecoderError
()
Player
::
ForwardDecoderError
()
{
{
Error
error
=
dc
.
GetError
();
try
{
if
(
error
.
IsDefined
())
{
dc
.
CheckRethrowError
();
pc
.
SetError
(
PlayerError
::
DECODER
,
std
::
move
(
error
));
}
catch
(...)
{
pc
.
SetError
(
PlayerError
::
DECODER
,
std
::
current_exception
());
return
false
;
return
false
;
}
}
...
...
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