diff options
Diffstat (limited to 'core/templates')
-rw-r--r-- | core/templates/map.h | 2 | ||||
-rw-r--r-- | core/templates/safe_refcount.h | 1 | ||||
-rw-r--r-- | core/templates/thread_work_pool.h | 11 |
3 files changed, 11 insertions, 3 deletions
diff --git a/core/templates/map.h b/core/templates/map.h index 51a237472d..7dfee13d2c 100644 --- a/core/templates/map.h +++ b/core/templates/map.h @@ -32,7 +32,7 @@ #define MAP_H #include "core/error/error_macros.h" -#include "core/templates/set.h" +#include "core/os/memory.h" // based on the very nice implementation of rb-trees by: // https://web.archive.org/web/20120507164830/http://web.mit.edu/~emin/www/source_code/red_black_tree/index.html diff --git a/core/templates/safe_refcount.h b/core/templates/safe_refcount.h index 91a34ecd54..e9e5695f80 100644 --- a/core/templates/safe_refcount.h +++ b/core/templates/safe_refcount.h @@ -36,6 +36,7 @@ #if !defined(NO_THREADS) #include <atomic> +#include <type_traits> // Design goals for these classes: // - No automatic conversions or arithmetic operators, diff --git a/core/templates/thread_work_pool.h b/core/templates/thread_work_pool.h index 19ab1dda3a..9f7a692cc5 100644 --- a/core/templates/thread_work_pool.h +++ b/core/templates/thread_work_pool.h @@ -83,7 +83,7 @@ public: ERR_FAIL_COND(!threads); //never initialized ERR_FAIL_COND(current_work != nullptr); - index.store(0); + index.store(0, std::memory_order_release); Work<C, M, U> *w = memnew((Work<C, M, U>)); w->instance = p_instance; @@ -104,8 +104,15 @@ public: return current_work != nullptr; } + bool is_done_dispatching() const { + ERR_FAIL_COND_V(current_work == nullptr, false); + return index.load(std::memory_order_acquire) >= current_work->max_elements; + } + uint32_t get_work_index() const { - return index; + ERR_FAIL_COND_V(current_work == nullptr, 0); + uint32_t idx = index.load(std::memory_order_acquire); + return MIN(idx, current_work->max_elements); } void end_work() { |