tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

allocation_counter.h (1716B)


      1 /*
      2 *  Copyright (c) 2025 The WebRTC project authors. All Rights Reserved.
      3 *
      4 *  Use of this source code is governed by a BSD-style license
      5 *  that can be found in the LICENSE file in the root of the source
      6 *  tree. An additional intellectual property rights grant can be found
      7 *  in the file PATENTS.  All contributing project authors may
      8 *  be found in the AUTHORS file in the root of the source tree.
      9 */
     10 
     11 #ifndef COMMON_AUDIO_ALLOCATION_COUNTER_H_
     12 #define COMMON_AUDIO_ALLOCATION_COUNTER_H_
     13 
     14 #if defined(ADDRESS_SANITIZER) || defined(LEAK_SANITIZER) ||  \
     15    defined(MEMORY_SANITIZER) || defined(THREAD_SANITIZER) || \
     16    defined(UNDEFINED_SANITIZER)
     17 // The allocator override mechanism is not available since the
     18 // sanitizers override the allocators themselves.
     19 #else
     20 #define WEBRTC_ALLOCATION_COUNTER_AVAILABLE 1
     21 
     22 #include <cstddef>
     23 
     24 namespace webrtc {
     25 
     26 // Use to count the number of heap allocations that have been performed on the
     27 // current thread within the scope of the AllocationCounter.
     28 //
     29 // * Note1: This class is a test-only utility.  In order to be able to count
     30 //   allocations, AllocationCounter overrides the global new and delete
     31 //   operators for the test binary.
     32 //
     33 // * Note2: An AllocationCounter instance must always be used from the same
     34 //   thread.
     35 class AllocationCounter {
     36 public:
     37  AllocationCounter();
     38  ~AllocationCounter() = default;
     39 
     40  // Returns the number of heap allocations that have been made since
     41  // construction.
     42  size_t new_count() const;
     43  size_t delete_count() const;
     44 
     45 private:
     46  const size_t initial_new_count_;
     47  const size_t initial_delete_count_;
     48 };
     49 }  // namespace webrtc
     50 
     51 #endif  // all the sanitizers
     52 #endif  // COMMON_AUDIO_ALLOCATION_COUNTER_H_