aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/util/mmap_file_allocator_factory.h
blob: ed97ee5c2d29b2db5fa8ef640cf42c6ed331579e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <vespa/vespalib/stllike/string.h>
#include <memory>
#include <atomic>

namespace vespalib::alloc {

class MemoryAllocator;

/*
 * Class for creating an mmap file allocator on demand.
 */
class MmapFileAllocatorFactory {
    vespalib::string _dir_name;
    std::atomic<uint64_t> _generation;

    MmapFileAllocatorFactory();
    ~MmapFileAllocatorFactory();
    MmapFileAllocatorFactory(const MmapFileAllocatorFactory &) = delete;
    MmapFileAllocatorFactory& operator=(const MmapFileAllocatorFactory &) = delete;
public:
    void setup(const vespalib::string &dir_name);
    std::unique_ptr<MemoryAllocator> make_memory_allocator(const vespalib::string& name);

    static MmapFileAllocatorFactory& instance();
};

}