aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp
diff options
context:
space:
mode:
authorbabenko <babenko@yandex-team.com>2024-08-02 12:04:49 +0300
committerbabenko <babenko@yandex-team.com>2024-08-02 12:18:17 +0300
commit23b7c61b3876a421a9f239646c2f67c70877d21e (patch)
tree080f664dac1dc44ce20cebe488942f1066f0d4be /library/cpp
parent99d0a5c88a19f2a5310c8bfe5ed63ef53e8ce00b (diff)
downloadydb-23b7c61b3876a421a9f239646c2f67c70877d21e.tar.gz
Refactor and unify exit codes
ec1d0c473e709e8aad76b4e190a75ad4125a9ce2
Diffstat (limited to 'library/cpp')
-rw-r--r--library/cpp/yt/memory/chunked_memory_pool-inl.h6
-rw-r--r--library/cpp/yt/memory/ya.make1
-rw-r--r--library/cpp/yt/system/exit.cpp14
-rw-r--r--library/cpp/yt/system/exit.h22
-rw-r--r--library/cpp/yt/system/ya.make1
5 files changed, 44 insertions, 0 deletions
diff --git a/library/cpp/yt/memory/chunked_memory_pool-inl.h b/library/cpp/yt/memory/chunked_memory_pool-inl.h
index 58a0cefcc2..2502204160 100644
--- a/library/cpp/yt/memory/chunked_memory_pool-inl.h
+++ b/library/cpp/yt/memory/chunked_memory_pool-inl.h
@@ -6,6 +6,8 @@
#include "serialize.h"
+#include <library/cpp/yt/system/exit.h>
+
#include <library/cpp/yt/malloc/malloc.h>
#include <util/system/align.h>
@@ -30,6 +32,10 @@ TDerived* TAllocationHolder::Allocate(size_t size, TRefCountedTypeCookie cookie)
auto requestedSize = sizeof(TDerived) + size;
auto* ptr = ::malloc(requestedSize);
+ if (!ptr) {
+ AbortProcess(ToUnderlying(EProcessExitCode::OutOfMemory));
+ }
+
#ifndef _win_
auto allocatedSize = ::malloc_usable_size(ptr);
if (allocatedSize) {
diff --git a/library/cpp/yt/memory/ya.make b/library/cpp/yt/memory/ya.make
index 7a5a2f88ea..9dc4372729 100644
--- a/library/cpp/yt/memory/ya.make
+++ b/library/cpp/yt/memory/ya.make
@@ -21,6 +21,7 @@ PEERDIR(
library/cpp/yt/assert
library/cpp/yt/misc
library/cpp/yt/malloc
+ library/cpp/yt/system
)
CHECK_DEPENDENT_DIRS(
diff --git a/library/cpp/yt/system/exit.cpp b/library/cpp/yt/system/exit.cpp
new file mode 100644
index 0000000000..b17f6c5ad7
--- /dev/null
+++ b/library/cpp/yt/system/exit.cpp
@@ -0,0 +1,14 @@
+#include "exit.h"
+
+namespace NYT {
+
+////////////////////////////////////////////////////////////////////////////////
+
+void AbortProcess(int exitCode)
+{
+ _exit(exitCode);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+} // namespace NYT
diff --git a/library/cpp/yt/system/exit.h b/library/cpp/yt/system/exit.h
new file mode 100644
index 0000000000..6c009fff90
--- /dev/null
+++ b/library/cpp/yt/system/exit.h
@@ -0,0 +1,22 @@
+#pragma once
+
+#include <library/cpp/yt/misc/enum.h>
+
+namespace NYT {
+
+////////////////////////////////////////////////////////////////////////////////
+
+DEFINE_ENUM(EProcessExitCode,
+ ((OK) (0))
+ ((ArgumentsError) (1))
+ ((GenericError) (2))
+ ((IOError) (3))
+ ((OutOfMemory) (9))
+);
+
+//! Invokes _exit to abort the process immediately without calling any cleanup code.
+[[noreturn]] void AbortProcess(int exitCode);
+
+////////////////////////////////////////////////////////////////////////////////
+
+} // namespace NYT
diff --git a/library/cpp/yt/system/ya.make b/library/cpp/yt/system/ya.make
index 22aab5151e..de4516d928 100644
--- a/library/cpp/yt/system/ya.make
+++ b/library/cpp/yt/system/ya.make
@@ -3,6 +3,7 @@ LIBRARY()
INCLUDE(${ARCADIA_ROOT}/library/cpp/yt/ya_cpp.make.inc)
SRCS(
+ exit.cpp
thread_id.cpp
)