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 #if defined(OS_MACOSX) | 6 #if defined(OS_MACOSX) |
7 #include "base/mac/scoped_nsautorelease_pool.h" | 7 #include "base/mac/scoped_nsautorelease_pool.h" |
8 #endif | 8 #endif |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/shared_memory.h" | 10 #include "base/shared_memory.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 namespace base { | 28 namespace base { |
29 | 29 |
30 namespace { | 30 namespace { |
31 | 31 |
32 // Each thread will open the shared memory. Each thread will take a different 4 | 32 // Each thread will open the shared memory. Each thread will take a different 4 |
33 // byte int pointer, and keep changing it, with some small pauses in between. | 33 // byte int pointer, and keep changing it, with some small pauses in between. |
34 // Verify that each thread's value in the shared memory is always correct. | 34 // Verify that each thread's value in the shared memory is always correct. |
35 class MultipleThreadMain : public PlatformThread::Delegate { | 35 class MultipleThreadMain : public PlatformThread::Delegate { |
36 public: | 36 public: |
37 explicit MultipleThreadMain(int16 id) : id_(id) {} | 37 explicit MultipleThreadMain(int16 id) : id_(id) {} |
38 ~MultipleThreadMain() {} | 38 virtual ~MultipleThreadMain() {} |
39 | 39 |
40 static void CleanUp() { | 40 static void CleanUp() { |
41 SharedMemory memory; | 41 SharedMemory memory; |
42 memory.Delete(s_test_name_); | 42 memory.Delete(s_test_name_); |
43 } | 43 } |
44 | 44 |
45 // PlatformThread::Delegate interface. | 45 // PlatformThread::Delegate interface. |
46 void ThreadMain() { | 46 virtual void ThreadMain() OVERRIDE { |
47 #if defined(OS_MACOSX) | 47 #if defined(OS_MACOSX) |
48 mac::ScopedNSAutoreleasePool pool; | 48 mac::ScopedNSAutoreleasePool pool; |
49 #endif | 49 #endif |
50 const uint32 kDataSize = 1024; | 50 const uint32 kDataSize = 1024; |
51 SharedMemory memory; | 51 SharedMemory memory; |
52 bool rv = memory.CreateNamed(s_test_name_, true, kDataSize); | 52 bool rv = memory.CreateNamed(s_test_name_, true, kDataSize); |
53 EXPECT_TRUE(rv); | 53 EXPECT_TRUE(rv); |
54 rv = memory.Map(kDataSize); | 54 rv = memory.Map(kDataSize); |
55 EXPECT_TRUE(rv); | 55 EXPECT_TRUE(rv); |
56 int *ptr = static_cast<int*>(memory.memory()) + id_; | 56 int *ptr = static_cast<int*>(memory.memory()) + id_; |
(...skipping 25 matching lines...) Expand all Loading... |
82 // This test requires the ability to pass file descriptors between processes. | 82 // This test requires the ability to pass file descriptors between processes. |
83 // We haven't done that yet in Chrome for POSIX. | 83 // We haven't done that yet in Chrome for POSIX. |
84 #if defined(OS_WIN) | 84 #if defined(OS_WIN) |
85 // Each thread will open the shared memory. Each thread will take the memory, | 85 // Each thread will open the shared memory. Each thread will take the memory, |
86 // and keep changing it while trying to lock it, with some small pauses in | 86 // and keep changing it while trying to lock it, with some small pauses in |
87 // between. Verify that each thread's value in the shared memory is always | 87 // between. Verify that each thread's value in the shared memory is always |
88 // correct. | 88 // correct. |
89 class MultipleLockThread : public PlatformThread::Delegate { | 89 class MultipleLockThread : public PlatformThread::Delegate { |
90 public: | 90 public: |
91 explicit MultipleLockThread(int id) : id_(id) {} | 91 explicit MultipleLockThread(int id) : id_(id) {} |
92 ~MultipleLockThread() {} | 92 virtual ~MultipleLockThread() {} |
93 | 93 |
94 // PlatformThread::Delegate interface. | 94 // PlatformThread::Delegate interface. |
95 void ThreadMain() { | 95 virtual void ThreadMain() OVERRIDE { |
96 const uint32 kDataSize = sizeof(int); | 96 const uint32 kDataSize = sizeof(int); |
97 SharedMemoryHandle handle = NULL; | 97 SharedMemoryHandle handle = NULL; |
98 { | 98 { |
99 SharedMemory memory1; | 99 SharedMemory memory1; |
100 EXPECT_TRUE(memory1.CreateNamed("SharedMemoryMultipleLockThreadTest", | 100 EXPECT_TRUE(memory1.CreateNamed("SharedMemoryMultipleLockThreadTest", |
101 true, kDataSize)); | 101 true, kDataSize)); |
102 EXPECT_TRUE(memory1.ShareToProcess(GetCurrentProcess(), &handle)); | 102 EXPECT_TRUE(memory1.ShareToProcess(GetCurrentProcess(), &handle)); |
103 // TODO(paulg): Implement this once we have a posix version of | 103 // TODO(paulg): Implement this once we have a posix version of |
104 // SharedMemory::ShareToProcess. | 104 // SharedMemory::ShareToProcess. |
105 EXPECT_TRUE(true); | 105 EXPECT_TRUE(true); |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 } | 427 } |
428 | 428 |
429 SharedMemoryProcessTest::CleanUp(); | 429 SharedMemoryProcessTest::CleanUp(); |
430 } | 430 } |
431 | 431 |
432 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) { | 432 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) { |
433 return SharedMemoryProcessTest::TaskTestMain(); | 433 return SharedMemoryProcessTest::TaskTestMain(); |
434 } | 434 } |
435 | 435 |
436 } // namespace base | 436 } // namespace base |
OLD | NEW |