PlatformThread::Delegate interface.
| 56 | |
| 57 | // PlatformThread::Delegate interface. |
| 58 | virtual void ThreadMain() OVERRIDE { |
| 59 | #if defined(OS_MACOSX) |
| 60 | mac::ScopedNSAutoreleasePool pool; |
| 61 | #endif |
| 62 | const uint32_t kDataSize = 1024; |
| 63 | SharedMemory memory; |
| 64 | bool rv = memory.CreateNamedDeprecated(s_test_name_, true, kDataSize); |
| 65 | EXPECT_TRUE(rv); |
| 66 | rv = memory.Map(kDataSize); |
| 67 | EXPECT_TRUE(rv); |
| 68 | int *ptr = static_cast<int*>(memory.memory()) + id_; |
| 69 | EXPECT_EQ(0, *ptr); |
| 70 | |
| 71 | for (int idx = 0; idx < 100; idx++) { |
| 72 | *ptr = idx; |
| 73 | PlatformThread::Sleep(butil::TimeDelta::FromMilliseconds(1)); |
| 74 | EXPECT_EQ(*ptr, idx); |
| 75 | } |
| 76 | // Reset back to 0 for the next test that uses the same name. |
| 77 | *ptr = 0; |
| 78 | |
| 79 | memory.Close(); |
| 80 | } |
| 81 | |
| 82 | private: |
| 83 | int16_t id_; |