diff options
author | Tor Egge <Tor.Egge@broadpark.no> | 2017-10-27 01:57:52 +0200 |
---|---|---|
committer | Tor Egge <Tor.Egge@oath.com> | 2017-10-27 08:50:17 +0000 |
commit | 2bf0eaac4188d9e6b0efc72599297b68f6e80486 (patch) | |
tree | 8026a53c1a980a4a758446ebd609473ab00556a8 /documentapi | |
parent | c1a847ff3e9cf48187131079c736e660474fe7d2 (diff) |
Reduce use of FastOS_Mutex and FastOS_Cond.
Remove handover tricks, use move constructor and move assignment instead.
Diffstat (limited to 'documentapi')
3 files changed, 20 insertions, 51 deletions
diff --git a/documentapi/src/tests/systemstate/systemstate.cpp b/documentapi/src/tests/systemstate/systemstate.cpp index 7aadf82aeed..3e42c94950a 100644 --- a/documentapi/src/tests/systemstate/systemstate.cpp +++ b/documentapi/src/tests/systemstate/systemstate.cpp @@ -174,7 +174,7 @@ Test::testHandle() SystemStateHandle handle(*state); ASSERT_TRUE(handle.isValid()); - SystemStateHandle hoe(handle); + SystemStateHandle hoe(std::move(handle)); ASSERT_TRUE(!handle.isValid()); ASSERT_TRUE(hoe.isValid()); } diff --git a/documentapi/src/vespa/documentapi/messagebus/systemstate/systemstatehandle.cpp b/documentapi/src/vespa/documentapi/messagebus/systemstate/systemstatehandle.cpp index ad2f4485ac8..9ccaece4511 100644 --- a/documentapi/src/vespa/documentapi/messagebus/systemstate/systemstatehandle.cpp +++ b/documentapi/src/vespa/documentapi/messagebus/systemstate/systemstatehandle.cpp @@ -4,34 +4,28 @@ using namespace documentapi; -SystemStateHandover::SystemStateHandover(SystemState *state, vespalib::LockGuard &guard) : - _state(state), - _guard(guard) -{} - SystemStateHandle::SystemStateHandle(SystemState &state) : _state(&state), _guard(*state._lock) {} -SystemStateHandle::SystemStateHandle(SystemStateHandle &rhs) : +SystemStateHandle::SystemStateHandle(SystemStateHandle &&rhs) : _state(rhs._state), - _guard(rhs._guard) + _guard(std::move(rhs._guard)) { rhs._state = nullptr; } -SystemStateHandle::SystemStateHandle(const SystemStateHandover &rhs) : - _state(rhs._state), - _guard(rhs._guard) -{} +SystemStateHandle & +SystemStateHandle::operator=(SystemStateHandle &&rhs) +{ + if (this != &rhs) { + _state = rhs._state; + _guard = std::move(rhs._guard); + rhs._state = nullptr; + } + return *this; +} SystemStateHandle::~SystemStateHandle() {} -SystemStateHandle::operator -SystemStateHandover() { - SystemStateHandover ret(_state, _guard); - _state = nullptr; - return ret; -} - diff --git a/documentapi/src/vespa/documentapi/messagebus/systemstate/systemstatehandle.h b/documentapi/src/vespa/documentapi/messagebus/systemstate/systemstatehandle.h index aa87e1ee0ab..f0342cfb2de 100644 --- a/documentapi/src/vespa/documentapi/messagebus/systemstate/systemstatehandle.h +++ b/documentapi/src/vespa/documentapi/messagebus/systemstate/systemstatehandle.h @@ -7,31 +7,15 @@ namespace documentapi { /** - * Implements a handover class to enable the system state handler to be perform handover even on const objects - * such as occur when returning a handle by value from a function. - */ -class SystemStateHandover { - friend class SystemStateHandle; -private: - SystemStateHandover(const SystemStateHandover &); - SystemStateHandover &operator=(const SystemStateHandover &); - SystemStateHandover(SystemState *state, vespalib::LockGuard &guard); - -private: - SystemState *_state; - mutable vespalib::LockGuard _guard; -}; - -/** - * Implements a handle to grant synchronized access to the content of a system state object. This needs the - * above handover class to be able to return itself from methods that create it. + * Implements a handle to grant synchronized access to the content of a system state object. */ class SystemStateHandle { private: SystemState *_state; // The associated system state for which this object is a handler. vespalib::LockGuard _guard; // The lock guard for the system state's lock. - SystemState &operator=(const SystemStateHandle &rhs); // hide + SystemStateHandle &operator=(const SystemStateHandle &) = delete; + SystemStateHandle(const SystemStateHandle &) = delete; public: /** @@ -42,28 +26,19 @@ public: SystemStateHandle(SystemState &state); /** - * Implements the copy constructor. - * - * @param rhs The handle to copy to this. - */ - SystemStateHandle(SystemStateHandle &rhs); - - /** - * Implements the copy constructor for a const handle. + * Implements the move constructor. * - * @param rhs The handle to copy to this. + * @param rhs The handle to move to this. */ - SystemStateHandle(const SystemStateHandover &rhs); + SystemStateHandle(SystemStateHandle &&rhs); + SystemStateHandle &operator=(SystemStateHandle &&rhs); /** * Destructor. Releases the contained lock on the associated system state object. There is no unlock() * mechanism provided, since this will happen automatically as soon as this handle goes out of scope. */ ~SystemStateHandle(); - /** Implements a cast-operator for handover. */ - operator SystemStateHandover(); - /** Returns whether or not this handle is valid. */ bool isValid() const { return _state != NULL; } |