Skip to content

Commit 5dd0ea9

Browse files
committed
Return libc_alloc_guard back to runtime-light
1 parent f8c88f6 commit 5dd0ea9

File tree

7 files changed

+22
-46
lines changed

7 files changed

+22
-46
lines changed

runtime-common/core/allocator/platform-malloc-interface.h

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,8 @@
1313
#include "runtime-common/core/allocator/runtime-allocator.h"
1414
#include "runtime-common/core/utils/kphp-assert-core.h"
1515

16-
namespace kphp::memory {
16+
namespace kphp::memory::platform {
1717

18-
struct libc_alloc_guard final {
19-
libc_alloc_guard() noexcept;
20-
// AllocatorState::get_mutable().enable_libc_alloc();
21-
22-
~libc_alloc_guard();
23-
// AllocatorState::get_mutable().disable_libc_alloc();
24-
25-
libc_alloc_guard(const libc_alloc_guard&) = delete;
26-
libc_alloc_guard(libc_alloc_guard&&) = delete;
27-
libc_alloc_guard& operator=(const libc_alloc_guard&) = delete;
28-
libc_alloc_guard& operator=(libc_alloc_guard&&) = delete;
29-
};
30-
31-
namespace platform {
3218
constexpr int64_t MALLOC_REPLACER_SIZE_OFFSET = sizeof(size_t);
3319
constexpr uint64_t MALLOC_REPLACER_MAX_ALLOC = 0xFFFFFF00;
3420

@@ -83,6 +69,4 @@ inline void* realloc(void* ptr, size_t new_size) noexcept {
8369
}
8470
return new_ptr;
8571
}
86-
} // namespace platform
87-
88-
} // namespace kphp::memory
72+
} // namespace kphp::memory::platform

runtime-common/stdlib/kml/kphp_ml_interface.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ Optional<string> f$kml_get_custom_property(const string& model_name, const strin
162162
return {};
163163
}
164164

165-
auto guard = kphp::memory::libc_alloc_guard{};
166165
auto inner_result = p_kml->get_custom_property(kphp_ml::stl::string(property_name.c_str()));
167166

168167
if (!inner_result.has_value()) {

runtime-light/allocator/allocator.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,27 @@
88
#include <cstddef>
99

1010
#include "runtime-common/core/allocator/script-allocator-managed.h"
11+
#include "runtime-light/allocator/allocator-state.h"
1112

1213
template<std::derived_from<ScriptAllocatorManaged> T, typename... Args>
1314
requires std::constructible_from<T, Args...>
1415
auto make_unique_on_script_memory(Args&&... args) noexcept {
1516
return std::make_unique<T>(std::forward<Args>(args)...);
1617
}
18+
19+
namespace kphp::memory {
20+
struct libc_alloc_guard final {
21+
libc_alloc_guard() noexcept {
22+
AllocatorState::get_mutable().enable_libc_alloc();
23+
}
24+
25+
~libc_alloc_guard() {
26+
AllocatorState::get_mutable().disable_libc_alloc();
27+
}
28+
29+
libc_alloc_guard(const libc_alloc_guard&) = delete;
30+
libc_alloc_guard(libc_alloc_guard&&) = delete;
31+
libc_alloc_guard& operator=(const libc_alloc_guard&) = delete;
32+
libc_alloc_guard& operator=(libc_alloc_guard&&) = delete;
33+
};
34+
} // namespace kphp::memory

runtime-light/allocator/runtime-light-allocator.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <cstddef>
77
#include <cstring>
88

9-
#include "runtime-common/core/allocator/platform-malloc-interface.h"
9+
#include "runtime-light/allocator/allocator.h"
1010
#include "runtime-light/allocator/allocator-state.h"
1111
#include "runtime-light/k2-platform/k2-api.h"
1212
#include "runtime-light/stdlib/diagnostics/logs.h"
@@ -114,15 +114,3 @@ void* RuntimeAllocator::realloc_global_memory(void* old_mem, size_t new_size, si
114114
void RuntimeAllocator::free_global_memory(void* mem, size_t /*unused*/) noexcept {
115115
k2::free(mem);
116116
}
117-
118-
namespace kphp::memory {
119-
120-
libc_alloc_guard::libc_alloc_guard() noexcept {
121-
AllocatorState::get_mutable().enable_libc_alloc();
122-
}
123-
124-
libc_alloc_guard::~libc_alloc_guard() {
125-
AllocatorState::get_mutable().disable_libc_alloc();
126-
}
127-
128-
} // namespace kphp::memory

runtime-light/state/component-state.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@
1010
#include <string_view>
1111

1212
#include "common/mixin/not_copyable.h"
13-
#include "runtime-common/core/allocator/platform-malloc-interface.h"
1413
#include "runtime-common/core/runtime-core.h"
1514
#include "runtime-common/stdlib/kml/kphp_ml_init.h"
1615
#include "runtime-light/allocator/allocator-state.h"
17-
#include "runtime-light/allocator/allocator.h"
1816
#include "runtime-light/k2-platform/k2-api.h"
1917
#include "runtime-light/stdlib/kml/kml-component-state.h"
2018

@@ -37,7 +35,6 @@ struct ComponentState final : private vk::not_copyable {
3735
strncpy(buffer, kml_dir.c_str(), kml_dir.size() + 1); // Copy null terminator, too
3836
kml_component_state.kml_models_context.kml_directory = buffer;
3937

40-
kphp::memory::libc_alloc_guard guard;
4138
kml_init_models();
4239
}
4340

runtime-light/stdlib/time/timelib-timezone-cache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
#include "kphp/timelib/timelib.h"
1515

16-
#include "runtime-common/core/allocator/platform-malloc-interface.h"
16+
#include "runtime-light/allocator/allocator.h"
1717
#include "runtime-common/core/allocator/script-allocator.h"
1818
#include "runtime-common/core/std/containers.h"
1919
#include "runtime-light/stdlib/diagnostics/logs.h"

runtime/critical_section.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,3 @@ void init_critical_section() noexcept {
4444
}
4545

4646
} // namespace dl
47-
48-
namespace kphp::memory {
49-
libc_alloc_guard::libc_alloc_guard() noexcept {
50-
dl::enter_critical_section();
51-
}
52-
53-
libc_alloc_guard::~libc_alloc_guard() {
54-
dl::leave_critical_section();
55-
}
56-
} // namespace kphp::memory

0 commit comments

Comments
 (0)