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
681e012f
Commit
681e012f
authored
Feb 27, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
db/update: cancel the update on shutdown
parent
3be36643
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
59 additions
and
1 deletion
+59
-1
NEWS
NEWS
+1
-0
Main.cxx
src/Main.cxx
+3
-0
Queue.hxx
src/db/update/Queue.hxx
+4
-0
Service.cxx
src/db/update/Service.cxx
+19
-0
Service.hxx
src/db/update/Service.hxx
+8
-0
Walk.cxx
src/db/update/Walk.cxx
+1
-1
Walk.hxx
src/db/update/Walk.hxx
+23
-0
No files found.
NEWS
View file @
681e012f
...
...
@@ -9,6 +9,7 @@ ver 0.19 (not yet released)
- proxy: forward "idle" events
- proxy: copy "Last-Modified" from remote directories
- upnp: new plugin
- cancel the update on shutdown
* storage
- music_directory can point to a remote file server
- nfs: new plugin
...
...
src/Main.cxx
View file @
681e012f
...
...
@@ -596,6 +596,9 @@ int mpd_main(int argc, char *argv[])
#if defined(ENABLE_DATABASE) && defined(ENABLE_INOTIFY)
mpd_inotify_finish
();
if
(
instance
->
update
!=
nullptr
)
instance
->
update
->
CancelAllAsync
();
#endif
if
(
state_file
!=
nullptr
)
{
...
...
src/db/update/Queue.hxx
View file @
681e012f
...
...
@@ -50,6 +50,10 @@ public:
bool
Push
(
const
char
*
path
,
bool
discard
,
unsigned
id
);
UpdateQueueItem
Pop
();
void
Clear
()
{
update_queue
=
decltype
(
update_queue
)();
}
};
#endif
src/db/update/Service.cxx
View file @
681e012f
...
...
@@ -47,6 +47,23 @@ UpdateService::UpdateService(EventLoop &_loop, SimpleDatabase &_db,
{
}
UpdateService
::~
UpdateService
()
{
CancelAllAsync
();
if
(
update_thread
.
IsDefined
())
update_thread
.
Join
();
}
void
UpdateService
::
CancelAllAsync
()
{
assert
(
GetEventLoop
().
IsInsideOrNull
());
queue
.
Clear
();
walk
.
Cancel
();
}
inline
void
UpdateService
::
Task
()
{
...
...
@@ -94,6 +111,8 @@ UpdateService::StartThread(UpdateQueueItem &&i)
next
=
std
::
move
(
i
);
walk
.
Prepare
();
Error
error
;
if
(
!
update_thread
.
Start
(
Task
,
this
,
error
))
FatalError
(
error
);
...
...
src/db/update/Service.hxx
View file @
681e012f
...
...
@@ -64,6 +64,8 @@ public:
Storage
&
_storage
,
DatabaseListener
&
_listener
);
~
UpdateService
();
/**
* Returns a non-zero job id when we are currently updating
* the database.
...
...
@@ -82,6 +84,12 @@ public:
gcc_nonnull_all
unsigned
Enqueue
(
const
char
*
path
,
bool
discard
);
/**
* Clear the queue and cancel the current update. Does not
* wait for the thread to exit.
*/
void
CancelAllAsync
();
private
:
/* virtual methods from class DeferredMonitor */
virtual
void
RunDeferred
()
override
;
...
...
src/db/update/Walk.cxx
View file @
681e012f
...
...
@@ -358,7 +358,7 @@ UpdateWalk::UpdateDirectory(Directory &directory, const FileInfo &info)
PurgeDeletedFromDirectory
(
directory
);
const
char
*
name_utf8
;
while
((
name_utf8
=
reader
->
Read
())
!=
nullptr
)
{
while
(
!
cancel
&&
(
name_utf8
=
reader
->
Read
())
!=
nullptr
)
{
if
(
skip_path
(
name_utf8
))
continue
;
...
...
src/db/update/Walk.hxx
View file @
681e012f
...
...
@@ -48,6 +48,13 @@ class UpdateWalk final {
bool
walk_discard
;
bool
modified
;
/**
* Set to true by the main thread when the update thread shall
* cancel as quickly as possible. Access to this flag is
* unprotected.
*/
volatile
bool
cancel
;
Storage
&
storage
;
DatabaseEditor
editor
;
...
...
@@ -57,6 +64,22 @@ public:
Storage
&
_storage
);
/**
* Cancel the current update and quit the Walk() method as
* soon as possible.
*/
void
Cancel
()
{
cancel
=
true
;
}
/**
* Call from the main thread before starting the update
* thread.
*/
void
Prepare
()
{
cancel
=
false
;
}
/**
* Returns true if the database was modified.
*/
bool
Walk
(
Directory
&
root
,
const
char
*
path
,
bool
discard
);
...
...
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