https://git.reactos.org/?p=reactos.git;a=commitdiff;h=e2ffc35894f760c7d0718…
commit e2ffc35894f760c7d0718cdf6ddfc910ac683b81
Author:     Timo Kreuzer <timo.kreuzer(a)reactos.org>
AuthorDate: Sun Oct 27 11:42:27 2024 +0200
Commit:     Timo Kreuzer <timo.kreuzer(a)reactos.org>
CommitDate: Wed Jan 22 18:56:08 2025 +0200
    [UCRT] Fix/improve __crt_state_management
---
 .../ucrt/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 <typename T>
         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<typename T2> void uninitialize(T2) throw() { }
-            template<typename T2, size_t N> 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<typename T2>
+            void uninitialize(T2 Lambda) throw()
+            {
+                Lambda(_value[0]);
+            }
+
+            template<typename T2>
+            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;
         }