| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/debug/activity_tracker.h" | 5 #include "base/debug/activity_tracker.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 // If the value is actually a single byte, see if it can be stuffed at the | 324 // If the value is actually a single byte, see if it can be stuffed at the |
| 325 // end of the name extent rather than wasting kMemoryAlignment bytes. | 325 // end of the name extent rather than wasting kMemoryAlignment bytes. |
| 326 if (size == 1 && name_extent > name_size) { | 326 if (size == 1 && name_extent > name_size) { |
| 327 full_size = base_size; | 327 full_size = base_size; |
| 328 --name_extent; | 328 --name_extent; |
| 329 --base_size; | 329 --base_size; |
| 330 } | 330 } |
| 331 | 331 |
| 332 // Truncate the stored size to the amount of available memory. Stop now if | 332 // Truncate the stored size to the amount of available memory. Stop now if |
| 333 // there's not any room for even part of the value. | 333 // there's not any room for even part of the value. |
| 334 size = std::min(full_size - base_size, size); | 334 if (size != 0) { |
| 335 if (size == 0) | 335 size = std::min(full_size - base_size, size); |
| 336 return; | 336 if (size == 0) |
| 337 return; |
| 338 } |
| 337 | 339 |
| 338 // Allocate a chunk of memory. | 340 // Allocate a chunk of memory. |
| 339 Header* header = reinterpret_cast<Header*>(memory_); | 341 Header* header = reinterpret_cast<Header*>(memory_); |
| 340 memory_ += full_size; | 342 memory_ += full_size; |
| 341 available_ -= full_size; | 343 available_ -= full_size; |
| 342 | 344 |
| 343 // Datafill the header and name records. Memory must be zeroed. The |type| | 345 // Datafill the header and name records. Memory must be zeroed. The |type| |
| 344 // is written last, atomically, to release all the other values. | 346 // is written last, atomically, to release all the other values. |
| 345 DCHECK_EQ(END_OF_VALUES, header->type.load(std::memory_order_relaxed)); | 347 DCHECK_EQ(END_OF_VALUES, header->type.load(std::memory_order_relaxed)); |
| 346 DCHECK_EQ(0, header->value_size.load(std::memory_order_relaxed)); | 348 DCHECK_EQ(0, header->value_size.load(std::memory_order_relaxed)); |
| (...skipping 1031 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1378 : GlobalActivityTracker::ScopedThreadActivity( | 1380 : GlobalActivityTracker::ScopedThreadActivity( |
| 1379 program_counter, | 1381 program_counter, |
| 1380 nullptr, | 1382 nullptr, |
| 1381 Activity::ACT_PROCESS_WAIT, | 1383 Activity::ACT_PROCESS_WAIT, |
| 1382 ActivityData::ForProcess(process->Pid()), | 1384 ActivityData::ForProcess(process->Pid()), |
| 1383 /*lock_allowed=*/true) {} | 1385 /*lock_allowed=*/true) {} |
| 1384 #endif | 1386 #endif |
| 1385 | 1387 |
| 1386 } // namespace debug | 1388 } // namespace debug |
| 1387 } // namespace base | 1389 } // namespace base |
| OLD | NEW |