fix emplace construction for shm_data. Previous required copy constructor

This commit is contained in:
abathur puppe 2024-05-09 14:17:45 +02:00 committed by 木头云
parent 035d76d5aa
commit 025311d5f6
2 changed files with 11 additions and 4 deletions

View File

@ -125,8 +125,11 @@ class mutex {
IPC_UNUSED_ std::lock_guard<std::mutex> guard {info.lock}; IPC_UNUSED_ std::lock_guard<std::mutex> guard {info.lock};
auto it = info.mutex_handles.find(name); auto it = info.mutex_handles.find(name);
if (it == info.mutex_handles.end()) { if (it == info.mutex_handles.end()) {
it = info.mutex_handles.emplace(name, it = info.mutex_handles
curr_prog::shm_data::init{name}).first; .emplace(
std::piecewise_construct, std::forward_as_tuple(name),
std::forward_as_tuple(curr_prog::shm_data::init{name}))
.first;
} }
mutex_ = &it->second.mtx; mutex_ = &it->second.mtx;
ref_ = &it->second.ref; ref_ = &it->second.ref;

View File

@ -55,8 +55,12 @@ class mutex {
IPC_UNUSED_ std::lock_guard<std::mutex> guard {info.lock}; IPC_UNUSED_ std::lock_guard<std::mutex> guard {info.lock};
auto it = info.mutex_handles.find(name); auto it = info.mutex_handles.find(name);
if (it == info.mutex_handles.end()) { if (it == info.mutex_handles.end()) {
it = info.mutex_handles.emplace(name, it = info.mutex_handles
curr_prog::shm_data::init{name, sizeof(pthread_mutex_t)}).first; .emplace(std::piecewise_construct,
std::forward_as_tuple(name),
std::forward_as_tuple(curr_prog::shm_data::init{
name, sizeof(pthread_mutex_t)}))
.first;
} }
shm_ = &it->second.shm; shm_ = &it->second.shm;
ref_ = &it->second.ref; ref_ = &it->second.ref;