]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/port/win/win_jemalloc.cc
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / rocksdb / port / win / win_jemalloc.cc
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under the BSD-style license found in the
3 // LICENSE file in the root directory of this source tree. An additional grant
4 // of patent rights can be found in the PATENTS file in the same directory.
5 //
6 // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
7 // Use of this source code is governed by a BSD-style license that can be
8 // found in the LICENSE file. See the AUTHORS file for names of contributors.
9
10 #ifndef ROCKSDB_JEMALLOC
11 # error This file can only be part of jemalloc aware build
12 #endif
13
14 #include <stdexcept>
15 #include "jemalloc/jemalloc.h"
16 #include "port/win/port_win.h"
17
18 #if defined(ZSTD) && defined(ZSTD_STATIC_LINKING_ONLY)
19 #include <zstd.h>
20 #if (ZSTD_VERSION_NUMBER >= 500)
21 namespace rocksdb {
22 namespace port {
23 void* JemallocAllocateForZSTD(void* /* opaque */, size_t size) {
24 return je_malloc(size);
25 }
26 void JemallocDeallocateForZSTD(void* /* opaque */, void* address) {
27 je_free(address);
28 }
29 ZSTD_customMem GetJeZstdAllocationOverrides() {
30 return {JemallocAllocateForZSTD, JemallocDeallocateForZSTD, nullptr};
31 }
32 } // namespace port
33 } // namespace rocksdb
34 #endif // (ZSTD_VERSION_NUMBER >= 500)
35 #endif // defined(ZSTD) defined(ZSTD_STATIC_LINKING_ONLY)
36
37 // Global operators to be replaced by a linker when this file is
38 // a part of the build
39
40 namespace rocksdb {
41 namespace port {
42 void* jemalloc_aligned_alloc(size_t size, size_t alignment) ROCKSDB_NOEXCEPT {
43 return je_aligned_alloc(alignment, size);
44 }
45 void jemalloc_aligned_free(void* p) ROCKSDB_NOEXCEPT { je_free(p); }
46 } // namespace port
47 } // namespace rocksdb
48
49 void* operator new(size_t size) {
50 void* p = je_malloc(size);
51 if (!p) {
52 throw std::bad_alloc();
53 }
54 return p;
55 }
56
57 void* operator new[](size_t size) {
58 void* p = je_malloc(size);
59 if (!p) {
60 throw std::bad_alloc();
61 }
62 return p;
63 }
64
65 void operator delete(void* p) {
66 if (p) {
67 je_free(p);
68 }
69 }
70
71 void operator delete[](void* p) {
72 if (p) {
73 je_free(p);
74 }
75 }