From e2ffc35894f760c7d0718cdf6ddfc910ac683b81 Mon Sep 17 00:00:00 2001 From: Timo Kreuzer Date: Sun, 27 Oct 2024 11:42:27 +0200 Subject: [PATCH] [UCRT] Fix/improve __crt_state_management --- .../inc/corecrt_internal_state_isolation.h | 59 +++++++++++++++---- 1 file changed, 49 insertions(+), 10 deletions(-) diff --git a/sdk/lib/ucrt/inc/corecrt_internal_state_isolation.h b/sdk/lib/ucrt/inc/corecrt_internal_state_isolation.h index 341de26f6ff..47477fc3f57 100644 --- a/sdk/lib/ucrt/inc/corecrt_internal_state_isolation.h +++ b/sdk/lib/ucrt/inc/corecrt_internal_state_isolation.h @@ -15,33 +15,72 @@ extern "C++" { namespace __crt_state_management { +#ifdef _CRT_GLOBAL_STATE_ISOLATION +#error FIXME: Global state isolation is not implemented yet constexpr size_t state_index_count = 2; +#else + constexpr size_t state_index_count = 1; +#endif + struct scoped_global_state_reset { scoped_global_state_reset() throw() { } ~scoped_global_state_reset() throw() { } - }; // FIXME: Implement this + }; + template class dual_state_global { - T _value[2]; + T _value[state_index_count]; + public: + + // Implemented in corecrt_internal_ptd_propagation.h T& value(__crt_cached_ptd_host& ptd) throw(); T const& value(__crt_cached_ptd_host& ptd) const throw(); - T& value(void) throw() { return _value[0]; } - T value_explicit(size_t index) throw() { return _value[index]; } - T* dangerous_get_state_array() throw() { return _value; } - void initialize(T) throw() { } - template void uninitialize(T2) throw() { } - template void initialize_from_array(T2 const (&values)[N]) throw() { } + + T& value(void) throw() + { + return _value[0]; + } + + T value_explicit(size_t index) throw() + { + return _value[index]; + } + + T* dangerous_get_state_array() throw() + { + return _value; + } + + void initialize(T x) throw() + { + _value[0] = x; + } + + template + void uninitialize(T2 Lambda) throw() + { + Lambda(_value[0]); + } + + template + void initialize_from_array(T2 (&values)[state_index_count]) throw() + { + for (size_t i = 0; i < state_index_count; i++) + { + _value[i] = values[i]; + } + } }; - inline int get_current_state_index(__crt_scoped_get_last_error_reset const &last_error_reset) + inline size_t get_current_state_index(__crt_scoped_get_last_error_reset const &last_error_reset) { return 0; } - inline int get_current_state_index(void) + inline size_t get_current_state_index(void) { return 0; }