xref: /aosp_15_r20/external/cronet/net/base/network_activity_monitor.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
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 #include "third_party/abseil-cpp/absl/base/attributes.h"
11 
12 namespace net::activity_monitor {
13 
14 namespace {
15 
16 ABSL_CONST_INIT std::atomic<uint64_t> g_bytes_received = 0;
17 
18 }  // namespace
19 
IncrementBytesReceived(uint64_t bytes_received)20 void IncrementBytesReceived(uint64_t bytes_received) {
21   // std::memory_order_relaxed is used because no other operation on
22   // |bytes_received_| depends on memory operations that happened before this
23   // increment.
24   g_bytes_received.fetch_add(bytes_received, std::memory_order_relaxed);
25 }
26 
GetBytesReceived()27 uint64_t GetBytesReceived() {
28   return g_bytes_received.load(std::memory_order_relaxed);
29 }
30 
ResetBytesReceivedForTesting()31 void ResetBytesReceivedForTesting() {
32   g_bytes_received = 0;
33 }
34 
35 }  // namespace net::activity_monitor
36