Added the ability to request a write lock on the tree.

This commit is contained in:
Relintai 2022-02-10 16:47:18 +01:00
parent a7b8d0621c
commit 26d161fd26
4 changed files with 26 additions and 3 deletions

View File

@ -18,6 +18,8 @@ public:
NOTIFICATION_CHILD_ADDED = 4,
NOTIFICATION_CHILD_REMOVED = 5,
NOTIFICATION_CHILD_MOVED = 6,
NOTIFICATION_UPDATE = 7,
NOTIFICATION_TREE_WRITE_LOCKED = 8,
};
bool is_in_tree() const;

View File

@ -19,8 +19,24 @@ void NodeTree::set_root(Node *root) {
}
}
void NodeTree::send_update(float delta) {
// todo
void NodeTree::update() {
if (!_root_node) {
return;
}
_root_node->notification(Node::NOTIFICATION_UPDATE);
if (_write_lock_requested) {
_rw_lock.write_lock();
_root_node->notification(Node::NOTIFICATION_TREE_WRITE_LOCKED);
_rw_lock.write_unlock();
}
}
void NodeTree::_send_update() {
if (_root_node) {
_root_node->notification(Node::NOTIFICATION_UPDATE);
}
}
NodeTree::NodeTree() :

View File

@ -13,7 +13,7 @@ public:
Node *get_root();
virtual void set_root(Node *root);
virtual void send_update(float delta);
virtual void update();
void request_write_lock();
@ -21,8 +21,11 @@ public:
~NodeTree();
protected:
virtual void _send_update();
Node *_root_node;
float _update_interval;
bool _write_lock_requested;
RWLock _rw_lock;
};

View File

@ -20,7 +20,9 @@ void WebServer::set_root(Node *root) {
void WebServer::handle_request(Request *request) {
ERR_FAIL_COND(!_web_root);
_rw_lock.read_lock();
_web_root->handle_request_main(request);
_rw_lock.read_unlock();
}