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
bb3f487e
Commit
bb3f487e
authored
Jul 20, 2020
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lib/smbclient/Context: add global Mutex for smbc_{new,free}_context()
Preparing to replace `smbclient_mutex`, for finer-grained locking.
parent
7d97d0ae
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
2 deletions
+22
-2
Context.cxx
src/lib/smbclient/Context.cxx
+9
-1
Context.hxx
src/lib/smbclient/Context.hxx
+13
-1
No files found.
src/lib/smbclient/Context.cxx
View file @
bb3f487e
...
...
@@ -24,6 +24,8 @@
#include <string.h>
Mutex
SmbclientContext
::
global_mutex
;
static
void
mpd_smbc_get_auth_data
([[
maybe_unused
]]
const
char
*
srv
,
[[
maybe_unused
]]
const
char
*
shr
,
...
...
@@ -40,7 +42,13 @@ mpd_smbc_get_auth_data([[maybe_unused]] const char *srv,
SmbclientContext
SmbclientContext
::
New
()
{
SMBCCTX
*
ctx
=
smbc_new_context
();
SMBCCTX
*
ctx
;
{
const
std
::
lock_guard
<
Mutex
>
protect
(
global_mutex
);
ctx
=
smbc_new_context
();
}
if
(
ctx
==
nullptr
)
throw
MakeErrno
(
"smbc_new_context() failed"
);
...
...
src/lib/smbclient/Context.hxx
View file @
bb3f487e
...
...
@@ -20,6 +20,8 @@
#ifndef MPD_SMBCLIENT_CONTEXT_HXX
#define MPD_SMBCLIENT_CONTEXT_HXX
#include "thread/Mutex.hxx"
#include <libsmbclient.h>
#include <utility>
...
...
@@ -28,6 +30,14 @@
* Wrapper for `SMBCCTX*`.
*/
class
SmbclientContext
{
/**
* This mutex protects the libsmbclient functions
* smbc_new_context() and smbc_free_context() which need to be
* serialized. We need to do this because we can't use
* smbc_thread_posix(), which is not exported by libsmbclient.
*/
static
Mutex
global_mutex
;
SMBCCTX
*
ctx
=
nullptr
;
explicit
SmbclientContext
(
SMBCCTX
*
_ctx
)
noexcept
...
...
@@ -37,8 +47,10 @@ public:
SmbclientContext
()
=
default
;
~
SmbclientContext
()
noexcept
{
if
(
ctx
!=
nullptr
)
if
(
ctx
!=
nullptr
)
{
const
std
::
lock_guard
<
Mutex
>
protect
(
global_mutex
);
smbc_free_context
(
ctx
,
1
);
}
}
SmbclientContext
(
SmbclientContext
&&
src
)
noexcept
...
...
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