• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "net/base/network_activity_monitor.h"
6 
7 #include <atomic>
8 #include <type_traits>
9 
10 
11 namespace net::activity_monitor {
12 
13 namespace {
14 
15 constinit std::atomic<uint64_t> g_bytes_received = 0;
16 
17 }  // namespace
18 
IncrementBytesReceived(uint64_t bytes_received)19 void IncrementBytesReceived(uint64_t bytes_received) {
20   // std::memory_order_relaxed is used because no other operation on
21   // |bytes_received_| depends on memory operations that happened before this
22   // increment.
23   g_bytes_received.fetch_add(bytes_received, std::memory_order_relaxed);
24 }
25 
GetBytesReceived()26 uint64_t GetBytesReceived() {
27   return g_bytes_received.load(std::memory_order_relaxed);
28 }
29 
ResetBytesReceivedForTesting()30 void ResetBytesReceivedForTesting() {
31   g_bytes_received = 0;
32 }
33 
34 }  // namespace net::activity_monitor
35