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
c6d8f6da
Commit
c6d8f6da
authored
Jan 14, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
db/upnp/WorkQueue: use array instead of std::list
Reduce bloat further.
parent
73fd98b8
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
15 deletions
+19
-15
WorkQueue.hxx
src/db/upnp/WorkQueue.hxx
+19
-15
No files found.
src/db/upnp/WorkQueue.hxx
View file @
c6d8f6da
...
...
@@ -59,7 +59,8 @@ class WorkQueue {
unsigned
n_workers_exited
;
bool
ok
;
std
::
list
<
pthread_t
>
threads
;
unsigned
n_threads
;
pthread_t
*
threads
;
// Synchronization
std
::
queue
<
T
>
queue
;
...
...
@@ -81,6 +82,7 @@ public:
:
name
(
_name
),
high
(
hi
),
low
(
lo
),
n_workers_exited
(
0
),
ok
(
true
),
n_threads
(
0
),
threads
(
nullptr
),
n_clients_waiting
(
0
),
n_workers_waiting
(
0
)
{
}
...
...
@@ -101,15 +103,19 @@ public:
{
const
ScopeLock
protect
(
mutex
);
assert
(
nworkers
>
0
);
assert
(
n_threads
==
0
);
assert
(
threads
==
nullptr
);
threads
=
new
pthread_t
[
n_threads
];
for
(
int
i
=
0
;
i
<
nworkers
;
i
++
)
{
int
err
;
pthread_t
thr
;
if
((
err
=
pthread_create
(
&
thr
,
0
,
workproc
,
arg
)))
{
if
((
err
=
pthread_create
(
&
threads
[
n_threads
++
],
0
,
workproc
,
arg
)))
{
LOGERR
((
"WorkQueue:%s: pthread_create failed, err %d
\n
"
,
name
.
c_str
(),
err
));
return
false
;
}
threads
.
push_back
(
thr
);
}
return
true
;
}
...
...
@@ -178,7 +184,7 @@ public:
// We're done when the queue is empty AND all workers are back
// waiting for a task.
while
(
IsOK
()
&&
(
queue
.
size
()
>
0
||
n_workers_waiting
!=
threads
.
size
()
))
{
n_workers_waiting
!=
n_threads
))
{
n_clients_waiting
++
;
client_cond
.
wait
(
mutex
);
n_clients_waiting
--
;
...
...
@@ -197,13 +203,9 @@ public:
{
const
ScopeLock
protect
(
mutex
);
if
(
threads
.
empty
())
// Already called ?
return
;
// Wait for all worker threads to have called workerExit()
ok
=
false
;
while
(
n_workers_exited
<
threads
.
size
()
)
{
while
(
n_workers_exited
<
n_threads
)
{
worker_cond
.
broadcast
();
n_clients_waiting
++
;
client_cond
.
wait
(
mutex
);
...
...
@@ -212,13 +214,15 @@ public:
// Perform the thread joins and compute overall status
// Workers return (void*)1 if ok
while
(
!
threads
.
empty
()
)
{
for
(
unsigned
i
=
0
;
i
<
n_threads
;
++
i
)
{
void
*
status
;
auto
thread
=
threads
.
front
();
pthread_join
(
thread
,
&
status
);
threads
.
pop_front
();
pthread_join
(
threads
[
i
],
&
status
);
}
delete
[]
threads
;
threads
=
nullptr
;
n_threads
=
0
;
// Reset to start state.
n_workers_exited
=
n_clients_waiting
=
n_workers_waiting
=
0
;
ok
=
true
;
...
...
@@ -283,7 +287,7 @@ public:
private
:
bool
IsOK
()
{
return
ok
&&
n_workers_exited
==
0
&&
!
threads
.
empty
()
;
return
ok
&&
n_workers_exited
==
0
&&
n_threads
>
0
;
}
};
...
...
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