@@ -160,14 +160,14 @@ namespace snmalloc
160160 */
161161 void ensure_registered ()
162162 {
163- if constexpr (!pal_supports<Time, PAL>)
164- return ;
165-
166- if (
167- !registered_timer.load (stl::memory_order_relaxed) &&
168- !registered_timer.exchange (true , stl::memory_order_acq_rel))
163+ if constexpr (pal_supports<Time, PAL>)
169164 {
170- PAL::register_timer (&timer_object);
165+ if (
166+ !registered_timer.load (stl::memory_order_relaxed) &&
167+ !registered_timer.exchange (true , stl::memory_order_acq_rel))
168+ {
169+ PAL::register_timer (&timer_object);
170+ }
171171 }
172172 }
173173
@@ -178,54 +178,54 @@ namespace snmalloc
178178 template <typename FlushFn>
179179 void sync_epoch (FlushFn&& flush_fn)
180180 {
181- if constexpr (!pal_supports<Time, PAL>)
182- return ;
183-
184- auto current = global_epoch.load (stl::memory_order_acquire);
185-
186- auto behind = current - local_epoch;
187- if (behind == 0 )
188- return ;
181+ if constexpr (pal_supports<Time, PAL>)
182+ {
183+ auto current = global_epoch.load (stl::memory_order_acquire);
189184
190- if (behind > NUM_EPOCHS)
191- behind = NUM_EPOCHS;
185+ auto behind = current - local_epoch;
186+ if (behind == 0 )
187+ return ;
192188
193- // Snapshot counts before flushing.
194- size_t before_count[NUM_SIZECLASSES];
195- for (size_t sc = 0 ; sc < NUM_SIZECLASSES; sc++)
196- before_count[sc] = sc_state[sc].count ;
189+ if (behind > NUM_EPOCHS)
190+ behind = NUM_EPOCHS;
197191
198- // Flush stale epoch slots.
199- for (size_t i = 0 ; i < behind; i++)
200- {
201- auto epoch_to_flush = (local_epoch + 1 + i) % NUM_EPOCHS;
202- flush_epoch_slot (epoch_to_flush, flush_fn);
203- }
192+ // Snapshot counts before flushing.
193+ size_t before_count[NUM_SIZECLASSES];
194+ for (size_t sc = 0 ; sc < NUM_SIZECLASSES; sc++)
195+ before_count[sc] = sc_state[sc].count ;
204196
205- // Adjust budgets based on what happened.
206- // Net out misses against flushed items to determine direction.
207- for (size_t sc = 0 ; sc < NUM_SIZECLASSES; sc++)
208- {
209- auto & state = sc_state[sc];
210- size_t flushed = before_count[sc] - state.count ;
211-
212- if (state.peak_misses > flushed)
197+ // Flush stale epoch slots.
198+ for (size_t i = 0 ; i < behind; i++)
213199 {
214- // More misses than surplus: grow budget by the difference.
215- state. budget += state. peak_misses - flushed ;
200+ auto epoch_to_flush = (local_epoch + 1 + i) % NUM_EPOCHS;
201+ flush_epoch_slot (epoch_to_flush, flush_fn) ;
216202 }
217- else if (flushed > state.peak_misses )
203+
204+ // Adjust budgets based on what happened.
205+ // Net out misses against flushed items to determine direction.
206+ for (size_t sc = 0 ; sc < NUM_SIZECLASSES; sc++)
218207 {
219- // More surplus than misses: shrink budget smoothly.
220- state.budget -= (flushed - state.peak_misses ) / 2 ;
208+ auto & state = sc_state[sc];
209+ size_t flushed = before_count[sc] - state.count ;
210+
211+ if (state.peak_misses > flushed)
212+ {
213+ // More misses than surplus: grow budget by the difference.
214+ state.budget += state.peak_misses - flushed;
215+ }
216+ else if (flushed > state.peak_misses )
217+ {
218+ // More surplus than misses: shrink budget smoothly.
219+ state.budget -= (flushed - state.peak_misses ) / 2 ;
220+ }
221+ // If equal, budget stays the same.
222+
223+ state.misses = 0 ;
224+ state.peak_misses = 0 ;
221225 }
222- // If equal, budget stays the same.
223226
224- state.misses = 0 ;
225- state.peak_misses = 0 ;
227+ local_epoch = current;
226228 }
227-
228- local_epoch = current;
229229 }
230230
231231 /* *
0 commit comments