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
52
52
using serializer_function = std::function< void ( PContext& ) >;
53
53
54
54
/* !
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.
58
58
*/
59
59
class opengeode_basic_api Data
60
60
{
Original file line number Diff line number Diff line change @@ -75,19 +75,18 @@ namespace geode
75
75
76
76
void new_data_reference ()
77
77
{
78
- const std::lock_guard< std::mutex > locking{ lock_ };
79
78
counter_++;
80
79
last_++;
81
80
}
82
81
83
82
void delete_data_reference ()
84
83
{
85
- const std::lock_guard< std::mutex > locking{ lock_ };
86
84
OPENGEODE_ASSERT (
87
85
counter_ > 0 , " [Database::Storage] Cannot decrement" );
88
86
counter_--;
89
87
if ( unused () )
90
88
{
89
+ const std::lock_guard< std::mutex > locking{ lock_ };
91
90
clean_queue ();
92
91
wait_for_memory_release ();
93
92
}
@@ -125,7 +124,7 @@ namespace geode
125
124
126
125
void wait_for_memory_release ()
127
126
{
128
- const auto last = last_;
127
+ const auto last = last_. load () ;
129
128
queue_.emplace ( async::spawn ( [this , last] {
130
129
std::unique_lock< std::mutex > locking{ lock_ };
131
130
if ( !condition_.wait_for (
@@ -138,17 +137,16 @@ namespace geode
138
137
data_.reset ();
139
138
}
140
139
}
141
- locking.unlock ();
142
140
} ) );
143
141
}
144
142
145
143
private:
146
144
std::unique_ptr< Identifier > data_;
147
145
std::atomic< bool > terminate_{ false };
148
- index_t counter_{ 0 };
146
+ std::atomic< index_t > counter_{ 0 };
149
147
std::mutex lock_;
150
148
std::condition_variable condition_;
151
- index_t last_{ 0 };
149
+ std::atomic< index_t > last_{ 0 };
152
150
std::queue< async::task< void > > queue_;
153
151
};
154
152
You can’t perform that action at this time.
0 commit comments