1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-07 12:30:27 +00:00

Modernize atomics

- Based on C++11's `atomic`
- Reworked `SafeRefCount` (based on the rewrite by @hpvb)
- Replaced free atomic functions by the new `SafeNumeric<T>`
- Replaced wrong cases of `volatile` by the new `SafeFlag`
- Platform-specific implementations no longer needed

Co-authored-by: Hein-Pieter van Braam-Stewart <hp@tmm.cx>
This commit is contained in:
Pedro J. Estébanez
2021-01-31 13:34:42 +01:00
parent 6d89f675b1
commit 4485b43a57
54 changed files with 641 additions and 676 deletions

View File

@@ -34,12 +34,12 @@
void VisualServerWrapMT::thread_exit() {
exit = true;
exit.set();
}
void VisualServerWrapMT::thread_draw(bool p_swap_buffers, double frame_step) {
if (!atomic_decrement(&draw_pending)) {
if (!draw_pending.decrement()) {
visual_server->draw(p_swap_buffers, frame_step);
}
@@ -47,7 +47,7 @@ void VisualServerWrapMT::thread_draw(bool p_swap_buffers, double frame_step) {
void VisualServerWrapMT::thread_flush() {
atomic_decrement(&draw_pending);
draw_pending.decrement();
}
void VisualServerWrapMT::_thread_callback(void *_instance) {
@@ -65,9 +65,9 @@ void VisualServerWrapMT::thread_loop() {
visual_server->init();
exit = false;
draw_thread_up = true;
while (!exit) {
exit.clear();
draw_thread_up.set();
while (!exit.is_set()) {
// flush commands one by one, until exit is requested
command_queue.wait_and_flush_one();
}
@@ -83,7 +83,7 @@ void VisualServerWrapMT::sync() {
if (create_thread) {
atomic_increment(&draw_pending);
draw_pending.increment();
command_queue.push_and_sync(this, &VisualServerWrapMT::thread_flush);
} else {
@@ -95,7 +95,7 @@ void VisualServerWrapMT::draw(bool p_swap_buffers, double frame_step) {
if (create_thread) {
atomic_increment(&draw_pending);
draw_pending.increment();
command_queue.push(this, &VisualServerWrapMT::thread_draw, p_swap_buffers, frame_step);
} else {
@@ -113,7 +113,7 @@ void VisualServerWrapMT::init() {
thread.start(_thread_callback, this);
print_verbose("VisualServerWrapMT: Starting render thread");
}
while (!draw_thread_up) {
while (!draw_thread_up.is_set()) {
OS::get_singleton()->delay_usec(1000);
}
print_verbose("VisualServerWrapMT: Finished render thread");
@@ -174,8 +174,6 @@ VisualServerWrapMT::VisualServerWrapMT(VisualServer *p_contained, bool p_create_
visual_server = p_contained;
create_thread = p_create_thread;
draw_pending = 0;
draw_thread_up = false;
pool_max_size = GLOBAL_GET("memory/limits/multithreaded_server/rid_pool_prealloc");
if (!p_create_thread) {