| 157 | } |
| 158 | |
| 159 | void TrackingAllocator::DeallocateRawAsync(void* ptr) { |
| 160 | // freeing a null ptr is a no-op |
| 161 | if (nullptr == ptr) { |
| 162 | return; |
| 163 | } |
| 164 | bool should_delete; |
| 165 | // fetch the following outside the lock in case the call to |
| 166 | // AllocatedSize is slow |
| 167 | bool tracks_allocation_sizes = allocator_->TracksAllocationSizes(); |
| 168 | size_t allocated_bytes = 0; |
| 169 | if (tracks_allocation_sizes) { |
| 170 | allocated_bytes = allocator_->AllocatedSize(ptr); |
| 171 | } else if (track_sizes_locally_) { |
| 172 | mutex_lock lock(mu_); |
| 173 | auto itr = in_use_.find(ptr); |
| 174 | if (itr != in_use_.end()) { |
| 175 | tracks_allocation_sizes = true; |
| 176 | allocated_bytes = (*itr).second.allocated_size; |
| 177 | in_use_.erase(itr); |
| 178 | } |
| 179 | } |
| 180 | Allocator* allocator = allocator_; |
| 181 | { |
| 182 | mutex_lock lock(mu_); |
| 183 | if (tracks_allocation_sizes) { |
| 184 | CHECK_GE(allocated_, allocated_bytes); |
| 185 | allocated_ -= allocated_bytes; |
| 186 | allocations_.emplace_back(-allocated_bytes, Env::Default()->NowMicros()); |
| 187 | } |
| 188 | should_delete = UnRef(); |
| 189 | } |
| 190 | allocator->DeallocateRawAsync(ptr); |
| 191 | if (should_delete) { |
| 192 | delete this; |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | bool TrackingAllocator::TracksAllocationSizes() const { |
| 197 | return track_sizes_locally_ || allocator_->TracksAllocationSizes(); |
nothing calls this directly
no test coverage detected