db/simple: use class ScopeDatabaseLock
This commit is contained in:
@@ -39,6 +39,27 @@
|
||||
#include <sys/stat.h>
|
||||
#include <string.h>
|
||||
|
||||
static Directory *
|
||||
LockFindChild(Directory &directory, const char *name)
|
||||
{
|
||||
const ScopeDatabaseLock protect;
|
||||
return directory.FindChild(name);
|
||||
}
|
||||
|
||||
static Directory *
|
||||
LockMakeChild(Directory &directory, const char *name)
|
||||
{
|
||||
const ScopeDatabaseLock protect;
|
||||
return directory.MakeChild(name);
|
||||
}
|
||||
|
||||
static Song *
|
||||
LockFindSong(Directory &directory, const char *name)
|
||||
{
|
||||
const ScopeDatabaseLock protect;
|
||||
return directory.FindSong(name);
|
||||
}
|
||||
|
||||
void
|
||||
UpdateWalk::UpdateArchiveTree(Directory &directory, const char *name)
|
||||
{
|
||||
@@ -46,11 +67,9 @@ UpdateWalk::UpdateArchiveTree(Directory &directory, const char *name)
|
||||
if (tmp) {
|
||||
const std::string child_name(name, tmp);
|
||||
//add dir is not there already
|
||||
db_lock();
|
||||
Directory *subdir =
|
||||
directory.MakeChild(child_name.c_str());
|
||||
Directory *subdir = LockMakeChild(directory,
|
||||
child_name.c_str());
|
||||
subdir->device = DEVICE_INARCHIVE;
|
||||
db_unlock();
|
||||
|
||||
//create directories first
|
||||
UpdateArchiveTree(*subdir, tmp + 1);
|
||||
@@ -62,15 +81,14 @@ UpdateWalk::UpdateArchiveTree(Directory &directory, const char *name)
|
||||
}
|
||||
|
||||
//add file
|
||||
db_lock();
|
||||
Song *song = directory.FindSong(name);
|
||||
db_unlock();
|
||||
Song *song = LockFindSong(directory, name);
|
||||
if (song == nullptr) {
|
||||
song = Song::LoadFile(storage, name, directory);
|
||||
if (song != nullptr) {
|
||||
db_lock();
|
||||
directory.AddSong(song);
|
||||
db_unlock();
|
||||
{
|
||||
const ScopeDatabaseLock protect;
|
||||
directory.AddSong(song);
|
||||
}
|
||||
|
||||
modified = true;
|
||||
FormatDefault(update_domain, "added %s/%s",
|
||||
@@ -108,9 +126,7 @@ UpdateWalk::UpdateArchiveFile(Directory &parent, const char *name,
|
||||
const StorageFileInfo &info,
|
||||
const ArchivePlugin &plugin)
|
||||
{
|
||||
db_lock();
|
||||
Directory *directory = parent.FindChild(name);
|
||||
db_unlock();
|
||||
Directory *directory = LockFindChild(parent, name);
|
||||
|
||||
if (directory != nullptr && directory->mtime == info.mtime &&
|
||||
!walk_discard)
|
||||
@@ -139,12 +155,12 @@ UpdateWalk::UpdateArchiveFile(Directory &parent, const char *name,
|
||||
if (directory == nullptr) {
|
||||
FormatDebug(update_domain,
|
||||
"creating archive directory: %s", name);
|
||||
db_lock();
|
||||
|
||||
const ScopeDatabaseLock protect;
|
||||
directory = parent.CreateChild(name);
|
||||
/* mark this directory as archive (we use device for
|
||||
this) */
|
||||
directory->device = DEVICE_INARCHIVE;
|
||||
db_unlock();
|
||||
}
|
||||
|
||||
directory->mtime = info.mtime;
|
||||
|
Reference in New Issue
Block a user