File tree Expand file tree Collapse file tree 4 files changed +41
-14
lines changed Expand file tree Collapse file tree 4 files changed +41
-14
lines changed Original file line number Diff line number Diff line change @@ -2639,20 +2639,12 @@ bool CacheAllocator<CacheTrait>::moveForSlabRelease(
2639
2639
const auto allocInfo = allocator_->getAllocInfo (oldItem.getMemory ());
2640
2640
if (chainedItem) {
2641
2641
newItemHdl.reset ();
2642
- auto ref = parentItem->unmarkMoving ();
2643
- if (UNLIKELY (ref == 0 )) {
2644
- wakeUpWaiters (*parentItem, {});
2645
- const auto res =
2646
- releaseBackToAllocator (*parentItem, RemoveContext::kNormal , false );
2647
- XDCHECK (res == ReleaseRes::kReleased );
2648
- return true ;
2649
- } else {
2650
- XDCHECK_NE (ref, 0 );
2651
- auto parentHdl = acquire (parentItem);
2652
- if (parentHdl) {
2653
- wakeUpWaiters (*parentItem, std::move (parentHdl));
2654
- }
2655
- }
2642
+ auto ref = parentItem->unmarkMovingAndIncRef ();
2643
+ XDCHECK_NE (ref, 0 );
2644
+ auto parentHdl = acquire (parentItem);
2645
+ XDCHECK (parentHdl);
2646
+ parentHdl->decRef ();
2647
+ wakeUpWaiters (*parentItem, std::move (parentHdl));
2656
2648
} else {
2657
2649
auto ref = unmarkMovingAndWakeUpWaiters (oldItem, std::move (newItemHdl));
2658
2650
XDCHECK (ref == 0 );
Original file line number Diff line number Diff line change @@ -247,6 +247,11 @@ RefcountWithFlags::Value CacheItem<CacheTrait>::unmarkMoving() noexcept {
247
247
return ref_.unmarkMoving ();
248
248
}
249
249
250
+ template <typename CacheTrait>
251
+ RefcountWithFlags::Value CacheItem<CacheTrait>::unmarkMovingAndIncRef() noexcept {
252
+ return ref_.unmarkMovingAndIncRef ();
253
+ }
254
+
250
255
template <typename CacheTrait>
251
256
bool CacheItem<CacheTrait>::isMoving() const noexcept {
252
257
return ref_.isMoving ();
Original file line number Diff line number Diff line change @@ -380,6 +380,7 @@ class CACHELIB_PACKED_ATTR CacheItem {
380
380
*/
381
381
bool markMoving ();
382
382
RefcountWithFlags::Value unmarkMoving () noexcept ;
383
+ RefcountWithFlags::Value unmarkMovingAndIncRef () noexcept ;
383
384
bool isMoving () const noexcept ;
384
385
bool isOnlyMoving () const noexcept ;
385
386
Original file line number Diff line number Diff line change @@ -379,6 +379,35 @@ class FOLLY_PACK_ATTR RefcountWithFlags {
379
379
380
380
return retValue & kRefMask ;
381
381
}
382
+
383
+ /*
384
+ * this is used when we immediately call acquire after unmarking
385
+ * moving - this is currently done in the case of moving a
386
+ * chained item when the parent is unmarked moving and we
387
+ * need to wake up the waiters with the parent handle BUT
388
+ * we don't want the parent item to be marked moving/exclusive
389
+ * between unmarking moving and acquire - so we do not
390
+ * modify the refcount (moving state = exclusive bit set and refcount == 1)
391
+ */
392
+ Value unmarkMovingAndIncRef () noexcept {
393
+ XDCHECK (isMoving ());
394
+ auto predicate = [](const Value curValue) {
395
+ XDCHECK ((curValue & kAccessRefMask ) != 0 );
396
+ return true ;
397
+ };
398
+
399
+ Value retValue;
400
+ auto newValue = [&retValue](const Value curValue) {
401
+ retValue =
402
+ (curValue) & ~getAdminRef<kExclusive >();
403
+ return retValue;
404
+ };
405
+
406
+ auto updated = atomicUpdateValue (predicate, newValue);
407
+ XDCHECK (updated);
408
+
409
+ return retValue & kRefMask ;
410
+ }
382
411
383
412
bool isMoving () const noexcept {
384
413
auto raw = getRaw ();
You can’t perform that action at this time.
0 commit comments