diff options
author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-12-10 18:28:34 +0100 |
---|---|---|
committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-12-10 18:28:34 +0100 |
commit | 30e073f58659a8b24890c834cb8b342adc8c5feb (patch) | |
tree | 16650b0f1de890f063ea36bf483504600b82d0a4 /src | |
parent | e4543302fcacf871b319710e925919203f520f32 (diff) | |
download | lanes-30e073f58659a8b24890c834cb8b342adc8c5feb.tar.gz lanes-30e073f58659a8b24890c834cb8b342adc8c5feb.tar.bz2 lanes-30e073f58659a8b24890c834cb8b342adc8c5feb.zip |
DeepFactory counts the number of active Deep objects
Diffstat (limited to 'src')
-rw-r--r-- | src/deep.cpp | 2 | ||||
-rw-r--r-- | src/deep.hpp | 6 |
2 files changed, 8 insertions, 0 deletions
diff --git a/src/deep.cpp b/src/deep.cpp index 398e13f..bc0b73c 100644 --- a/src/deep.cpp +++ b/src/deep.cpp | |||
@@ -131,6 +131,7 @@ int DeepFactory::DeepGC(lua_State* const L_) | |||
131 | void DeepFactory::DeleteDeepObject(lua_State* const L_, DeepPrelude* const o_) | 131 | void DeepFactory::DeleteDeepObject(lua_State* const L_, DeepPrelude* const o_) |
132 | { | 132 | { |
133 | STACK_CHECK_START_REL(L_, 0); | 133 | STACK_CHECK_START_REL(L_, 0); |
134 | o_->factory.deepObjectCount.fetch_sub(1, std::memory_order_relaxed); | ||
134 | o_->factory.deleteDeepObjectInternal(L_, o_); | 135 | o_->factory.deleteDeepObjectInternal(L_, o_); |
135 | STACK_CHECK(L_, 0); | 136 | STACK_CHECK(L_, 0); |
136 | } | 137 | } |
@@ -318,6 +319,7 @@ void DeepFactory::pushDeepUserdata(DestState const L_, UserValueCount const nuv_ | |||
318 | if (_prelude == nullptr) { | 319 | if (_prelude == nullptr) { |
319 | raise_luaL_error(L_, "DeepFactory::newDeepObjectInternal failed to create deep userdata (out of memory)"); | 320 | raise_luaL_error(L_, "DeepFactory::newDeepObjectInternal failed to create deep userdata (out of memory)"); |
320 | } | 321 | } |
322 | deepObjectCount.fetch_add(1, std::memory_order_relaxed); | ||
321 | 323 | ||
322 | if (_prelude->magic != kDeepVersion) { | 324 | if (_prelude->magic != kDeepVersion) { |
323 | // just in case, don't leak the newly allocated deep userdata object | 325 | // just in case, don't leak the newly allocated deep userdata object |
diff --git a/src/deep.hpp b/src/deep.hpp index 6bc3b20..8196e66 100644 --- a/src/deep.hpp +++ b/src/deep.hpp | |||
@@ -50,6 +50,10 @@ class DeepPrelude | |||
50 | // external C modules should create a single object implementing that interface for each Deep userdata class they want to expose | 50 | // external C modules should create a single object implementing that interface for each Deep userdata class they want to expose |
51 | class DeepFactory | 51 | class DeepFactory |
52 | { | 52 | { |
53 | private: | ||
54 | // the current count of deep object instances | ||
55 | mutable std::atomic<int> deepObjectCount{}; | ||
56 | |||
53 | protected: | 57 | protected: |
54 | // protected non-virtual destructor: Lanes won't manage the Factory's lifetime | 58 | // protected non-virtual destructor: Lanes won't manage the Factory's lifetime |
55 | DeepFactory() = default; | 59 | DeepFactory() = default; |
@@ -80,6 +84,8 @@ class DeepFactory | |||
80 | // NVI: public interface | 84 | // NVI: public interface |
81 | static void DeleteDeepObject(lua_State* L_, DeepPrelude* o_); | 85 | static void DeleteDeepObject(lua_State* L_, DeepPrelude* o_); |
82 | [[nodiscard]] | 86 | [[nodiscard]] |
87 | int getObjectCount() const { return deepObjectCount.load(std::memory_order_relaxed); } | ||
88 | [[nodiscard]] | ||
83 | static bool IsDeepUserdata(lua_State* const L_, StackIndex const idx_); | 89 | static bool IsDeepUserdata(lua_State* const L_, StackIndex const idx_); |
84 | [[nodiscard]] | 90 | [[nodiscard]] |
85 | static DeepFactory* LookupFactory(lua_State* L_, StackIndex index_, LookupMode mode_); | 91 | static DeepFactory* LookupFactory(lua_State* L_, StackIndex index_, LookupMode mode_); |