diff options
author | Tor Egge <Tor.Egge@broadpark.no> | 2021-02-13 20:29:22 +0100 |
---|---|---|
committer | Tor Egge <Tor.Egge@broadpark.no> | 2021-02-13 20:29:22 +0100 |
commit | b316d0bcdcd345829cb4f13bf0b2d910c48f82d5 (patch) | |
tree | 78a5fd2a8a9e4ae6c8ffc6c303af96d94559fdd1 | |
parent | 78f05fdddffb06745c38e1e020fa0c879536bd3e (diff) |
Forward declare MemoryAllocator in vespalib/util/alloc.h.
13 files changed, 54 insertions, 22 deletions
diff --git a/searchcore/src/apps/vespa-gen-testdocs/vespa-gen-testdocs.cpp b/searchcore/src/apps/vespa-gen-testdocs/vespa-gen-testdocs.cpp index c2b0735ff8f..321f9345791 100644 --- a/searchcore/src/apps/vespa-gen-testdocs/vespa-gen-testdocs.cpp +++ b/searchcore/src/apps/vespa-gen-testdocs/vespa-gen-testdocs.cpp @@ -4,6 +4,7 @@ #include <vespa/vespalib/stllike/string.h> #include <vespa/vespalib/stllike/hash_set.h> #include <vespa/vespalib/stllike/asciistream.h> +#include <vespa/vespalib/util/memory_allocator.h> #include <vespa/fastlib/io/bufferedfile.h> #include <vespa/fastos/app.h> #include <iostream> diff --git a/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp b/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp index 9a19a795076..8ba4232a5c6 100644 --- a/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp +++ b/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp @@ -14,6 +14,7 @@ #include <vespa/vespalib/stllike/asciistream.h> #include <vespa/vespalib/test/insertion_operators.h> #include <vespa/vespalib/util/exceptions.h> +#include <vespa/vespalib/util/memory_allocator.h> #include <vespa/vespalib/util/threadstackexecutor.h> #include <iomanip> diff --git a/searchlib/src/vespa/searchlib/attribute/multivalueattribute.hpp b/searchlib/src/vespa/searchlib/attribute/multivalueattribute.hpp index 1def5dab060..0cd2e0bbc27 100644 --- a/searchlib/src/vespa/searchlib/attribute/multivalueattribute.hpp +++ b/searchlib/src/vespa/searchlib/attribute/multivalueattribute.hpp @@ -5,6 +5,7 @@ #include <vespa/searchlib/attribute/multivalueattribute.h> #include <vespa/vespalib/stllike/hash_map.h> #include <vespa/vespalib/stllike/hash_map.hpp> +#include <vespa/vespalib/util/memory_allocator.h> namespace search { diff --git a/searchlib/src/vespa/searchlib/docstore/visitcache.cpp b/searchlib/src/vespa/searchlib/docstore/visitcache.cpp index 1671b6cae69..0e3294d45e5 100644 --- a/searchlib/src/vespa/searchlib/docstore/visitcache.cpp +++ b/searchlib/src/vespa/searchlib/docstore/visitcache.cpp @@ -6,6 +6,7 @@ #include <vespa/vespalib/stllike/hash_map.hpp> #include <vespa/vespalib/data/databuffer.h> #include <vespa/vespalib/util/compressor.h> +#include <vespa/vespalib/util/memory_allocator.h> #include <algorithm> namespace search::docstore { diff --git a/searchlib/src/vespa/searchlib/queryeval/predicate_blueprint.cpp b/searchlib/src/vespa/searchlib/queryeval/predicate_blueprint.cpp index 97e7044ec0f..66acc2f0836 100644 --- a/searchlib/src/vespa/searchlib/queryeval/predicate_blueprint.cpp +++ b/searchlib/src/vespa/searchlib/queryeval/predicate_blueprint.cpp @@ -13,6 +13,7 @@ #include <vespa/vespalib/btree/btreeiterator.hpp> #include <vespa/vespalib/btree/btreestore.hpp> #include <vespa/vespalib/btree/btreenodeallocator.hpp> +#include <vespa/vespalib/util/memory_allocator.h> #include <algorithm> #include <vespa/log/log.h> LOG_SETUP(".searchlib.predicate.predicate_blueprint"); diff --git a/searchlib/src/vespa/searchlib/tensor/hnsw_index.cpp b/searchlib/src/vespa/searchlib/tensor/hnsw_index.cpp index 44b2ff2b7f1..4ad998421ca 100644 --- a/searchlib/src/vespa/searchlib/tensor/hnsw_index.cpp +++ b/searchlib/src/vespa/searchlib/tensor/hnsw_index.cpp @@ -9,6 +9,7 @@ #include <vespa/vespalib/data/slime/cursor.h> #include <vespa/vespalib/data/slime/inserter.h> #include <vespa/vespalib/datastore/array_store.hpp> +#include <vespa/vespalib/util/memory_allocator.h> #include <vespa/vespalib/util/rcuvector.hpp> #include <vespa/log/log.h> diff --git a/searchlib/src/vespa/searchlib/util/comprbuffer.cpp b/searchlib/src/vespa/searchlib/util/comprbuffer.cpp index cc969695061..35c4abafca4 100644 --- a/searchlib/src/vespa/searchlib/util/comprbuffer.cpp +++ b/searchlib/src/vespa/searchlib/util/comprbuffer.cpp @@ -2,6 +2,7 @@ #include "comprbuffer.h" #include <vespa/fastos/file.h> +#include <vespa/vespalib/util/memory_allocator.h> #include <cassert> #include <cstring> diff --git a/storage/src/vespa/storage/bucketdb/btree_bucket_database.cpp b/storage/src/vespa/storage/bucketdb/btree_bucket_database.cpp index c8d8acd629a..8b38cd61cf6 100644 --- a/storage/src/vespa/storage/bucketdb/btree_bucket_database.cpp +++ b/storage/src/vespa/storage/bucketdb/btree_bucket_database.cpp @@ -4,6 +4,7 @@ #include "generic_btree_bucket_database.hpp" #include <vespa/vespalib/datastore/array_store.hpp> #include <vespa/vespalib/datastore/buffer_type.hpp> +#include <vespa/vespalib/util/memory_allocator.h> #include <iostream> /* diff --git a/vespalib/src/tests/datastore/array_store/array_store_test.cpp b/vespalib/src/tests/datastore/array_store/array_store_test.cpp index 168a4685ba1..72f803b441b 100644 --- a/vespalib/src/tests/datastore/array_store/array_store_test.cpp +++ b/vespalib/src/tests/datastore/array_store/array_store_test.cpp @@ -6,6 +6,7 @@ #include <vespa/vespalib/stllike/hash_map.hpp> #include <vespa/vespalib/testkit/testapp.h> #include <vespa/vespalib/test/insertion_operators.h> +#include <vespa/vespalib/util/memory_allocator.h> #include <vespa/vespalib/util/traits.h> #include <vector> diff --git a/vespalib/src/vespa/vespalib/datastore/bufferstate.cpp b/vespalib/src/vespa/vespalib/datastore/bufferstate.cpp index 76e706435cf..d3a5402d7b0 100644 --- a/vespalib/src/vespa/vespalib/datastore/bufferstate.cpp +++ b/vespalib/src/vespa/vespalib/datastore/bufferstate.cpp @@ -1,6 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "bufferstate.h" +#include <vespa/vespalib/util/memory_allocator.h> #include <limits> #include <cassert> diff --git a/vespalib/src/vespa/vespalib/stllike/allocator.h b/vespalib/src/vespa/vespalib/stllike/allocator.h index efe885f5c96..0a890973e09 100644 --- a/vespalib/src/vespa/vespalib/stllike/allocator.h +++ b/vespalib/src/vespa/vespalib/stllike/allocator.h @@ -2,7 +2,7 @@ #pragma once -#include <vespa/vespalib/util/alloc.h> +#include <vespa/vespalib/util/memory_allocator.h> namespace vespalib { diff --git a/vespalib/src/vespa/vespalib/util/alloc.cpp b/vespalib/src/vespa/vespalib/util/alloc.cpp index 5271a6ca779..511593ba1d6 100644 --- a/vespalib/src/vespa/vespalib/util/alloc.cpp +++ b/vespalib/src/vespa/vespalib/util/alloc.cpp @@ -1,5 +1,6 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "alloc.h" +#include "memory_allocator.h" #include "round_up_to_page_size.h" #include <sys/mman.h> #include <vespa/vespalib/util/stringfmt.h> @@ -465,6 +466,34 @@ MemoryAllocator::select_allocator(size_t mmapLimit, size_t alignment) { return & AutoAllocator::getAllocator(mmapLimit, alignment); } +Alloc::Alloc(const MemoryAllocator * allocator, size_t sz) noexcept + : _alloc(allocator->alloc(sz)), + _allocator(allocator) +{ +} + +Alloc::~Alloc() +{ + if (_alloc.first != nullptr) { + _allocator->free(_alloc); + _alloc.first = nullptr; + } +} + +Alloc& +Alloc::operator=(Alloc && rhs) noexcept +{ + if (this != & rhs) { + if (_alloc.first != nullptr) { + _allocator->free(_alloc); + } + _alloc = rhs._alloc; + _allocator = rhs._allocator; + rhs.clear(); + } + return *this; +} + Alloc Alloc::allocHeap(size_t sz) { @@ -511,6 +540,12 @@ Alloc::alloc() noexcept } Alloc +Alloc::alloc(size_t sz) noexcept +{ + return Alloc(&AutoAllocator::getDefault(), sz); +} + +Alloc Alloc::alloc(size_t sz, size_t mmapLimit, size_t alignment) noexcept { return Alloc(&AutoAllocator::getAllocator(mmapLimit, alignment), sz); diff --git a/vespalib/src/vespa/vespalib/util/alloc.h b/vespalib/src/vespa/vespalib/util/alloc.h index 5d53334d8f6..5e71180f9be 100644 --- a/vespalib/src/vespa/vespalib/util/alloc.h +++ b/vespalib/src/vespa/vespalib/util/alloc.h @@ -1,12 +1,13 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once -#include "memory_allocator.h" #include <vespa/vespalib/util/optimized.h> #include <memory> namespace vespalib::alloc { +class MemoryAllocator; + /** * This represents an allocation. * It can be created, moved, swapped. @@ -16,7 +17,7 @@ namespace vespalib::alloc { class Alloc { private: - using PtrAndSize = MemoryAllocator::PtrAndSize; + using PtrAndSize = std::pair<void *, size_t>; public: size_t size() const { return _alloc.second; } void * get() { return _alloc.first; } @@ -40,24 +41,9 @@ public: { rhs.clear(); } - Alloc & operator=(Alloc && rhs) noexcept { - if (this != & rhs) { - if (_alloc.first != nullptr) { - _allocator->free(_alloc); - } - _alloc = rhs._alloc; - _allocator = rhs._allocator; - rhs.clear(); - } - return *this; - } + Alloc & operator=(Alloc && rhs) noexcept; Alloc() noexcept : _alloc(nullptr, 0), _allocator(nullptr) { } - ~Alloc() { - if (_alloc.first != nullptr) { - _allocator->free(_alloc); - _alloc.first = nullptr; - } - } + ~Alloc(); void swap(Alloc & rhs) noexcept { std::swap(_alloc, rhs._alloc); std::swap(_allocator, rhs._allocator); @@ -73,11 +59,12 @@ public: * Optional alignment is assumed to be <= system page size, since mmap * is always used when size is above limit. */ - static Alloc alloc(size_t sz, size_t mmapLimit = MemoryAllocator::HUGEPAGE_SIZE, size_t alignment=0) noexcept; + static Alloc alloc(size_t sz) noexcept; + static Alloc alloc(size_t sz, size_t mmapLimit, size_t alignment=0) noexcept; static Alloc alloc() noexcept; static Alloc alloc_with_allocator(const MemoryAllocator* allocator) noexcept; private: - Alloc(const MemoryAllocator * allocator, size_t sz) noexcept : _alloc(allocator->alloc(sz)), _allocator(allocator) { } + Alloc(const MemoryAllocator * allocator, size_t sz) noexcept; Alloc(const MemoryAllocator * allocator) noexcept : _alloc(nullptr, 0), _allocator(allocator) { } void clear() { _alloc.first = nullptr; |