aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-01-14 11:45:49 +0100
committerMax Kellermann <max@duempel.org>2014-01-14 11:48:19 +0100
commit738991494a863ea74080202e6bc9e869a46f32e9 (patch)
treea79cdb882d96116248499e4bb9a79418aa6fc91c /src
parentee4c3ff1b815fb9bf9e03449eb50af04a559bd99 (diff)
downloadmpd-738991494a863ea74080202e6bc9e869a46f32e9.tar.gz
mpd-738991494a863ea74080202e6bc9e869a46f32e9.tar.xz
mpd-738991494a863ea74080202e6bc9e869a46f32e9.zip
db/upnp/WorkQueue: initialize "ok" to false, eliminate redundant checks
Diffstat (limited to 'src')
-rw-r--r--src/db/upnp/WorkQueue.hxx31
1 files changed, 10 insertions, 21 deletions
diff --git a/src/db/upnp/WorkQueue.hxx b/src/db/upnp/WorkQueue.hxx
index 285fb8c4e..ed58cb170 100644
--- a/src/db/upnp/WorkQueue.hxx
+++ b/src/db/upnp/WorkQueue.hxx
@@ -75,7 +75,7 @@ public:
WorkQueue(const char *_name, size_t hi = 0, size_t lo = 1)
:name(_name), high(hi), low(lo),
n_workers_exited(0),
- ok(true),
+ ok(false),
n_threads(0), threads(nullptr)
{
}
@@ -97,6 +97,7 @@ public:
const ScopeLock protect(mutex);
assert(nworkers > 0);
+ assert(!ok);
assert(n_threads == 0);
assert(threads == nullptr);
@@ -110,6 +111,8 @@ public:
return false;
}
}
+
+ ok = true;
return true;
}
@@ -121,10 +124,10 @@ public:
{
const ScopeLock protect(mutex);
- while (IsOK() && high > 0 && queue.size() >= high) {
- // Keep the order: we test IsOK() AFTER the sleep...
+ while (ok && high > 0 && queue.size() >= high) {
+ // Keep the order: we test ok AFTER the sleep...
client_cond.wait(mutex);
- if (!IsOK())
+ if (!ok)
return false;
}
@@ -163,7 +166,6 @@ public:
// Reset to start state.
n_workers_exited = 0;
- ok = true;
}
/** Take task from queue. Called from worker.
@@ -175,22 +177,15 @@ public:
{
const ScopeLock protect(mutex);
- if (!IsOK()) {
+ if (!ok)
return false;
- }
- while (IsOK() && queue.size() < low) {
+ while (ok && queue.size() < low) {
if (queue.empty())
client_cond.broadcast();
worker_cond.wait(mutex);
- if (!IsOK()) {
- // !ok is a normal condition when shutting down
- if (IsOK()) {
- LOGERR(("WorkQueue::take:%s: cond_wait failed or !ok\n",
- name.c_str()));
- }
+ if (!ok)
return false;
- }
}
tp = queue.front();
@@ -217,12 +212,6 @@ public:
ok = false;
client_cond.broadcast();
}
-
-private:
- bool IsOK()
- {
- return ok && n_threads > 0;
- }
};
#endif /* _WORKQUEUE_H_INCLUDED_ */