Skip to content

Commit cd6704e

Browse files
author
Grok Compression
committed
cleanup: use static object destructor instead of atexit
1 parent 1fc3e50 commit cd6704e

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

src/lib/core/grok.cpp

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,16 @@ static grk_object* grkDecompressCreate(grk::IStream* stream)
108108
return &codec->obj;
109109
}
110110

111-
static inline void grk_deinitialize()
111+
class GrkCleanup
112112
{
113-
grk_plugin_cleanup();
114-
ExecSingleton::destroy();
115-
}
113+
public:
114+
GrkCleanup() = default;
115+
~GrkCleanup()
116+
{
117+
grk_plugin_cleanup();
118+
ExecSingleton::destroy();
119+
}
120+
};
116121

117122
static inline bool areStringsEqual(const char* lhs, const char* rhs)
118123
{
@@ -163,17 +168,7 @@ void grk_initialize(const char* pluginPath, uint32_t numThreads, bool* plugin_in
163168
*plugin_initialized = initState_.pluginInitialized_;
164169
return;
165170
}
166-
167-
// Register cleanup once, before doing init work
168-
static bool atexit_registered = false;
169-
if(!atexit_registered)
170-
{
171-
if(std::atexit(grk_deinitialize) != 0)
172-
{
173-
// Handle registration failure (e.g., log error)
174-
}
175-
atexit_registered = true;
176-
}
171+
static GrkCleanup cleanup;
177172

178173
// 1. set up executor
179174
ExecSingleton::create(numThreads);

0 commit comments

Comments
 (0)