Skip to content

Commit 2a2b626

Browse files
committed
补充遗漏的初始化
1 parent 162011d commit 2a2b626

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/libipc/platform/posix/mutex.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,18 @@ class mutex {
8080
}
8181
}
8282

83+
static pthread_mutex_t const &zero_mem() {
84+
static const pthread_mutex_t tmp{};
85+
return tmp;
86+
}
87+
8388
public:
8489
mutex() = default;
8590
~mutex() = default;
8691

8792
static void init() {
8893
// Avoid exception problems caused by static member initialization order.
94+
zero_mem();
8995
curr_prog::get();
9096
}
9197

@@ -98,9 +104,8 @@ class mutex {
98104
}
99105

100106
bool valid() const noexcept {
101-
static const char tmp[sizeof(pthread_mutex_t)] {};
102107
return (shm_ != nullptr) && (ref_ != nullptr) && (mutex_ != nullptr)
103-
&& (std::memcmp(tmp, mutex_, sizeof(pthread_mutex_t)) != 0);
108+
&& (std::memcmp(&zero_mem(), mutex_, sizeof(pthread_mutex_t)) != 0);
104109
}
105110

106111
bool open(char const *name) noexcept {

0 commit comments

Comments
 (0)