general: Use deducation guides for std::lock_guard and std::unique_lock
Since C++17, the introduction of deduction guides for locking facilities means that we no longer need to hardcode the mutex type into the locks themselves, making it easier to switch mutex types, should it ever be necessary in the future.
This commit is contained in:
parent
d5bcb45b2a
commit
21c71d21ae
21 changed files with 124 additions and 122 deletions
|
@ -157,7 +157,7 @@ bool RoomMember::RoomMemberImpl::IsConnected() const {
|
|||
void RoomMember::RoomMemberImpl::MemberLoop() {
|
||||
// Receive packets while the connection is open
|
||||
while (IsConnected()) {
|
||||
std::lock_guard<std::mutex> lock(network_mutex);
|
||||
std::lock_guard lock(network_mutex);
|
||||
ENetEvent event;
|
||||
if (enet_host_service(client, &event, 100) > 0) {
|
||||
switch (event.type) {
|
||||
|
@ -245,7 +245,7 @@ void RoomMember::RoomMemberImpl::MemberLoop() {
|
|||
}
|
||||
}
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(send_list_mutex);
|
||||
std::lock_guard lock(send_list_mutex);
|
||||
for (const auto& packet : send_list) {
|
||||
ENetPacket* enetPacket = enet_packet_create(packet.GetData(), packet.GetDataSize(),
|
||||
ENET_PACKET_FLAG_RELIABLE);
|
||||
|
@ -263,7 +263,7 @@ void RoomMember::RoomMemberImpl::StartLoop() {
|
|||
}
|
||||
|
||||
void RoomMember::RoomMemberImpl::Send(Packet&& packet) {
|
||||
std::lock_guard<std::mutex> lock(send_list_mutex);
|
||||
std::lock_guard lock(send_list_mutex);
|
||||
send_list.push_back(std::move(packet));
|
||||
}
|
||||
|
||||
|
@ -318,7 +318,7 @@ void RoomMember::RoomMemberImpl::HandleRoomInformationPacket(const ENetEvent* ev
|
|||
packet >> member.avatar_url;
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(username_mutex);
|
||||
std::lock_guard lock(username_mutex);
|
||||
if (member.nickname == nickname) {
|
||||
username = member.username;
|
||||
}
|
||||
|
@ -473,7 +473,7 @@ RoomMember::RoomMemberImpl::Callbacks::Get() {
|
|||
|
||||
template <typename T>
|
||||
void RoomMember::RoomMemberImpl::Invoke(const T& data) {
|
||||
std::lock_guard<std::mutex> lock(callback_mutex);
|
||||
std::lock_guard lock(callback_mutex);
|
||||
CallbackSet<T> callback_set = callbacks.Get<T>();
|
||||
for (auto const& callback : callback_set)
|
||||
(*callback)(data);
|
||||
|
@ -482,7 +482,7 @@ void RoomMember::RoomMemberImpl::Invoke(const T& data) {
|
|||
template <typename T>
|
||||
RoomMember::CallbackHandle<T> RoomMember::RoomMemberImpl::Bind(
|
||||
std::function<void(const T&)> callback) {
|
||||
std::lock_guard<std::mutex> lock(callback_mutex);
|
||||
std::lock_guard lock(callback_mutex);
|
||||
CallbackHandle<T> handle;
|
||||
handle = std::make_shared<std::function<void(const T&)>>(callback);
|
||||
callbacks.Get<T>().insert(handle);
|
||||
|
@ -512,7 +512,7 @@ const std::string& RoomMember::GetNickname() const {
|
|||
}
|
||||
|
||||
const std::string& RoomMember::GetUsername() const {
|
||||
std::lock_guard<std::mutex> lock(room_member_impl->username_mutex);
|
||||
std::lock_guard lock(room_member_impl->username_mutex);
|
||||
return room_member_impl->username;
|
||||
}
|
||||
|
||||
|
@ -663,7 +663,7 @@ RoomMember::CallbackHandle<Room::BanList> RoomMember::BindOnBanListReceived(
|
|||
|
||||
template <typename T>
|
||||
void RoomMember::Unbind(CallbackHandle<T> handle) {
|
||||
std::lock_guard<std::mutex> lock(room_member_impl->callback_mutex);
|
||||
std::lock_guard lock(room_member_impl->callback_mutex);
|
||||
room_member_impl->callbacks.Get<T>().erase(handle);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue