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
28f3e190
Commit
28f3e190
authored
Jan 03, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
InotifyQueue: use std::deque instead of GSList
parent
c4090b67
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
37 deletions
+19
-37
InotifyQueue.cxx
src/InotifyQueue.cxx
+15
-33
InotifyQueue.hxx
src/InotifyQueue.hxx
+1
-1
InotifyUpdate.cxx
src/InotifyUpdate.cxx
+3
-3
No files found.
src/InotifyQueue.cxx
View file @
28f3e190
...
@@ -21,6 +21,9 @@
...
@@ -21,6 +21,9 @@
#include "InotifyQueue.hxx"
#include "InotifyQueue.hxx"
#include "UpdateGlue.hxx"
#include "UpdateGlue.hxx"
#include <deque>
#include <string>
#include <glib.h>
#include <glib.h>
#include <string.h>
#include <string.h>
...
@@ -37,7 +40,7 @@ enum {
...
@@ -37,7 +40,7 @@ enum {
INOTIFY_UPDATE_DELAY_S
=
5
,
INOTIFY_UPDATE_DELAY_S
=
5
,
};
};
static
GSList
*
inotify_queue
;
static
std
::
deque
<
std
::
string
>
inotify_queue
;
static
guint
queue_source_id
;
static
guint
queue_source_id
;
void
void
...
@@ -45,20 +48,11 @@ mpd_inotify_queue_init(void)
...
@@ -45,20 +48,11 @@ mpd_inotify_queue_init(void)
{
{
}
}
static
void
free_callback
(
gpointer
data
,
G_GNUC_UNUSED
gpointer
user_data
)
{
g_free
(
data
);
}
void
void
mpd_inotify_queue_finish
(
void
)
mpd_inotify_queue_finish
(
void
)
{
{
if
(
queue_source_id
!=
0
)
if
(
queue_source_id
!=
0
)
g_source_remove
(
queue_source_id
);
g_source_remove
(
queue_source_id
);
g_slist_foreach
(
inotify_queue
,
free_callback
,
NULL
);
g_slist_free
(
inotify_queue
);
}
}
static
gboolean
static
gboolean
...
@@ -66,8 +60,8 @@ mpd_inotify_run_update(G_GNUC_UNUSED gpointer data)
...
@@ -66,8 +60,8 @@ mpd_inotify_run_update(G_GNUC_UNUSED gpointer data)
{
{
unsigned
id
;
unsigned
id
;
while
(
inotify_queue
!=
NULL
)
{
while
(
!
inotify_queue
.
empty
()
)
{
c
har
*
uri_utf8
=
(
char
*
)
inotify_queue
->
data
;
c
onst
char
*
uri_utf8
=
inotify_queue
.
front
().
c_str
()
;
id
=
update_enqueue
(
uri_utf8
,
false
);
id
=
update_enqueue
(
uri_utf8
,
false
);
if
(
id
==
0
)
if
(
id
==
0
)
...
@@ -76,9 +70,7 @@ mpd_inotify_run_update(G_GNUC_UNUSED gpointer data)
...
@@ -76,9 +70,7 @@ mpd_inotify_run_update(G_GNUC_UNUSED gpointer data)
g_debug
(
"updating '%s' job=%u"
,
uri_utf8
,
id
);
g_debug
(
"updating '%s' job=%u"
,
uri_utf8
,
id
);
g_free
(
uri_utf8
);
inotify_queue
.
pop_front
();
inotify_queue
=
g_slist_delete_link
(
inotify_queue
,
inotify_queue
);
}
}
/* done, remove the timer event by returning false */
/* done, remove the timer event by returning false */
...
@@ -97,39 +89,29 @@ path_in(const char *path, const char *possible_parent)
...
@@ -97,39 +89,29 @@ path_in(const char *path, const char *possible_parent)
}
}
void
void
mpd_inotify_enqueue
(
char
*
uri_utf8
)
mpd_inotify_enqueue
(
c
onst
c
har
*
uri_utf8
)
{
{
GSList
*
old_queue
=
inotify_queue
;
if
(
queue_source_id
!=
0
)
if
(
queue_source_id
!=
0
)
g_source_remove
(
queue_source_id
);
g_source_remove
(
queue_source_id
);
queue_source_id
=
g_timeout_add_seconds
(
INOTIFY_UPDATE_DELAY_S
,
queue_source_id
=
g_timeout_add_seconds
(
INOTIFY_UPDATE_DELAY_S
,
mpd_inotify_run_update
,
NULL
);
mpd_inotify_run_update
,
NULL
);
inotify_queue
=
NULL
;
for
(
auto
i
=
inotify_queue
.
begin
(),
end
=
inotify_queue
.
end
()
;
while
(
old_queue
!=
NULL
)
{
i
!=
end
;
)
{
c
har
*
current_uri
=
(
char
*
)
old_queue
->
data
;
c
onst
char
*
current_uri
=
i
->
c_str
()
;
if
(
path_in
(
uri_utf8
,
current_uri
))
{
if
(
path_in
(
uri_utf8
,
current_uri
))
/* already enqueued */
/* already enqueued */
g_free
(
uri_utf8
);
inotify_queue
=
g_slist_concat
(
inotify_queue
,
old_queue
);
return
;
return
;
}
old_queue
=
g_slist_delete_link
(
old_queue
,
old_queue
);
if
(
path_in
(
current_uri
,
uri_utf8
))
if
(
path_in
(
current_uri
,
uri_utf8
))
/* existing path is a sub-path of the new
/* existing path is a sub-path of the new
path; we can dequeue the existing path and
path; we can dequeue the existing path and
update the new path instead */
update the new path instead */
g_free
(
current_ur
i
);
i
=
inotify_queue
.
erase
(
i
);
else
else
/* move the existing path to the new queue */
++
i
;
inotify_queue
=
g_slist_prepend
(
inotify_queue
,
current_uri
);
}
}
inotify_queue
=
g_slist_prepend
(
inotify_queue
,
uri_utf8
);
inotify_queue
.
emplace_back
(
uri_utf8
);
}
}
src/InotifyQueue.hxx
View file @
28f3e190
...
@@ -27,6 +27,6 @@ void
...
@@ -27,6 +27,6 @@ void
mpd_inotify_queue_finish
(
void
);
mpd_inotify_queue_finish
(
void
);
void
void
mpd_inotify_enqueue
(
char
*
uri_utf8
);
mpd_inotify_enqueue
(
c
onst
c
har
*
uri_utf8
);
#endif
#endif
src/InotifyUpdate.cxx
View file @
28f3e190
...
@@ -295,10 +295,10 @@ mpd_inotify_callback(int wd, unsigned mask,
...
@@ -295,10 +295,10 @@ mpd_inotify_callback(int wd, unsigned mask,
?
fs_charset_to_utf8
(
uri_fs
)
?
fs_charset_to_utf8
(
uri_fs
)
:
g_strdup
(
""
);
:
g_strdup
(
""
);
if
(
uri_utf8
!=
NULL
)
if
(
uri_utf8
!=
NULL
)
{
/* this function will take care of freeing
uri_utf8 */
mpd_inotify_enqueue
(
uri_utf8
);
mpd_inotify_enqueue
(
uri_utf8
);
g_free
(
uri_utf8
);
}
}
}
g_free
(
uri_fs
);
g_free
(
uri_fs
);
...
...
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