From 589844c8278027b1dbb83d6e028bd7881142a4c8 Mon Sep 17 00:00:00 2001 From: Relintai Date: Thu, 21 Jul 2022 18:19:40 +0200 Subject: [PATCH] Added an RWLock to User. --- modules/users/users/user.cpp | 18 ++++++++++++++++++ modules/users/users/user.h | 8 ++++++++ 2 files changed, 26 insertions(+) diff --git a/modules/users/users/user.cpp b/modules/users/users/user.cpp index c5e0e3dd2..3f15b4818 100644 --- a/modules/users/users/user.cpp +++ b/modules/users/users/user.cpp @@ -93,6 +93,19 @@ void User::save() { emit_changed(); } +void User::read_lock() { + _rw_lock.read_lock(); +} +void User::read_unlock() { + _rw_lock.read_unlock(); +} +void User::write_lock() { + _rw_lock.write_lock(); +} +void User::write_unlock() { + _rw_lock.write_unlock(); +} + User::User() { _rank = 0; _banned = false; @@ -153,6 +166,11 @@ void User::_bind_methods() { ClassDB::bind_method(D_METHOD("save"), &User::save); + ClassDB::bind_method(D_METHOD("read_lock"), &User::read_lock); + ClassDB::bind_method(D_METHOD("read_unlock"), &User::read_unlock); + ClassDB::bind_method(D_METHOD("write_lock"), &User::write_lock); + ClassDB::bind_method(D_METHOD("write_unlock"), &User::write_unlock); + BIND_ENUM_CONSTANT(PERMISSION_CREATE); BIND_ENUM_CONSTANT(PERMISSION_READ); BIND_ENUM_CONSTANT(PERMISSION_UPDATE); diff --git a/modules/users/users/user.h b/modules/users/users/user.h index e6e1fb26c..77d098569 100644 --- a/modules/users/users/user.h +++ b/modules/users/users/user.h @@ -1,6 +1,7 @@ #ifndef USER_H #define USER_H +#include "core/os/rw_lock.h" #include "core/ustring.h" #include "core/resource.h" @@ -58,6 +59,11 @@ public: void save(); + void read_lock(); + void read_unlock(); + void write_lock(); + void write_unlock(); + User(); ~User(); @@ -73,6 +79,8 @@ protected: bool _banned; String _password_reset_token; bool _locked; + + RWLock _rw_lock; }; VARIANT_ENUM_CAST(User::Permissions);