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
d44880df
Commit
d44880df
authored
Oct 17, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
UpdateGlue: handle update id management
Add UpdateQueueItem::id to keep track of the id in every item. Replaces thhe hack in update_queue_push().
parent
0c63632c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
21 deletions
+33
-21
UpdateGlue.cxx
src/UpdateGlue.cxx
+20
-10
UpdateQueue.cxx
src/UpdateQueue.cxx
+5
-5
UpdateQueue.hxx
src/UpdateQueue.hxx
+8
-6
No files found.
src/UpdateGlue.cxx
View file @
d44880df
...
...
@@ -57,7 +57,7 @@ static UpdateQueueItem next;
unsigned
isUpdatingDB
(
void
)
{
return
(
progress
!=
UPDATE_PROGRESS_IDLE
)
?
update_task_id
:
0
;
return
next
.
id
;
}
static
void
...
...
@@ -101,10 +101,17 @@ spawn_update_task(UpdateQueueItem &&i)
if
(
!
update_thread
.
Start
(
update_task
,
nullptr
,
error
))
FatalError
(
error
);
if
(
++
update_task_id
>
update_task_id_max
)
update_task_id
=
1
;
FormatDebug
(
update_domain
,
"spawned thread for update job id %i"
,
update_task_id
);
"spawned thread for update job id %i"
,
next
.
id
);
}
static
unsigned
generate_update_id
()
{
unsigned
id
=
update_task_id
+
1
;
if
(
id
>
update_task_id_max
)
id
=
1
;
return
id
;
}
unsigned
...
...
@@ -116,19 +123,20 @@ update_enqueue(const char *path, bool discard)
return
0
;
if
(
progress
!=
UPDATE_PROGRESS_IDLE
)
{
unsigned
next_task_id
=
update_queue_push
(
path
,
discard
,
update_task_id
);
if
(
next_task_id
==
0
)
const
unsigned
id
=
generate_update_id
();
if
(
!
update_queue_push
(
path
,
discard
,
id
))
return
0
;
return
next_task_id
>
update_task_id_max
?
1
:
next_task_id
;
update_task_id
=
id
;
return
id
;
}
spawn_update_task
(
UpdateQueueItem
(
path
,
discard
));
const
unsigned
id
=
update_task_id
=
generate_update_id
();
spawn_update_task
(
UpdateQueueItem
(
path
,
discard
,
id
));
idle_add
(
IDLE_UPDATE
);
return
update_task_
id
;
return
id
;
}
/**
...
...
@@ -137,8 +145,10 @@ update_enqueue(const char *path, bool discard)
static
void
update_finished_event
(
void
)
{
assert
(
progress
==
UPDATE_PROGRESS_DONE
);
assert
(
next
.
IsDefined
());
update_thread
.
Join
();
next
=
UpdateQueueItem
();
idle_add
(
IDLE_UPDATE
);
...
...
src/UpdateQueue.cxx
View file @
d44880df
...
...
@@ -27,14 +27,14 @@ static constexpr unsigned MAX_UPDATE_QUEUE_SIZE = 32;
static
std
::
queue
<
UpdateQueueItem
,
std
::
list
<
UpdateQueueItem
>>
update_queue
;
unsigned
update_queue_push
(
const
char
*
path
,
bool
discard
,
unsigned
base
)
bool
update_queue_push
(
const
char
*
path
,
bool
discard
,
unsigned
id
)
{
if
(
update_queue
.
size
()
>=
MAX_UPDATE_QUEUE_SIZE
)
return
0
;
return
false
;
update_queue
.
emplace
(
path
,
discard
);
return
base
+
update_queue
.
size
()
;
update_queue
.
emplace
(
path
,
discard
,
id
);
return
true
;
}
UpdateQueueItem
...
...
src/UpdateQueue.hxx
View file @
d44880df
...
...
@@ -26,19 +26,21 @@
struct
UpdateQueueItem
{
std
::
string
path_utf8
;
unsigned
id
;
bool
discard
;
UpdateQueueItem
()
=
default
;
UpdateQueueItem
(
const
char
*
_path
,
bool
_discard
)
:
path_utf8
(
_path
),
discard
(
_discard
)
{}
UpdateQueueItem
()
:
id
(
0
)
{}
UpdateQueueItem
(
const
char
*
_path
,
bool
_discard
,
unsigned
_id
)
:
path_utf8
(
_path
),
id
(
_id
),
discard
(
_discard
)
{}
bool
IsDefined
()
const
{
return
!
path_utf8
.
empty
()
;
return
id
!=
0
;
}
};
unsigned
update_queue_push
(
const
char
*
path
,
bool
discard
,
unsigned
base
);
bool
update_queue_push
(
const
char
*
path
,
bool
discard
,
unsigned
id
);
UpdateQueueItem
update_queue_shift
();
...
...
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