put a object into thread local cache or global cache.
| 65 | |
| 66 | // put a object into thread local cache or global cache. |
| 67 | void put(std::unique_ptr<Storage> obj) { |
| 68 | // push to the first batch. |
| 69 | if (first_.size() < kThreadLocalMaxNum) { |
| 70 | first_.push_back(std::move(obj)); |
| 71 | return; |
| 72 | } |
| 73 | |
| 74 | // push to the second batch. |
| 75 | second_.push_back(std::move(obj)); |
| 76 | if (UNLIKELY(second_.size() >= kThreadLocalMaxNum)) { |
| 77 | // push to the global cache. |
| 78 | parent_.putBatch(std::move(second_)); |
| 79 | second_.clear(); |
| 80 | second_.reserve(kThreadLocalMaxNum); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | private: |
| 85 | ObjectPool &parent_; |
no test coverage detected