Commit 1e71e4c0 authored by Dave Watson's avatar Dave Watson Committed by Facebook Github Bot

Remove batch

Summary:
Remove hazptr_obj_batch feature.  Not required after D7429494:

After timer runs out, *all* thread caches are cleaned up, not just the current one,
so it should be safe to push anything to local thread cache, even if thread isn't used often,
as long as *some* thread is used.

Reviewed By: magedm

Differential Revision: D7433978

fbshipit-source-id: 01508fd199fcd267550efc08d2695b53f1569c84
parent d211a58c
......@@ -222,7 +222,6 @@ class UnboundedQueue {
struct Consumer {
Atom<Segment*> head;
Atom<Ticket> ticket;
folly::hazptr::hazptr_obj_batch batch;
};
struct Producer {
Atom<Segment*> tail;
......@@ -556,22 +555,8 @@ class UnboundedQueue {
// segment may incorrectly set head back.
asm_volatile_pause();
}
/* ***IMPORTANT*** prepReclaimSegment() must be called after
* confirming that head() is up-to-date and before calling
* setHead() to be thread-safe. */
/* ***IMPORTANT*** Segment s cannot be retired before the call to
* setHead(s). This is why prep_retire_refcounted(), which is
* called by prepReclaimSegment() does not retire objects, it
* merely adds the object to the batch and returns a private batch
* structure of a list of objects that can be retired later, if
* there are enough objects for amortizing the cost of updating
* the domain structure. */
auto res = prepReclaimSegment(s);
setHead(next);
/* Now it is safe to retire s. */
/* ***IMPORTANT*** The destructor of res automatically calls
* retire_all(), which retires to the domain any objects moved to
* res from batch in the call to prepReclaimSegment(). */
reclaimSegment(s);
}
/** reclaimSegment */
......@@ -583,17 +568,6 @@ class UnboundedQueue {
}
}
/** prepReclaimSegment */
folly::hazptr::hazptr_obj_batch prepReclaimSegment(Segment* s) noexcept {
if (SPSC) {
delete s;
/*Return an empty result; nothing more to do for this segment */
return folly::hazptr::hazptr_obj_batch();
} else {
return c_.batch.prep_retire_refcounted(s);
}
}
FOLLY_ALWAYS_INLINE size_t index(Ticket t) const noexcept {
return (t * Stride) & (SegmentSize - 1);
}
......
......@@ -1226,73 +1226,5 @@ inline bool hazptr_priv_try_retire(hazptr_obj* obj) {
return false;
}
/** hazptr_obj_batch */
/* Only for default domain. Supports only hazptr_obj_base_refcounted
* and a thread-safe access only, for now. */
class hazptr_obj_batch {
static constexpr int DefaultThreshold = 20;
hazptr_obj* head_{nullptr};
hazptr_obj* tail_{nullptr};
int rcount_{0};
int threshold_{DefaultThreshold};
public:
hazptr_obj_batch() {}
hazptr_obj_batch(hazptr_obj* head, hazptr_obj* tail, int rcount)
: head_(head), tail_(tail), rcount_(rcount) {}
~hazptr_obj_batch() {
retire_all();
}
/* Prepare a hazptr_obj_base_refcounted for retirement but don't
push it the domain yet. Return true if the batch is ready. */
template <typename T, typename D = std::default_delete<T>>
hazptr_obj_batch prep_retire_refcounted(
hazptr_obj_base_refcounted<T, D>* obj,
D deleter = {}) {
obj->preRetire(deleter);
obj->next_ = head_;
head_ = obj;
if (tail_ == nullptr) {
tail_ = obj;
}
if (++rcount_ < threshold_) {
return hazptr_obj_batch();
} else {
auto head = head_;
auto tail = tail_;
auto rcount = rcount_;
clear();
return hazptr_obj_batch(head, tail, rcount);
}
}
bool empty() {
return rcount_ == 0;
}
void retire_all() {
if (!empty()) {
auto& domain = default_hazptr_domain();
domain.pushRetired(head_, tail_, rcount_);
domain.tryBulkReclaim();
clear();
}
}
void set_threshold(int thresh) {
threshold_ = thresh;
}
private:
void clear() {
head_ = nullptr;
tail_ = nullptr;
rcount_ = 0;
}
};
} // namespace hazptr
} // namespace folly
......@@ -84,7 +84,6 @@ class hazptr_domain {
void tryTimedCleanup();
private:
friend class hazptr_obj_batch;
friend class hazptr_holder;
template <typename, typename>
friend class hazptr_obj_base;
......@@ -117,7 +116,6 @@ void hazptr_cleanup(hazptr_domain& domain = default_hazptr_domain());
/** Definition of hazptr_obj */
class hazptr_obj {
friend class hazptr_obj_batch;
friend class hazptr_domain;
template <typename, typename>
friend class hazptr_obj_base;
......@@ -168,8 +166,6 @@ class hazptr_obj_base : public hazptr_obj {
/** Definition of hazptr_recounted_obj_base */
template <typename T, typename D = std::default_delete<T>>
class hazptr_obj_base_refcounted : public hazptr_obj {
friend class hazptr_obj_batch;
public:
/* Retire a removed object and pass the responsibility for
* reclaiming it to the hazptr library */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment