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

Method ThreadMain

test/shared_memory_unittest.cc:58–80  ·  view source on GitHub ↗

PlatformThread::Delegate interface.

Source from the content-addressed store, hash-verified

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_;

Callers

nothing calls this directly

Calls 2

MapMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected