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
c1f90a99
Commit
c1f90a99
authored
Aug 08, 2012
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tag_pool: use GStaticMutex
Eliminates explicit global initialisation.
parent
510097cc
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
24 additions
and
49 deletions
+24
-49
main.c
src/main.c
+0
-3
tag.c
src/tag.c
+10
-10
tag_pool.c
src/tag_pool.c
+11
-14
tag_pool.h
src/tag_pool.h
+1
-5
DumpDatabase.cxx
test/DumpDatabase.cxx
+1
-3
dump_playlist.c
test/dump_playlist.c
+0
-3
dump_text_file.c
test/dump_text_file.c
+0
-3
run_decoder.c
test/run_decoder.c
+0
-5
run_input.c
test/run_input.c
+1
-3
No files found.
src/main.c
View file @
c1f90a99
...
...
@@ -53,7 +53,6 @@
#include "tag.h"
#include "zeroconf.h"
#include "event_pipe.h"
#include "tag_pool.h"
#include "mpd_error.h"
#ifdef ENABLE_INOTIFY
...
...
@@ -359,7 +358,6 @@ int mpd_main(int argc, char *argv[])
io_thread_init
();
winsock_init
();
idle_init
();
tag_pool_init
();
config_global_init
();
success
=
parse_cmdline
(
argc
,
argv
,
&
options
,
&
error
);
...
...
@@ -544,7 +542,6 @@ int mpd_main(int argc, char *argv[])
archive_plugin_deinit_all
();
#endif
config_global_finish
();
tag_pool_deinit
();
idle_deinit
();
stats_global_finish
();
io_thread_deinit
();
...
...
src/tag.c
View file @
c1f90a99
...
...
@@ -168,9 +168,9 @@ static void tag_delete_item(struct tag *tag, unsigned idx)
assert
(
idx
<
tag
->
num_items
);
tag
->
num_items
--
;
g_
mutex_lock
(
tag_pool_lock
);
g_
static_mutex_lock
(
&
tag_pool_lock
);
tag_pool_put_item
(
tag
->
items
[
idx
]);
g_
mutex_unlock
(
tag_pool_lock
);
g_
static_mutex_unlock
(
&
tag_pool_lock
);
if
(
tag
->
num_items
-
idx
>
0
)
{
memmove
(
tag
->
items
+
idx
,
tag
->
items
+
idx
+
1
,
...
...
@@ -202,10 +202,10 @@ void tag_free(struct tag *tag)
assert
(
tag
!=
NULL
);
g_
mutex_lock
(
tag_pool_lock
);
g_
static_mutex_lock
(
&
tag_pool_lock
);
for
(
i
=
tag
->
num_items
;
--
i
>=
0
;
)
tag_pool_put_item
(
tag
->
items
[
i
]);
g_
mutex_unlock
(
tag_pool_lock
);
g_
static_mutex_unlock
(
&
tag_pool_lock
);
if
(
tag
->
items
==
bulk
.
items
)
{
#ifndef NDEBUG
...
...
@@ -231,10 +231,10 @@ struct tag *tag_dup(const struct tag *tag)
ret
->
num_items
=
tag
->
num_items
;
ret
->
items
=
ret
->
num_items
>
0
?
g_malloc
(
items_size
(
tag
))
:
NULL
;
g_
mutex_lock
(
tag_pool_lock
);
g_
static_mutex_lock
(
&
tag_pool_lock
);
for
(
unsigned
i
=
0
;
i
<
tag
->
num_items
;
i
++
)
ret
->
items
[
i
]
=
tag_pool_dup_item
(
tag
->
items
[
i
]);
g_
mutex_unlock
(
tag_pool_lock
);
g_
static_mutex_unlock
(
&
tag_pool_lock
);
return
ret
;
}
...
...
@@ -255,7 +255,7 @@ tag_merge(const struct tag *base, const struct tag *add)
ret
->
num_items
=
base
->
num_items
+
add
->
num_items
;
ret
->
items
=
ret
->
num_items
>
0
?
g_malloc
(
items_size
(
ret
))
:
NULL
;
g_
mutex_lock
(
tag_pool_lock
);
g_
static_mutex_lock
(
&
tag_pool_lock
);
/* copy all items from "add" */
...
...
@@ -270,7 +270,7 @@ tag_merge(const struct tag *base, const struct tag *add)
if
(
!
tag_has_type
(
add
,
base
->
items
[
i
]
->
type
))
ret
->
items
[
n
++
]
=
tag_pool_dup_item
(
base
->
items
[
i
]);
g_
mutex_unlock
(
tag_pool_lock
);
g_
static_mutex_unlock
(
&
tag_pool_lock
);
assert
(
n
<=
ret
->
num_items
);
...
...
@@ -502,9 +502,9 @@ tag_add_item_internal(struct tag *tag, enum tag_type type,
items_size
(
tag
)
-
sizeof
(
struct
tag_item
*
));
}
g_
mutex_lock
(
tag_pool_lock
);
g_
static_mutex_lock
(
&
tag_pool_lock
);
tag
->
items
[
i
]
=
tag_pool_get_item
(
type
,
value
,
len
);
g_
mutex_unlock
(
tag_pool_lock
);
g_
static_mutex_unlock
(
&
tag_pool_lock
);
g_free
(
p
);
}
...
...
src/tag_pool.c
View file @
c1f90a99
...
...
@@ -22,7 +22,17 @@
#include <assert.h>
GMutex
*
tag_pool_lock
=
NULL
;
#if GCC_CHECK_VERSION(4, 2)
/* workaround for a warning caused by G_STATIC_MUTEX_INIT */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
#endif
GStaticMutex
tag_pool_lock
=
G_STATIC_MUTEX_INIT
;
#if GCC_CHECK_VERSION(4, 2)
#pragma GCC diagnostic pop
#endif
#define NUM_SLOTS 4096
...
...
@@ -81,19 +91,6 @@ static struct slot *slot_alloc(struct slot *next,
return
slot
;
}
void
tag_pool_init
(
void
)
{
g_assert
(
tag_pool_lock
==
NULL
);
tag_pool_lock
=
g_mutex_new
();
}
void
tag_pool_deinit
(
void
)
{
g_assert
(
tag_pool_lock
!=
NULL
);
g_mutex_free
(
tag_pool_lock
);
tag_pool_lock
=
NULL
;
}
struct
tag_item
*
tag_pool_get_item
(
enum
tag_type
type
,
const
char
*
value
,
size_t
length
)
{
...
...
src/tag_pool.h
View file @
c1f90a99
...
...
@@ -24,14 +24,10 @@
#include <glib.h>
extern
G
Mutex
*
tag_pool_lock
;
extern
G
StaticMutex
tag_pool_lock
;
struct
tag_item
;
void
tag_pool_init
(
void
);
void
tag_pool_deinit
(
void
);
struct
tag_item
*
tag_pool_get_item
(
enum
tag_type
type
,
const
char
*
value
,
size_t
length
);
...
...
test/DumpDatabase.cxx
View file @
c1f90a99
...
...
@@ -27,7 +27,7 @@
extern
"C"
{
#include "conf.h"
#include "tag
_pool
.h"
#include "tag.h"
}
#include <iostream>
...
...
@@ -95,7 +95,6 @@ main(int argc, char **argv)
/* initialize MPD */
tag_pool_init
();
config_global_init
();
if
(
!
config_read_file
(
config_path
,
&
error
))
{
...
...
@@ -147,7 +146,6 @@ main(int argc, char **argv)
/* deinitialize everything */
config_global_finish
();
tag_pool_deinit
();
return
EXIT_SUCCESS
;
}
test/dump_playlist.c
View file @
c1f90a99
...
...
@@ -21,7 +21,6 @@
#include "io_thread.h"
#include "input_init.h"
#include "input_stream.h"
#include "tag_pool.h"
#include "tag_save.h"
#include "conf.h"
#include "song.h"
...
...
@@ -157,7 +156,6 @@ int main(int argc, char **argv)
/* initialize MPD */
tag_pool_init
();
config_global_init
();
success
=
config_read_file
(
argv
[
1
],
&
error
);
if
(
!
success
)
{
...
...
@@ -249,7 +247,6 @@ int main(int argc, char **argv)
input_stream_global_finish
();
io_thread_deinit
();
config_global_finish
();
tag_pool_deinit
();
return
0
;
}
test/dump_text_file.c
View file @
c1f90a99
...
...
@@ -22,7 +22,6 @@
#include "input_init.h"
#include "input_stream.h"
#include "text_input_stream.h"
#include "tag_pool.h"
#include "conf.h"
#include "stdbin.h"
...
...
@@ -112,7 +111,6 @@ int main(int argc, char **argv)
/* initialize MPD */
tag_pool_init
();
config_global_init
();
io_thread_init
();
...
...
@@ -164,7 +162,6 @@ int main(int argc, char **argv)
io_thread_deinit
();
config_global_finish
();
tag_pool_deinit
();
return
ret
;
}
test/run_decoder.c
View file @
c1f90a99
...
...
@@ -21,7 +21,6 @@
#include "io_thread.h"
#include "decoder_list.h"
#include "decoder_api.h"
#include "tag_pool.h"
#include "input_init.h"
#include "input_stream.h"
#include "audio_format.h"
...
...
@@ -191,8 +190,6 @@ int main(int argc, char **argv)
return
EXIT_FAILURE
;
}
tag_pool_init
();
if
(
!
input_stream_global_init
(
&
error
))
{
g_warning
(
"%s"
,
error
->
message
);
g_error_free
(
error
);
...
...
@@ -248,7 +245,5 @@ int main(int argc, char **argv)
return
1
;
}
tag_pool_deinit
();
return
0
;
}
test/run_input.c
View file @
c1f90a99
...
...
@@ -21,8 +21,8 @@
#include "io_thread.h"
#include "input_init.h"
#include "input_stream.h"
#include "tag_pool.h"
#include "tag_save.h"
#include "tag.h"
#include "conf.h"
#include "stdbin.h"
...
...
@@ -127,7 +127,6 @@ int main(int argc, char **argv)
/* initialize MPD */
tag_pool_init
();
config_global_init
();
io_thread_init
();
...
...
@@ -179,7 +178,6 @@ int main(int argc, char **argv)
io_thread_deinit
();
config_global_finish
();
tag_pool_deinit
();
return
ret
;
}
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