summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorthegeorg <[email protected]>2022-06-24 12:22:44 +0300
committerthegeorg <[email protected]>2022-06-24 12:22:44 +0300
commitece86e83e77dcf3d9e757517d3d16f707272a4c7 (patch)
tree6366c9b5116ff7606a9706074bf4a7db0c17279c
parenta4c1572074a6f4eb937168c283a61c43468d8650 (diff)
Allow creating Singlelon during Singleton destruction back again
ref:53c837a1fa0289db60812b95b6ac96be23ae018d
-rw-r--r--util/system/atexit.cpp3
-rw-r--r--util/system/atexit_ut.cpp19
2 files changed, 21 insertions, 1 deletions
diff --git a/util/system/atexit.cpp b/util/system/atexit.cpp
index 5ae7a21e233..7fafad95a6a 100644
--- a/util/system/atexit.cpp
+++ b/util/system/atexit.cpp
@@ -81,9 +81,10 @@ namespace {
alignas(TAtExit) static char atExitMem[sizeof(TAtExit)];
static void OnExit() {
- if (TAtExit* const atExit = atExitPtr.exchange(nullptr)) {
+ if (TAtExit* const atExit = atExitPtr.load()) {
atExit->Finish();
atExit->~TAtExit();
+ atExitPtr.store(nullptr);
}
}
diff --git a/util/system/atexit_ut.cpp b/util/system/atexit_ut.cpp
index 953f4328110..f093c2b86b4 100644
--- a/util/system/atexit_ut.cpp
+++ b/util/system/atexit_ut.cpp
@@ -1,6 +1,7 @@
#include <library/cpp/testing/unittest/registar.h>
#include "atexit.h"
+#include <util/generic/singleton.h>
#include <errno.h>
@@ -83,3 +84,21 @@ class TAtExitTest: public TTestBase {
};
UNIT_TEST_SUITE_REGISTRATION(TAtExitTest);
+
+Y_UNIT_TEST_SUITE(TestAtExit) {
+
+ Y_UNIT_TEST(CreateUponDestruction) {
+
+ struct T1 {
+ };
+
+ struct T2 {
+ ~T2() {
+ Singleton<T1>();
+ }
+ };
+
+ Singleton<T2>();
+
+ }
+}