Added an RWLock to User.

This commit is contained in:
Relintai 2022-07-21 18:19:40 +02:00
parent 0ef9dc8fcf
commit 589844c827
2 changed files with 26 additions and 0 deletions

View File

@ -93,6 +93,19 @@ void User::save() {
emit_changed(); 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() { User::User() {
_rank = 0; _rank = 0;
_banned = false; _banned = false;
@ -153,6 +166,11 @@ void User::_bind_methods() {
ClassDB::bind_method(D_METHOD("save"), &User::save); 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_CREATE);
BIND_ENUM_CONSTANT(PERMISSION_READ); BIND_ENUM_CONSTANT(PERMISSION_READ);
BIND_ENUM_CONSTANT(PERMISSION_UPDATE); BIND_ENUM_CONSTANT(PERMISSION_UPDATE);

View File

@ -1,6 +1,7 @@
#ifndef USER_H #ifndef USER_H
#define USER_H #define USER_H
#include "core/os/rw_lock.h"
#include "core/ustring.h" #include "core/ustring.h"
#include "core/resource.h" #include "core/resource.h"
@ -58,6 +59,11 @@ public:
void save(); void save();
void read_lock();
void read_unlock();
void write_lock();
void write_unlock();
User(); User();
~User(); ~User();
@ -73,6 +79,8 @@ protected:
bool _banned; bool _banned;
String _password_reset_token; String _password_reset_token;
bool _locked; bool _locked;
RWLock _rw_lock;
}; };
VARIANT_ENUM_CAST(User::Permissions); VARIANT_ENUM_CAST(User::Permissions);