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
a7414084
Commit
a7414084
authored
Jul 20, 2020
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
storage/smbclient: add Mutex attribute
This per-object Mutex replaces the global `smbclient_mutex`.
parent
f5a85a81
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
10 deletions
+16
-10
SmbclientStorage.cxx
src/storage/plugins/SmbclientStorage.cxx
+16
-10
No files found.
src/storage/plugins/SmbclientStorage.cxx
View file @
a7414084
...
...
@@ -23,7 +23,6 @@
#include "storage/FileInfo.hxx"
#include "lib/smbclient/Init.hxx"
#include "lib/smbclient/Context.hxx"
#include "lib/smbclient/Mutex.hxx"
#include "fs/Traits.hxx"
#include "thread/Mutex.hxx"
#include "system/Error.hxx"
...
...
@@ -60,6 +59,12 @@ class SmbclientStorage final : public Storage {
const
std
::
string
base
;
/**
* This mutex protects all calls into the #SmbclientContext,
* which is not thread-safe.
*/
Mutex
mutex
;
SmbclientContext
ctx
=
SmbclientContext
::
New
();
public
:
...
...
@@ -92,12 +97,12 @@ SmbclientStorage::MapToRelativeUTF8(std::string_view uri_utf8) const noexcept
}
static
StorageFileInfo
GetInfo
(
SmbclientContext
&
ctx
,
const
char
*
path
)
GetInfo
(
SmbclientContext
&
ctx
,
Mutex
&
mutex
,
const
char
*
path
)
{
struct
stat
st
;
{
const
std
::
lock_guard
<
Mutex
>
protect
(
smbclient_
mutex
);
const
std
::
lock_guard
<
Mutex
>
protect
(
mutex
);
if
(
ctx
.
Stat
(
path
,
st
)
!=
0
)
throw
MakeErrno
(
"Failed to access file"
);
}
...
...
@@ -121,7 +126,7 @@ StorageFileInfo
SmbclientStorage
::
GetInfo
(
std
::
string_view
uri_utf8
,
[[
maybe_unused
]]
bool
follow
)
{
const
std
::
string
mapped
=
MapUTF8
(
uri_utf8
);
return
::
GetInfo
(
ctx
,
mapped
.
c_str
());
return
::
GetInfo
(
ctx
,
m
utex
,
m
apped
.
c_str
());
}
std
::
unique_ptr
<
StorageDirectoryReader
>
...
...
@@ -132,12 +137,13 @@ SmbclientStorage::OpenDirectory(std::string_view uri_utf8)
SMBCFILE
*
handle
;
{
const
std
::
lock_guard
<
Mutex
>
protect
(
smbclient_
mutex
);
const
std
::
lock_guard
<
Mutex
>
protect
(
mutex
);
handle
=
ctx
.
OpenDirectory
(
mapped
.
c_str
());
if
(
handle
==
nullptr
)
throw
MakeErrno
(
"Failed to open directory"
);
}
if
(
handle
==
nullptr
)
throw
MakeErrno
(
"Failed to open directory"
);
return
std
::
make_unique
<
SmbclientDirectoryReader
>
(
*
this
,
std
::
move
(
mapped
),
handle
);
...
...
@@ -154,14 +160,14 @@ SkipNameFS(const char *name) noexcept
SmbclientDirectoryReader
::~
SmbclientDirectoryReader
()
{
const
std
::
lock_guard
<
Mutex
>
lock
(
s
mbclient_
mutex
);
const
std
::
lock_guard
<
Mutex
>
lock
(
s
torage
.
mutex
);
storage
.
ctx
.
CloseDirectory
(
handle
);
}
const
char
*
SmbclientDirectoryReader
::
Read
()
noexcept
{
const
std
::
lock_guard
<
Mutex
>
protect
(
s
mbclient_
mutex
);
const
std
::
lock_guard
<
Mutex
>
protect
(
s
torage
.
mutex
);
while
(
auto
e
=
storage
.
ctx
.
ReadDirectory
(
handle
))
{
name
=
e
->
name
;
...
...
@@ -176,7 +182,7 @@ StorageFileInfo
SmbclientDirectoryReader
::
GetInfo
([[
maybe_unused
]]
bool
follow
)
{
const
std
::
string
path
=
PathTraitsUTF8
::
Build
(
base
,
name
);
return
::
GetInfo
(
storage
.
ctx
,
path
.
c_str
());
return
::
GetInfo
(
storage
.
ctx
,
storage
.
mutex
,
path
.
c_str
());
}
static
std
::
unique_ptr
<
Storage
>
...
...
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