File tree Expand file tree Collapse file tree 2 files changed +7
-9
lines changed Expand file tree Collapse file tree 2 files changed +7
-9
lines changed Original file line number Diff line number Diff line change @@ -52,9 +52,9 @@ namespace geode
5252 using serializer_function = std::function< void ( PContext& ) >;
5353
5454 /* !
55- * Classe holding a const reference of a data.
56- * @warning Do not destroy this Data class before the const reference
57- * obtained using its get() method is no longer in used
55+ * Class holding a const reference of data.
56+ * @warning Do not destroy this Data class if the const reference
57+ * obtained using its get() method is still in used.
5858 */
5959 class opengeode_basic_api Data
6060 {
Original file line number Diff line number Diff line change @@ -75,19 +75,18 @@ namespace geode
7575
7676 void new_data_reference ()
7777 {
78- const std::lock_guard< std::mutex > locking{ lock_ };
7978 counter_++;
8079 last_++;
8180 }
8281
8382 void delete_data_reference ()
8483 {
85- const std::lock_guard< std::mutex > locking{ lock_ };
8684 OPENGEODE_ASSERT (
8785 counter_ > 0 , " [Database::Storage] Cannot decrement" );
8886 counter_--;
8987 if ( unused () )
9088 {
89+ const std::lock_guard< std::mutex > locking{ lock_ };
9190 clean_queue ();
9291 wait_for_memory_release ();
9392 }
@@ -125,7 +124,7 @@ namespace geode
125124
126125 void wait_for_memory_release ()
127126 {
128- const auto last = last_;
127+ const auto last = last_. load () ;
129128 queue_.emplace ( async::spawn ( [this , last] {
130129 std::unique_lock< std::mutex > locking{ lock_ };
131130 if ( !condition_.wait_for (
@@ -138,17 +137,16 @@ namespace geode
138137 data_.reset ();
139138 }
140139 }
141- locking.unlock ();
142140 } ) );
143141 }
144142
145143 private:
146144 std::unique_ptr< Identifier > data_;
147145 std::atomic< bool > terminate_{ false };
148- index_t counter_{ 0 };
146+ std::atomic< index_t > counter_{ 0 };
149147 std::mutex lock_;
150148 std::condition_variable condition_;
151- index_t last_{ 0 };
149+ std::atomic< index_t > last_{ 0 };
152150 std::queue< async::task< void > > queue_;
153151 };
154152
You can’t perform that action at this time.
0 commit comments