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
6805fa2f
Commit
6805fa2f
authored
Jan 30, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
InotifyUpdate: use std::map instead of GTree
parent
4d6b9611
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
38 deletions
+25
-38
InotifyUpdate.cxx
src/InotifyUpdate.cxx
+25
-38
No files found.
src/InotifyUpdate.cxx
View file @
6805fa2f
...
...
@@ -26,6 +26,9 @@
#include "fs/Path.hxx"
#include <glib.h>
#include <map>
#include <assert.h>
#include <sys/inotify.h>
#include <sys/stat.h>
...
...
@@ -59,40 +62,31 @@ static InotifyQueue *inotify_queue;
static
unsigned
inotify_max_depth
;
static
struct
watch_directory
inotify_root
;
static
GTree
*
inotify_directories
;
static
gint
compare
(
gconstpointer
a
,
gconstpointer
b
)
{
if
(
a
<
b
)
return
-
1
;
else
if
(
a
>
b
)
return
1
;
else
return
0
;
}
static
std
::
map
<
int
,
watch_directory
*>
inotify_directories
;
static
void
tree_add_watch_directory
(
struct
watch_directory
*
directory
)
{
g_tree_insert
(
inotify_directories
,
GINT_TO_POINTER
(
directory
->
descriptor
),
directory
);
inotify_directories
.
insert
(
std
::
make_pair
(
directory
->
descriptor
,
directory
)
);
}
static
void
tree_remove_watch_directory
(
struct
watch_directory
*
directory
)
{
G_GNUC_UNUSED
bool
found
=
g_tree_remove
(
inotify_directories
,
GINT_TO_POINTER
(
directory
->
descriptor
));
assert
(
found
);
auto
i
=
inotify_directories
.
find
(
directory
->
descriptor
);
assert
(
i
!=
inotify_directories
.
end
());
inotify_directories
.
erase
(
i
);
}
static
struct
watch_directory
*
tree_find_watch_directory
(
int
wd
)
{
return
(
struct
watch_directory
*
)
g_tree_lookup
(
inotify_directories
,
GINT_TO_POINTER
(
wd
));
auto
i
=
inotify_directories
.
find
(
wd
);
if
(
i
==
inotify_directories
.
end
())
return
nullptr
;
return
i
->
second
;
}
static
void
...
...
@@ -337,7 +331,6 @@ mpd_inotify_init(unsigned max_depth)
return
;
}
inotify_directories
=
g_tree_new
(
compare
);
tree_add_watch_directory
(
&
inotify_root
);
recursive_watch_subdirectories
(
&
inotify_root
,
path
.
c_str
(),
0
);
...
...
@@ -347,21 +340,6 @@ mpd_inotify_init(unsigned max_depth)
g_debug
(
"watching music directory"
);
}
static
gboolean
free_watch_directory
(
G_GNUC_UNUSED
gpointer
key
,
gpointer
value
,
G_GNUC_UNUSED
gpointer
data
)
{
struct
watch_directory
*
directory
=
(
struct
watch_directory
*
)
value
;
g_free
(
directory
->
name
);
g_list_free
(
directory
->
children
);
if
(
directory
!=
&
inotify_root
)
g_slice_free
(
struct
watch_directory
,
directory
);
return
false
;
}
void
mpd_inotify_finish
(
void
)
{
...
...
@@ -371,6 +349,15 @@ mpd_inotify_finish(void)
delete
inotify_queue
;
delete
inotify_source
;
g_tree_foreach
(
inotify_directories
,
free_watch_directory
,
NULL
);
g_tree_destroy
(
inotify_directories
);
for
(
auto
i
:
inotify_directories
)
{
watch_directory
*
directory
=
i
.
second
;
g_free
(
directory
->
name
);
g_list_free
(
directory
->
children
);
if
(
directory
!=
&
inotify_root
)
g_slice_free
(
struct
watch_directory
,
directory
);
}
inotify_directories
.
clear
();
}
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