Bug 1495871 - remove ipc/'s copies of *AtomicSequenceNum classes; r=jld
authorNathan Froyd <froydnj@mozilla.com>
Fri, 05 Oct 2018 13:43:47 -0400
changeset 488140 2296a2feb192ccf56f118999e1a6ec9fa9f36a34
parent 488139 2614ca0a8884a2995a59d07a59340d412450e4f2
child 488141 cdd41eaece0f8c55fe2f32740e1f0b292928c071
push id246
push userfmarier@mozilla.com
push dateSat, 13 Oct 2018 00:15:40 +0000
reviewersjld
bugs1495871
milestone64.0a1
Bug 1495871 - remove ipc/'s copies of *AtomicSequenceNum classes; r=jld Their uses are easily replaced with simpler classes.
ipc/chromium/src/base/atomic_sequence_num.h
ipc/chromium/src/base/atomicops.h
ipc/chromium/src/chrome/common/ipc_channel.cc
deleted file mode 100644
--- a/ipc/chromium/src/base/atomic_sequence_num.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef BASE_ATOMIC_SEQUENCE_NUM_H_
-#define BASE_ATOMIC_SEQUENCE_NUM_H_
-
-#include "base/atomicops.h"
-#include "base/basictypes.h"
-
-namespace base {
-
-class AtomicSequenceNumber;
-
-// Static (POD) AtomicSequenceNumber that MUST be used in global scope (or
-// non-function scope) ONLY. This implementation does not generate any static
-// initializer.  Note that it does not implement any constructor which means
-// that its fields are not initialized except when it is stored in the global
-// data section (.data in ELF). If you want to allocate an atomic sequence
-// number on the stack (or heap), please use the AtomicSequenceNumber class
-// declared below.
-class StaticAtomicSequenceNumber {
- public:
-  inline int GetNext() {
-    return static_cast<int>(
-        base::subtle::NoBarrier_AtomicIncrement(&seq_, 1) - 1);
-  }
-
- private:
-  friend class AtomicSequenceNumber;
-
-  inline void Reset() {
-    base::subtle::Release_Store(&seq_, 0);
-  }
-
-  base::subtle::Atomic32 seq_;
-};
-
-// AtomicSequenceNumber that can be stored and used safely (i.e. its fields are
-// always initialized as opposed to StaticAtomicSequenceNumber declared above).
-// Please use StaticAtomicSequenceNumber if you want to declare an atomic
-// sequence number in the global scope.
-class AtomicSequenceNumber {
- public:
-  AtomicSequenceNumber() {
-    seq_.Reset();
-  }
-
-  inline int GetNext() {
-    return seq_.GetNext();
-  }
-
- private:
-  StaticAtomicSequenceNumber seq_;
-  DISALLOW_COPY_AND_ASSIGN(AtomicSequenceNumber);
-};
-
-}  // namespace base
-
-#endif  // BASE_ATOMIC_SEQUENCE_NUM_H_
--- a/ipc/chromium/src/base/atomicops.h
+++ b/ipc/chromium/src/base/atomicops.h
@@ -1,16 +1,15 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
 // For atomic operations on reference counts, see atomic_refcount.h.
-// For atomic operations on sequence numbers, see atomic_sequence_num.h.
 
 // The routines exported by this module are subtle.  If you use them, even if
 // you get the code right, it will depend on careful reasoning about atomicity
 // and memory ordering; it will be less readable, and harder to maintain.  If
 // you plan to use these routines, you should have a good reason, such as solid
 // evidence that performance would otherwise suffer, or there being no
 // alternative.  You should assume only properties explicitly guaranteed by the
 // specifications in this file.  You are almost certainly _not_ writing code
--- a/ipc/chromium/src/chrome/common/ipc_channel.cc
+++ b/ipc/chromium/src/chrome/common/ipc_channel.cc
@@ -3,25 +3,26 @@
 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
 #include "chrome/common/ipc_channel.h"
 
 #include <limits>
 
-#include "base/atomic_sequence_num.h"
 #include "base/process_util.h"
 #include "base/rand_util.h"
 #include "base/string_util.h"
 
+#include "mozilla/Atomics.h"
+
 namespace {
 
 // Global atomic used to guarantee channel IDs are unique.
-base::StaticAtomicSequenceNumber g_last_id;
+mozilla::Atomic<int> g_last_id;
 
 }  // namespace
 
 namespace IPC {
 
 // static
 std::wstring Channel::GenerateUniqueRandomChannelID() {
   // Note: the string must start with the current process id, this is how
@@ -29,13 +30,13 @@ std::wstring Channel::GenerateUniqueRand
   //
   // This is composed of a unique incremental identifier, the process ID of
   // the creator, an identifier for the child instance, and a strong random
   // component. The strong random component prevents other processes from
   // hijacking or squatting on predictable channel names.
 
   return StringPrintf(L"%d.%u.%d",
       base::GetCurrentProcId(),
-      g_last_id.GetNext(),
+      g_last_id++,
       base::RandInt(0, std::numeric_limits<int32_t>::max()));
 }
 
-}  // namespace IPC
\ No newline at end of file
+}  // namespace IPC