diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2021-01-19 10:10:18 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2021-01-19 10:10:18 +0000 |
commit | 672d983232714b980d7366be67df52c83de9c631 (patch) | |
tree | 4166122a72b6d42991c325325bc20c56f62e8e8e /vespalib | |
parent | 677a35028b3aac1b6b7232b470d1fdf2df772a52 (diff) |
Move general purpose destructor callbacks to vespalib.
Diffstat (limited to 'vespalib')
-rw-r--r-- | vespalib/src/vespa/vespalib/util/CMakeLists.txt | 1 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/util/destructor_callbacks.cpp | 12 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/util/destructor_callbacks.h | 32 |
3 files changed, 45 insertions, 0 deletions
diff --git a/vespalib/src/vespa/vespalib/util/CMakeLists.txt b/vespalib/src/vespa/vespalib/util/CMakeLists.txt index 5a82fb200e0..22fbe0a95f6 100644 --- a/vespalib/src/vespa/vespalib/util/CMakeLists.txt +++ b/vespalib/src/vespa/vespalib/util/CMakeLists.txt @@ -17,6 +17,7 @@ vespa_add_library(vespalib_vespalib_util OBJECT closuretask.cpp compress.cpp compressor.cpp + destructor_callbacks.cpp dual_merge_director.cpp error.cpp exception.cpp diff --git a/vespalib/src/vespa/vespalib/util/destructor_callbacks.cpp b/vespalib/src/vespa/vespalib/util/destructor_callbacks.cpp new file mode 100644 index 00000000000..edb8381e64d --- /dev/null +++ b/vespalib/src/vespa/vespalib/util/destructor_callbacks.cpp @@ -0,0 +1,12 @@ +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include "destructor_callbacks.h" +#include "gate.h" + +namespace vespalib { + +GateCallback::~GateCallback() { + _gate.countDown(); +} + +} diff --git a/vespalib/src/vespa/vespalib/util/destructor_callbacks.h b/vespalib/src/vespa/vespalib/util/destructor_callbacks.h new file mode 100644 index 00000000000..fc0d23fa177 --- /dev/null +++ b/vespalib/src/vespa/vespalib/util/destructor_callbacks.h @@ -0,0 +1,32 @@ +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include "idestructorcallback.h" + +namespace vespalib { + +class Gate; + +class GateCallback : public vespalib::IDestructorCallback { +public: + GateCallback(vespalib::Gate & gate) noexcept : _gate(gate) {} + ~GateCallback() override; +private: + vespalib::Gate & _gate; +}; + +class IgnoreCallback : public vespalib::IDestructorCallback { +public: + IgnoreCallback() noexcept { } + ~IgnoreCallback() override = default; +}; + +template <typename T> +struct KeepAlive : public vespalib::IDestructorCallback { + explicit KeepAlive(T toKeep) noexcept : _toKeep(std::move(toKeep)) { } + ~KeepAlive() override = default; + T _toKeep; +}; + +} |