File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33// Distributed under the GPL v3 License, see LICENSE.notice.txt
44
55#include " runtime-common/core/runtime-core.h"
6+ #include " runtime-light/k2-platform/k2-api.h"
67#include " runtime-light/state/instance-state.h"
8+ #include " runtime-light/stdlib/diagnostics/logs.h"
9+
10+ namespace {
711
812constexpr string_size_type initial_minimum_string_buffer_length = 1024 ;
913constexpr string_size_type initial_maximum_string_buffer_length = (1 << 24 );
1014
15+ } // namespace
16+
17+ // FIXME codegen for constants initialization should not access RuntimeContext by mutable reference
1118RuntimeContext& RuntimeContext::get () noexcept {
12- return InstanceState::get ().runtime_context ;
19+ if (auto * instance_state_ptr{k2::instance_state ()}; instance_state_ptr != nullptr ) [[likely]] {
20+ return instance_state_ptr->runtime_context ;
21+ } else if (const auto * component_state_ptr{k2::component_state ()}; component_state_ptr != nullptr ) [[unlikely]] {
22+ kphp::log::error (" unexpected access to RuntimeContext" );
23+ } else if (const auto * image_state_ptr{k2::image_state ()}; image_state_ptr != nullptr ) [[likely]] {
24+ return const_cast <RuntimeContext&>(image_state_ptr->runtime_context );
25+ }
26+ kphp::log::error (" can't find suitable RuntimeContext" );
1327}
1428
1529void RuntimeContext::init () noexcept {
Original file line number Diff line number Diff line change 2828
2929struct ImageState final : private vk::not_copyable {
3030 AllocatorState image_allocator_state{INIT_IMAGE_ALLOCATOR_SIZE, 0 };
31+ RuntimeContext runtime_context;
3132
3233 uint32_t pid{k2::getpid ()};
3334 uid_t uid{k2::getuid ()};
@@ -48,6 +49,8 @@ struct ImageState final : private vk::not_copyable {
4849 RpcImageState rpc_image_state;
4950
5051 ImageState () noexcept {
52+ runtime_context.init ();
53+
5154 if (const int64_t sysconf_max_buffer_size{k2::sysconf (_SC_GETPW_R_SIZE_MAX)}; sysconf_max_buffer_size != -1 ) {
5255 passwd_max_buffer_size.emplace (sysconf_max_buffer_size);
5356 }
Original file line number Diff line number Diff line change @@ -58,7 +58,6 @@ consteval std::string_view resolve_sapi_name() noexcept {
5858// === initialization =============================================================================
5959
6060void InstanceState::init_script_execution () noexcept {
61- runtime_context.init ();
6261 kphp::coro::task<> script_task;
6362 init_php_scripts_in_each_worker (php_script_mutable_globals_singleton, script_task);
6463
Original file line number Diff line number Diff line change @@ -67,6 +67,7 @@ struct InstanceState final : vk::not_copyable {
6767 // In the second case clang++ zeroes the whole structure.
6868 // It drastically ruins performance. Be careful!
6969 InstanceState () noexcept {
70+ runtime_context.init ();
7071 kml_instance_state.init (ComponentState::get ().kml_component_state .max_buffer_size ());
7172 }
7273
@@ -89,16 +90,17 @@ struct InstanceState final : vk::not_copyable {
8990 }
9091
9192 AllocatorState instance_allocator_state{INIT_INSTANCE_ALLOCATOR_SIZE, 0 };
92- kphp::log::contextual_logger instance_logger ;
93+ RuntimeContext runtime_context ;
9394
95+ kphp::log::contextual_logger instance_logger;
9496 kphp::coro::io_scheduler io_scheduler;
97+
9598 CoroutineInstanceState coroutine_instance_state;
9699 ForkInstanceState fork_instance_state;
97100 WaitQueueInstanceState wait_queue_instance_state;
98101 RpcQueueInstanceState rpc_queue_instance_state;
99102 PhpScriptMutableGlobals php_script_mutable_globals_singleton;
100103
101- RuntimeContext runtime_context;
102104 CLIInstanceInstance cli_instance_instate;
103105 OutputInstanceState output_instance_state;
104106 RpcClientInstanceState rpc_client_instance_state;
Original file line number Diff line number Diff line change 1- @ok k2_skip
1+ @ok
22<?php
33
44var_dump (min ([1 ]));
You can’t perform that action at this time.
0 commit comments