MCPcopy Create free account
hub / github.com/apache/brpc / ThreadMain

Method ThreadMain

test/shared_memory_unittest.cc:107–134  ·  view source on GitHub ↗

PlatformThread::Delegate interface.

Source from the content-addressed store, hash-verified

105
106 // PlatformThread::Delegate interface.
107 virtual void ThreadMain() OVERRIDE {
108 const uint32_t kDataSize = sizeof(int);
109 SharedMemoryHandle handle = NULL;
110 {
111 SharedMemory memory1;
112 EXPECT_TRUE(memory1.CreateNamedDeprecated(
113 "SharedMemoryMultipleLockThreadTest", true, kDataSize));
114 EXPECT_TRUE(memory1.ShareToProcess(GetCurrentProcess(), &handle));
115 // TODO(paulg): Implement this once we have a posix version of
116 // SharedMemory::ShareToProcess.
117 EXPECT_TRUE(true);
118 }
119
120 SharedMemory memory2(handle, false);
121 EXPECT_TRUE(memory2.Map(kDataSize));
122 volatile int* const ptr = static_cast<int*>(memory2.memory());
123
124 for (int idx = 0; idx < 20; idx++) {
125 memory2.LockDeprecated();
126 int i = (id_ << 16) + idx;
127 *ptr = i;
128 PlatformThread::Sleep(TimeDelta::FromMilliseconds(1));
129 EXPECT_EQ(*ptr, i);
130 memory2.UnlockDeprecated();
131 }
132
133 memory2.Close();
134 }
135
136 private:
137 int id_;

Callers

nothing calls this directly

Calls 2

MapMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected