diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2020-10-09 19:28:29 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-09 19:28:29 +0200 |
commit | b724d3851a49b033a8bc24bc1c73a3aa29eb0390 (patch) | |
tree | 7d20274c657c5f154186b690c1c0a67ca0174a9f /core/thread_work_pool.h | |
parent | c35005ba25473ea8fa48aadbd1687984c76457cf (diff) | |
parent | 26f5bd245c535fec5bfdd51a0f939d0a51179d85 (diff) |
Merge pull request #42628 from reduz/particle-collisions
Implement GPU Particle Collisions
Diffstat (limited to 'core/thread_work_pool.h')
-rw-r--r-- | core/thread_work_pool.h | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/core/thread_work_pool.h b/core/thread_work_pool.h index e21d3974ee..661060aa3f 100644 --- a/core/thread_work_pool.h +++ b/core/thread_work_pool.h @@ -73,13 +73,15 @@ class ThreadWorkPool { ThreadData *threads = nullptr; uint32_t thread_count = 0; + BaseWork *current_work = nullptr; static void _thread_function(ThreadData *p_thread); public: template <class C, class M, class U> - void do_work(uint32_t p_elements, C *p_instance, M p_method, U p_userdata) { + void begin_work(uint32_t p_elements, C *p_instance, M p_method, U p_userdata) { ERR_FAIL_COND(!threads); //never initialized + ERR_FAIL_COND(current_work != nullptr); index.store(0); @@ -90,16 +92,37 @@ public: w->index = &index; w->max_elements = p_elements; + current_work = w; + for (uint32_t i = 0; i < thread_count; i++) { threads[i].work = w; threads[i].start.post(); } + } + + bool is_working() const { + return current_work != nullptr; + } + + uint32_t get_work_index() const { + return index; + } + + void end_work() { + ERR_FAIL_COND(current_work == nullptr); for (uint32_t i = 0; i < thread_count; i++) { threads[i].completed.wait(); threads[i].work = nullptr; } - memdelete(w); + memdelete(current_work); + current_work = nullptr; + } + + template <class C, class M, class U> + void do_work(uint32_t p_elements, C *p_instance, M p_method, U p_userdata) { + begin_work(p_elements, p_instance, p_method, p_userdata); + end_work(); } void init(int p_thread_count = -1); |