diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2023-03-08 10:51:59 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-08 10:51:59 +0100 |
commit | d752b95e2209221ec8828c5ed380e6388a6fc9c0 (patch) | |
tree | a83f88befe9b9017b8f32c9018f1cfd1b1da05da /vespalib | |
parent | 4de52ed5557f5d16d05e39296a1405223ccd8e54 (diff) | |
parent | 66ae46c80878aab4b0fc19d4c693e1a74cd8977a (diff) |
Merge pull request #26355 from vespa-engine/havardpe/use-ref-counted
use ref_counted for ReplyGate
Diffstat (limited to 'vespalib')
-rw-r--r-- | vespalib/CMakeLists.txt | 1 | ||||
-rw-r--r-- | vespalib/src/tests/referencecounter/.gitignore | 4 | ||||
-rw-r--r-- | vespalib/src/tests/referencecounter/CMakeLists.txt | 8 | ||||
-rw-r--r-- | vespalib/src/tests/referencecounter/referencecounter_test.cpp | 56 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/util/overview.h | 59 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/util/referencecounter.h | 62 |
6 files changed, 0 insertions, 190 deletions
diff --git a/vespalib/CMakeLists.txt b/vespalib/CMakeLists.txt index b689d587bee..dc99146fd3f 100644 --- a/vespalib/CMakeLists.txt +++ b/vespalib/CMakeLists.txt @@ -141,7 +141,6 @@ vespa_define_module( src/tests/programoptions src/tests/random src/tests/ref_counted - src/tests/referencecounter src/tests/regex src/tests/rendezvous src/tests/require diff --git a/vespalib/src/tests/referencecounter/.gitignore b/vespalib/src/tests/referencecounter/.gitignore deleted file mode 100644 index 7c753a29fab..00000000000 --- a/vespalib/src/tests/referencecounter/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -.depend -Makefile -referencecounter_test -vespalib_referencecounter_test_app diff --git a/vespalib/src/tests/referencecounter/CMakeLists.txt b/vespalib/src/tests/referencecounter/CMakeLists.txt deleted file mode 100644 index ee909b48281..00000000000 --- a/vespalib/src/tests/referencecounter/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -vespa_add_executable(vespalib_referencecounter_test_app TEST - SOURCES - referencecounter_test.cpp - DEPENDS - vespalib -) -vespa_add_test(NAME vespalib_referencecounter_test_app COMMAND vespalib_referencecounter_test_app) diff --git a/vespalib/src/tests/referencecounter/referencecounter_test.cpp b/vespalib/src/tests/referencecounter/referencecounter_test.cpp deleted file mode 100644 index 99dd455bcc8..00000000000 --- a/vespalib/src/tests/referencecounter/referencecounter_test.cpp +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/log/log.h> -LOG_SETUP("referencecounter_test"); -#include <vespa/vespalib/testkit/testapp.h> -#include <vespa/vespalib/util/referencecounter.h> - -struct Data -{ - int ctorCnt; - int dtorCnt; - Data() : ctorCnt(0), dtorCnt(0) {} -}; - -class DataRef : public vespalib::ReferenceCounter -{ -private: - Data &_d; - DataRef(const DataRef &); - DataRef &operator=(const DataRef &); -public: - DataRef(Data &d) : _d(d) { ++d.ctorCnt; } - ~DataRef() { ++_d.dtorCnt; } - int getCtorCnt() const { return _d.ctorCnt; } - int getDtorCnt() const { return _d.dtorCnt; } -}; - -using namespace vespalib; - -TEST_SETUP(Test); - -int -Test::Main() -{ - TEST_INIT("referencecounter_test"); - - Data data; - { - DataRef *pt1 = new DataRef(data); - - EXPECT_TRUE(pt1->refCount() == 1); - - DataRef *pt2 = pt1; - pt2->addRef(); - - EXPECT_TRUE(pt1->refCount() == 2); - - EXPECT_TRUE(data.ctorCnt == 1); - EXPECT_TRUE(data.dtorCnt == 0); - pt1->subRef(); - EXPECT_TRUE(pt1->refCount() == 1); - pt2->subRef(); - } - EXPECT_TRUE(data.ctorCnt == 1); - EXPECT_TRUE(data.dtorCnt == 1); - TEST_DONE(); -} diff --git a/vespalib/src/vespa/vespalib/util/overview.h b/vespalib/src/vespa/vespalib/util/overview.h deleted file mode 100644 index 74bf0a33310..00000000000 --- a/vespalib/src/vespa/vespalib/util/overview.h +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -/*! \mainpage Vespalib - C++ utility library for Vespa components - * - * \section intro_sec Introduction - * - * vespalib is a collection of simple utility classes shared - * between most Vespa components that are written in C++. - * Most of these aren't Vespa specific in any way, except that - * they reflect the Vespa code standard and conventions. - * - * \section install_sec Installation - * - * install vespa_vespalib_dev - * - * \section overview_sec Overview - * - * Most of the classes in vespalib can be used by themselves, - * for a full list see the alphabetical class list. - * Here are the major groups of classes: - * - * Generation counter - * - * vespalib::GenCnt - * - * Reference counting - * - * <BR> vespalib::ReferenceCounter - * - * Advanced pointer utilities - * - * \ref vespalib::PtrHolder<T> - * - * Simple hashmap - * - * \ref vespalib::HashMap<T> - * - * Scope guards for easier exception-safety - * - * vespalib::CounterGuard - * <BR> vespalib::DirPointer - * <BR> vespalib::FileDescriptor - * <BR> vespalib::FilePointer - * <BR> \ref vespalib::MaxValueGuard<T> - * <BR> \ref vespalib::ValueGuard<T> - * - * General utility macros - * <BR> \ref VESPA_STRLOC - * <BR> \ref VESPA_STRINGIZE(str) - * - * Standalone testing framework - * - * vespalib::TestApp - * - * Text handling - * - * vespalib::Utf8Reader - * <BR> vespalib::Utf8Writer - * <BR> vespalib::LowerCase - */ diff --git a/vespalib/src/vespa/vespalib/util/referencecounter.h b/vespalib/src/vespa/vespalib/util/referencecounter.h deleted file mode 100644 index 28bc927fe03..00000000000 --- a/vespalib/src/vespa/vespalib/util/referencecounter.h +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -/** - * @file referencecounter.h - * @author Thomas F. Gundersen - * @version $Id$ - * @date 2004-03-19 - **/ - -#pragma once - -#include <atomic> -#include <cassert> - -namespace vespalib -{ - -/** - * @brief Inherit this class to create a self-destroying class. - * - * Allows for objects to be shared without worrying about who "owns" - * the object. When a new owner is given the object, addRef() should - * be called. When finished with the object, subRef() should be - * called. When the last owner calls subRef(), the object is deleted. -*/ -class ReferenceCounter -{ -public: - /** - * @brief Constructor. The object will initially have 1 reference. - **/ - ReferenceCounter() : _refs(1) {} - - /** - * @brief Add an owner of this object. - * - * When the owner is finished with the - * object, call subRef(). - **/ - void addRef() { _refs.fetch_add(1); } - - /** - * @brief Remove an owner of this object. - * - * If that was the last owner, delete the object. - **/ - void subRef() { - if (_refs.fetch_sub(1) == 1) { - delete this; - } - } - unsigned refCount() const { return _refs; } -protected: - /** - * @brief Destructor. Does sanity check only. - **/ - virtual ~ReferenceCounter() { assert (_refs == 0); }; -private: - std::atomic<unsigned> _refs; -}; - -} // namespace vespalib - |