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
837bd79b
Commit
837bd79b
authored
Feb 02, 2012
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
db_lock: add assertions
parent
3edd4a24
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
0 deletions
+33
-0
db_lock.c
src/db_lock.c
+4
-0
db_lock.h
src/db_lock.h
+29
-0
No files found.
src/db_lock.c
View file @
837bd79b
...
...
@@ -21,3 +21,7 @@
#include "db_lock.h"
GStaticMutex
db_mutex
=
G_STATIC_MUTEX_INIT
;
#ifndef NDEBUG
GThread
*
db_mutex_holder
;
#endif
src/db_lock.h
View file @
837bd79b
...
...
@@ -30,9 +30,26 @@
#include <glib.h>
#include <assert.h>
#include <stdbool.h>
extern
GStaticMutex
db_mutex
;
#ifndef NDEBUG
extern
GThread
*
db_mutex_holder
;
/**
* Does the current thread hold the database lock?
*/
G_GNUC_PURE
static
inline
bool
holding_db_lock
(
void
)
{
return
db_mutex_holder
==
g_thread_self
();
}
#endif
/**
* Obtain the global database lock. This is needed before
* dereferencing a #song or #directory. It is not recursive.
...
...
@@ -40,7 +57,14 @@ extern GStaticMutex db_mutex;
static
inline
void
db_lock
(
void
)
{
assert
(
!
holding_db_lock
());
g_static_mutex_lock
(
&
db_mutex
);
assert
(
db_mutex_holder
==
NULL
);
#ifndef NDEBUG
db_mutex_holder
=
g_thread_self
();
#endif
}
/**
...
...
@@ -49,6 +73,11 @@ db_lock(void)
static
inline
void
db_unlock
(
void
)
{
assert
(
holding_db_lock
());
#ifndef NDEBUG
db_mutex_holder
=
NULL
;
#endif
g_static_mutex_unlock
(
&
db_mutex
);
}
...
...
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