OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/memory/shared_memory.h" | 7 #include "base/memory/shared_memory.h" |
8 #include "base/process/kill.h" | 8 #include "base/process/kill.h" |
9 #include "base/rand_util.h" | 9 #include "base/rand_util.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 public: | 48 public: |
49 explicit MultipleThreadMain(int16 id) : id_(id) {} | 49 explicit MultipleThreadMain(int16 id) : id_(id) {} |
50 virtual ~MultipleThreadMain() {} | 50 virtual ~MultipleThreadMain() {} |
51 | 51 |
52 static void CleanUp() { | 52 static void CleanUp() { |
53 SharedMemory memory; | 53 SharedMemory memory; |
54 memory.Delete(s_test_name_); | 54 memory.Delete(s_test_name_); |
55 } | 55 } |
56 | 56 |
57 // PlatformThread::Delegate interface. | 57 // PlatformThread::Delegate interface. |
58 virtual void ThreadMain() OVERRIDE { | 58 void ThreadMain() override { |
59 #if defined(OS_MACOSX) | 59 #if defined(OS_MACOSX) |
60 mac::ScopedNSAutoreleasePool pool; | 60 mac::ScopedNSAutoreleasePool pool; |
61 #endif | 61 #endif |
62 const uint32 kDataSize = 1024; | 62 const uint32 kDataSize = 1024; |
63 SharedMemory memory; | 63 SharedMemory memory; |
64 bool rv = memory.CreateNamedDeprecated(s_test_name_, true, kDataSize); | 64 bool rv = memory.CreateNamedDeprecated(s_test_name_, true, kDataSize); |
65 EXPECT_TRUE(rv); | 65 EXPECT_TRUE(rv); |
66 rv = memory.Map(kDataSize); | 66 rv = memory.Map(kDataSize); |
67 EXPECT_TRUE(rv); | 67 EXPECT_TRUE(rv); |
68 int *ptr = static_cast<int*>(memory.memory()) + id_; | 68 int *ptr = static_cast<int*>(memory.memory()) + id_; |
(...skipping 28 matching lines...) Expand all Loading... |
97 // Each thread will open the shared memory. Each thread will take the memory, | 97 // Each thread will open the shared memory. Each thread will take the memory, |
98 // and keep changing it while trying to lock it, with some small pauses in | 98 // and keep changing it while trying to lock it, with some small pauses in |
99 // between. Verify that each thread's value in the shared memory is always | 99 // between. Verify that each thread's value in the shared memory is always |
100 // correct. | 100 // correct. |
101 class MultipleLockThread : public PlatformThread::Delegate { | 101 class MultipleLockThread : public PlatformThread::Delegate { |
102 public: | 102 public: |
103 explicit MultipleLockThread(int id) : id_(id) {} | 103 explicit MultipleLockThread(int id) : id_(id) {} |
104 virtual ~MultipleLockThread() {} | 104 virtual ~MultipleLockThread() {} |
105 | 105 |
106 // PlatformThread::Delegate interface. | 106 // PlatformThread::Delegate interface. |
107 virtual void ThreadMain() OVERRIDE { | 107 void ThreadMain() override { |
108 const uint32 kDataSize = sizeof(int); | 108 const uint32 kDataSize = sizeof(int); |
109 SharedMemoryHandle handle = NULL; | 109 SharedMemoryHandle handle = NULL; |
110 { | 110 { |
111 SharedMemory memory1; | 111 SharedMemory memory1; |
112 EXPECT_TRUE(memory1.CreateNamedDeprecated( | 112 EXPECT_TRUE(memory1.CreateNamedDeprecated( |
113 "SharedMemoryMultipleLockThreadTest", true, kDataSize)); | 113 "SharedMemoryMultipleLockThreadTest", true, kDataSize)); |
114 EXPECT_TRUE(memory1.ShareToProcess(GetCurrentProcess(), &handle)); | 114 EXPECT_TRUE(memory1.ShareToProcess(GetCurrentProcess(), &handle)); |
115 // TODO(paulg): Implement this once we have a posix version of | 115 // TODO(paulg): Implement this once we have a posix version of |
116 // SharedMemory::ShareToProcess. | 116 // SharedMemory::ShareToProcess. |
117 EXPECT_TRUE(true); | 117 EXPECT_TRUE(true); |
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 SharedMemoryProcessTest::CleanUp(); | 691 SharedMemoryProcessTest::CleanUp(); |
692 } | 692 } |
693 | 693 |
694 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) { | 694 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) { |
695 return SharedMemoryProcessTest::TaskTestMain(); | 695 return SharedMemoryProcessTest::TaskTestMain(); |
696 } | 696 } |
697 | 697 |
698 #endif // !OS_IOS | 698 #endif // !OS_IOS |
699 | 699 |
700 } // namespace base | 700 } // namespace base |
OLD | NEW |