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
5de0f3f3
Commit
5de0f3f3
authored
Jan 14, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
db/upnp/WorkQueue: remove unnecessary "waiting" attributes
parent
9f316e11
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
24 deletions
+9
-24
WorkQueue.hxx
src/db/upnp/WorkQueue.hxx
+9
-24
No files found.
src/db/upnp/WorkQueue.hxx
View file @
5de0f3f3
...
@@ -67,9 +67,6 @@ class WorkQueue {
...
@@ -67,9 +67,6 @@ class WorkQueue {
Cond
client_cond
;
Cond
client_cond
;
Cond
worker_cond
;
Cond
worker_cond
;
Mutex
mutex
;
Mutex
mutex
;
// Client/Worker threads currently waiting for a job
unsigned
n_clients_waiting
;
unsigned
n_workers_waiting
;
public
:
public
:
/** Create a WorkQueue
/** Create a WorkQueue
...
@@ -82,8 +79,7 @@ public:
...
@@ -82,8 +79,7 @@ public:
:
name
(
_name
),
high
(
hi
),
low
(
lo
),
:
name
(
_name
),
high
(
hi
),
low
(
lo
),
n_workers_exited
(
0
),
n_workers_exited
(
0
),
ok
(
true
),
ok
(
true
),
n_threads
(
0
),
threads
(
nullptr
),
n_threads
(
0
),
threads
(
nullptr
)
n_clients_waiting
(
0
),
n_workers_waiting
(
0
)
{
{
}
}
...
@@ -136,20 +132,15 @@ public:
...
@@ -136,20 +132,15 @@ public:
while
(
IsOK
()
&&
high
>
0
&&
queue
.
size
()
>=
high
)
{
while
(
IsOK
()
&&
high
>
0
&&
queue
.
size
()
>=
high
)
{
// Keep the order: we test IsOK() AFTER the sleep...
// Keep the order: we test IsOK() AFTER the sleep...
n_clients_waiting
++
;
client_cond
.
wait
(
mutex
);
client_cond
.
wait
(
mutex
);
if
(
!
IsOK
())
{
if
(
!
IsOK
())
n_clients_waiting
--
;
return
false
;
return
false
;
}
n_clients_waiting
--
;
}
}
queue
.
push
(
t
);
queue
.
push
(
t
);
if
(
n_workers_waiting
>
0
)
{
// Just wake one worker, there is only one new task.
// Just wake one worker, there is only one new task.
worker_cond
.
signal
();
worker_cond
.
signal
();
}
return
true
;
return
true
;
}
}
...
@@ -165,9 +156,7 @@ public:
...
@@ -165,9 +156,7 @@ public:
ok
=
false
;
ok
=
false
;
while
(
n_workers_exited
<
n_threads
)
{
while
(
n_workers_exited
<
n_threads
)
{
worker_cond
.
broadcast
();
worker_cond
.
broadcast
();
n_clients_waiting
++
;
client_cond
.
wait
(
mutex
);
client_cond
.
wait
(
mutex
);
n_clients_waiting
--
;
}
}
// Perform the thread joins and compute overall status
// Perform the thread joins and compute overall status
...
@@ -182,7 +171,7 @@ public:
...
@@ -182,7 +171,7 @@ public:
n_threads
=
0
;
n_threads
=
0
;
// Reset to start state.
// Reset to start state.
n_workers_exited
=
n_clients_waiting
=
n_workers_waiting
=
0
;
n_workers_exited
=
0
;
ok
=
true
;
ok
=
true
;
}
}
...
@@ -200,7 +189,6 @@ public:
...
@@ -200,7 +189,6 @@ public:
}
}
while
(
IsOK
()
&&
queue
.
size
()
<
low
)
{
while
(
IsOK
()
&&
queue
.
size
()
<
low
)
{
n_workers_waiting
++
;
if
(
queue
.
empty
())
if
(
queue
.
empty
())
client_cond
.
broadcast
();
client_cond
.
broadcast
();
worker_cond
.
wait
(
mutex
);
worker_cond
.
wait
(
mutex
);
...
@@ -210,18 +198,15 @@ public:
...
@@ -210,18 +198,15 @@ public:
LOGERR
((
"WorkQueue::take:%s: cond_wait failed or !ok
\n
"
,
LOGERR
((
"WorkQueue::take:%s: cond_wait failed or !ok
\n
"
,
name
.
c_str
()));
name
.
c_str
()));
}
}
n_workers_waiting
--
;
return
false
;
return
false
;
}
}
n_workers_waiting
--
;
}
}
tp
=
queue
.
front
();
tp
=
queue
.
front
();
queue
.
pop
();
queue
.
pop
();
if
(
n_clients_waiting
>
0
)
{
// No reason to wake up more than one client thread
// No reason to wake up more than one client thread
client_cond
.
signal
();
client_cond
.
signal
();
}
return
true
;
return
true
;
}
}
...
...
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