diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2019-01-05 22:26:40 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2019-01-05 22:26:40 +0000 |
commit | 83598fd5c744586a34d17a0395619cc6d5080411 (patch) | |
tree | 8bf29261d86fced0b8f2ca8541687d831d645d7c /vespalib | |
parent | 0e7092d8b7a636ad18e953ae169e3b9f5e4ed421 (diff) |
GC unused code and update includes
Diffstat (limited to 'vespalib')
5 files changed, 8 insertions, 99 deletions
diff --git a/vespalib/src/tests/executor/stress_test.cpp b/vespalib/src/tests/executor/stress_test.cpp index 5c7620afb14..702991fd779 100644 --- a/vespalib/src/tests/executor/stress_test.cpp +++ b/vespalib/src/tests/executor/stress_test.cpp @@ -4,6 +4,7 @@ #include <vespa/vespalib/util/executor.h> #include <vespa/vespalib/util/threadstackexecutor.h> #include <vespa/vespalib/locale/c.h> +#include <vespa/fastos/time.h> using namespace vespalib; using namespace std::literals; diff --git a/vespalib/src/tests/left_right_heap/left_right_heap_bench.cpp b/vespalib/src/tests/left_right_heap/left_right_heap_bench.cpp index dd031f0c2ce..e6fdab7d773 100644 --- a/vespalib/src/tests/left_right_heap/left_right_heap_bench.cpp +++ b/vespalib/src/tests/left_right_heap/left_right_heap_bench.cpp @@ -3,6 +3,7 @@ #include <vespa/vespalib/util/left_right_heap.h> #include <vespa/vespalib/util/stringfmt.h> #include <vespa/vespalib/util/inline.h> +#include <vespa/fastos/time.h> using namespace vespalib; diff --git a/vespalib/src/tests/simple_thread_bundle/threading_speed_test.cpp b/vespalib/src/tests/simple_thread_bundle/threading_speed_test.cpp index 688261af3e7..b113e7a2284 100644 --- a/vespalib/src/tests/simple_thread_bundle/threading_speed_test.cpp +++ b/vespalib/src/tests/simple_thread_bundle/threading_speed_test.cpp @@ -2,6 +2,7 @@ #include <vespa/vespalib/testkit/test_kit.h> #include <vespa/vespalib/util/simple_thread_bundle.h> #include <vespa/vespalib/util/box.h> +#include <vespa/fastos/time.h> using namespace vespalib; diff --git a/vespalib/src/tests/slime/summary-feature-benchmark/summary-feature-benchmark.cpp b/vespalib/src/tests/slime/summary-feature-benchmark/summary-feature-benchmark.cpp index df5b239e341..2a58f1df382 100644 --- a/vespalib/src/tests/slime/summary-feature-benchmark/summary-feature-benchmark.cpp +++ b/vespalib/src/tests/slime/summary-feature-benchmark/summary-feature-benchmark.cpp @@ -2,6 +2,7 @@ #include <vespa/vespalib/testkit/test_kit.h> #include <vespa/vespalib/util/stringfmt.h> #include <vespa/vespalib/data/slime/slime.h> +#include <vespa/fastos/time.h> using namespace vespalib; using namespace vespalib::slime::convenience; diff --git a/vespalib/src/vespa/vespalib/util/sync.h b/vespalib/src/vespa/vespalib/util/sync.h index e3f3d44122c..6461eaf9c3f 100644 --- a/vespalib/src/vespa/vespalib/util/sync.h +++ b/vespalib/src/vespa/vespalib/util/sync.h @@ -2,13 +2,11 @@ #pragma once -#include <vespa/fastos/time.h> #include <cassert> #include <mutex> #include <condition_variable> #include <chrono> - namespace vespalib { /** @@ -362,13 +360,12 @@ public: void unlock() { assert(_guard); _guard.unlock(); - _cond = NULL; + _cond = nullptr; } /** * @brief Wait for a signal on the underlying Monitor. **/ void wait() { - assert(_cond != NULL); _cond->wait(_guard); } /** @@ -379,7 +376,6 @@ public: * @return true if a signal was received, false if the wait timed out. **/ bool wait(int msTimeout) { - assert(_cond != NULL); return _cond->wait_for(_guard, std::chrono::milliseconds(msTimeout)) == std::cv_status::no_timeout; } /** @@ -387,14 +383,12 @@ public: * Monitor. **/ void signal() { - assert(_cond != NULL); _cond->notify_one(); } /** * @brief Send a signal to all waiters on the underlying Monitor. **/ void broadcast() { - assert(_cond != NULL); _cond->notify_all(); } /** @@ -406,10 +400,9 @@ public: * will live long enough to be signaled. **/ void unsafeSignalUnlock() { - assert(_cond != NULL); _guard.unlock(); _cond->notify_one(); - _cond = NULL; + _cond = nullptr; } /** * @brief Send a signal to all waiters on the underlying Monitor, @@ -420,10 +413,9 @@ public: * will live long enough to be signaled. **/ void unsafeBroadcastUnlock() { - assert(_cond != NULL); _guard.unlock(); _cond->notify_all(); - _cond = NULL; + _cond = nullptr; } /** * @brief Release the lock held by this object if unlock has not @@ -436,94 +428,7 @@ public: * guard ref as input, ensuring that the caller have grabbed a lock. */ bool monitors(const Monitor& m) const { - return (_cond != NULL && _cond == &m._cond); - } -}; - - -/** - * Helper class that can be used to wait for a condition when having a - * constraint on how long you want to wait. The usage is best - * explained with an example: - * - * <pre> - * bool waitForWantedState(int maxwait) { - * MonitorGuard guard(_monitor); - * TimedWaiter waiter(guard, maxwait); - * while (!wantedState && waiter.hasTime()) { - * waiter.wait(); - * } - * return wantedState; - * } - * </pre> - * - * The example code will limit the total wait time to maxwait - * milliseconds across all blocking wait operations on the underlying - * monitor guard. - **/ -class TimedWaiter -{ -private: - MonitorGuard &_guard; - FastOS_Time _start; - int _maxwait; - int _remain; - bool _timeout; - - TimedWaiter(const TimedWaiter&); - TimedWaiter &operator=(const TimedWaiter&); -public: - - /** - * Create a new instance using the given monitor guard and wait - * time limit. If the maximum time is less than or equal to 0, the - * wait will time out immediately and no low-level wait operations - * will be performed. - * - * @param guard the underlying monitor guard used to perform the actual wait operation. - * @param maxwait maximum time to wait in milliseconds. - **/ - TimedWaiter(MonitorGuard &guard, int maxwait) - : _guard(guard), _start(), _maxwait(maxwait), _remain(0), _timeout(false) - { - if (_maxwait > 0) { - _start.SetNow(); - } else { - _timeout = true; - } - } - - /** - * Check if this object has any time left until the time limit is - * exceeded. - * - * @return true if there is time left. - **/ - bool hasTime() const { - return !_timeout; - } - - /** - * Perform low-level wait in such a way that we do not exceed the - * maximum total wait time. This method also performs the needed - * book-keeping to keep track of elapsed time between invocations. - * - * @return true if we woke up due to a signal, false if we timed out. - **/ - bool wait() { - if (!_timeout) { - if (_remain > 0) { - _remain = (_maxwait - (int)_start.MilliSecsToNow()); - } else { - _remain = _maxwait; - } - if (_remain > 0) { - _timeout = !_guard.wait(_remain); - } else { - _timeout = true; - } - } - return !_timeout; + return (_cond != nullptr && _cond == &m._cond); } }; |