diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2017-10-13 13:09:33 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2017-10-13 13:09:33 +0200 |
commit | 53202e7781276eadd2a4bed3b26eb1586bf85725 (patch) | |
tree | 58c18e58f96ae30516e73793780399870961282b /staging_vespalib | |
parent | 36fa7fa1f97d14b358d1a703be91712d39514aed (diff) |
Earlier conclusion about issue with too ealy stop was incorrect. However adding sanity checks to catch incorrect usage.
Diffstat (limited to 'staging_vespalib')
-rw-r--r-- | staging_vespalib/src/vespa/vespalib/util/document_runnable.cpp | 12 | ||||
-rw-r--r-- | staging_vespalib/src/vespa/vespalib/util/document_runnable.h | 3 |
2 files changed, 9 insertions, 6 deletions
diff --git a/staging_vespalib/src/vespa/vespalib/util/document_runnable.cpp b/staging_vespalib/src/vespa/vespalib/util/document_runnable.cpp index 11fbf9d1655..86f361ea1fe 100644 --- a/staging_vespalib/src/vespa/vespalib/util/document_runnable.cpp +++ b/staging_vespalib/src/vespa/vespalib/util/document_runnable.cpp @@ -2,7 +2,6 @@ #include "document_runnable.h" #include <vespa/vespalib/util/exceptions.h> -#include <vespa/vespalib/util/stringfmt.h> namespace document { @@ -13,13 +12,18 @@ Runnable::Runnable(FastOS_ThreadPool* pool) if (pool) start(*pool); } +Runnable::~Runnable() { + vespalib::MonitorGuard monitorGuard(_stateLock); + assert(_state == NOT_RUNNING); +} + bool Runnable::start(FastOS_ThreadPool& pool) { vespalib::MonitorGuard monitor(_stateLock); while (_state == STOPPING) monitor.wait(); if (_state != NOT_RUNNING) return false; _state = STARTING; - if (pool.NewThread(this) == NULL) { + if (pool.NewThread(this) == nullptr) { throw vespalib::IllegalStateException("Faled starting a new thread", VESPA_STRLOC); } return true; @@ -29,7 +33,6 @@ bool Runnable::stop() { vespalib::MonitorGuard monitor(_stateLock); if (_state == STOPPING || _state == NOT_RUNNING) return false; - while (_state == STARTING) monitor.wait(); GetThread()->SetBreakFlag(); _state = STOPPING; return onStop(); @@ -43,7 +46,7 @@ bool Runnable::onStop() bool Runnable::join() const { vespalib::MonitorGuard monitor(_stateLock); - if (_state == STARTING || _state == RUNNING) return false; + assert ((_state != STARTING) && (_state != RUNNING)); while (_state != NOT_RUNNING) monitor.wait(); return true; } @@ -56,7 +59,6 @@ void Runnable::Run(FastOS_ThreadInterface*, void*) // called even though about to stop for consistency) if (_state == STARTING) { _state = RUNNING; - monitor.broadcast(); } } diff --git a/staging_vespalib/src/vespa/vespalib/util/document_runnable.h b/staging_vespalib/src/vespa/vespalib/util/document_runnable.h index 456c7fefdbb..ec2c10d1f6e 100644 --- a/staging_vespalib/src/vespa/vespalib/util/document_runnable.h +++ b/staging_vespalib/src/vespa/vespalib/util/document_runnable.h @@ -42,7 +42,8 @@ public: * Create a runnable. * @param pool If set, runnable will be started in constructor. */ - Runnable(FastOS_ThreadPool* pool = 0); + Runnable(FastOS_ThreadPool* pool = nullptr); + ~Runnable(); /** * Start this runnable. |