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
7ef40de9
Commit
7ef40de9
authored
Oct 17, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
UpdateQueue: use std::string and std::queue
parent
196ec256
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
40 deletions
+35
-40
UpdateGlue.cxx
src/UpdateGlue.cxx
+4
-6
UpdateQueue.cxx
src/UpdateQueue.cxx
+14
-32
UpdateQueue.hxx
src/UpdateQueue.hxx
+17
-2
No files found.
src/UpdateGlue.cxx
View file @
7ef40de9
...
...
@@ -139,8 +139,6 @@ update_enqueue(const char *path, bool _discard)
*/
static
void
update_finished_event
(
void
)
{
char
*
path
;
assert
(
progress
==
UPDATE_PROGRESS_DONE
);
update_thread
.
Join
();
...
...
@@ -151,11 +149,11 @@ static void update_finished_event(void)
/* send "idle" events */
instance
->
DatabaseModified
();
path
=
update_queue_shift
(
&
discard
);
if
(
path
!=
NULL
)
{
auto
i
=
update_queue_shift
(
);
if
(
i
.
IsDefined
()
)
{
/* schedule the next path */
spawn_update_task
(
path
)
;
g_free
(
path
);
discard
=
i
.
discard
;
spawn_update_task
(
i
.
path_utf8
.
c_str
()
);
}
else
{
progress
=
UPDATE_PROGRESS_IDLE
;
...
...
src/UpdateQueue.cxx
View file @
7ef40de9
...
...
@@ -19,49 +19,31 @@
#include "config.h"
#include "UpdateQueue.hxx"
#include "util/Macros.hxx"
#include <glib.h>
#include <queue>
#include <list>
#include <assert.h>
#include <string.h>
static
constexpr
unsigned
MAX_UPDATE_QUEUE_SIZE
=
32
;
/* make this dynamic?, or maybe this is big enough... */
static
struct
{
char
*
path
;
bool
discard
;
}
update_queue
[
32
];
static
size_t
update_queue_length
;
static
std
::
queue
<
UpdateQueueItem
,
std
::
list
<
UpdateQueueItem
>>
update_queue
;
unsigned
update_queue_push
(
const
char
*
path
,
bool
discard
,
unsigned
base
)
{
assert
(
update_queue_length
<=
ARRAY_SIZE
(
update_queue
));
if
(
update_queue_length
==
ARRAY_SIZE
(
update_queue
))
if
(
update_queue
.
size
()
>=
MAX_UPDATE_QUEUE_SIZE
)
return
0
;
update_queue
[
update_queue_length
].
path
=
g_strdup
(
path
);
update_queue
[
update_queue_length
].
discard
=
discard
;
++
update_queue_length
;
return
base
+
update_queue_length
;
update_queue
.
emplace
(
path
,
discard
);
return
base
+
update_queue
.
size
();
}
char
*
update_queue_shift
(
bool
*
discard_r
)
UpdateQueueItem
update_queue_shift
()
{
char
*
path
;
if
(
update_queue_length
==
0
)
return
NULL
;
path
=
update_queue
[
0
].
path
;
*
discard_r
=
update_queue
[
0
].
discard
;
if
(
update_queue
.
empty
())
return
UpdateQueueItem
();
memmove
(
&
update_queue
[
0
],
&
update_queue
[
1
],
--
update_queue_length
*
sizeof
(
update_queue
[
0
])
);
return
path
;
auto
i
=
std
::
move
(
update_queue
.
front
());
update_queue
.
pop
(
);
return
i
;
}
src/UpdateQueue.hxx
View file @
7ef40de9
...
...
@@ -22,10 +22,25 @@
#include "check.h"
#include <string>
struct
UpdateQueueItem
{
std
::
string
path_utf8
;
bool
discard
;
UpdateQueueItem
()
=
default
;
UpdateQueueItem
(
const
char
*
_path
,
bool
_discard
)
:
path_utf8
(
_path
),
discard
(
_discard
)
{}
bool
IsDefined
()
const
{
return
!
path_utf8
.
empty
();
}
};
unsigned
update_queue_push
(
const
char
*
path
,
bool
discard
,
unsigned
base
);
char
*
update_queue_shift
(
bool
*
discard_r
);
UpdateQueueItem
update_queue_shift
();
#endif
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