diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/core_bind.cpp | 10 | ||||
-rw-r--r-- | core/core_bind.h | 2 | ||||
-rw-r--r-- | core/io/resource_format_binary.cpp | 3 | ||||
-rw-r--r-- | core/object/message_queue.cpp | 94 | ||||
-rw-r--r-- | core/object/message_queue.h | 2 | ||||
-rw-r--r-- | core/object/worker_thread_pool.h | 21 | ||||
-rw-r--r-- | core/os/os.cpp | 4 | ||||
-rw-r--r-- | core/os/os.h | 3 | ||||
-rw-r--r-- | core/string/print_string.cpp | 2 |
9 files changed, 95 insertions, 46 deletions
diff --git a/core/core_bind.cpp b/core/core_bind.cpp index 2d0d24406c..a73b198be2 100644 --- a/core/core_bind.cpp +++ b/core/core_bind.cpp @@ -442,6 +442,10 @@ bool OS::has_feature(const String &p_feature) const { } } +bool OS::is_sandboxed() const { + return ::OS::get_singleton()->is_sandboxed(); +} + uint64_t OS::get_static_memory_usage() const { return ::OS::get_singleton()->get_static_memory_usage(); } @@ -545,6 +549,10 @@ Vector<String> OS::get_granted_permissions() const { return ::OS::get_singleton()->get_granted_permissions(); } +void OS::revoke_granted_permissions() { + ::OS::get_singleton()->revoke_granted_permissions(); +} + String OS::get_unique_id() const { return ::OS::get_singleton()->get_unique_id(); } @@ -636,10 +644,12 @@ void OS::_bind_methods() { ClassDB::bind_method(D_METHOD("get_main_thread_id"), &OS::get_main_thread_id); ClassDB::bind_method(D_METHOD("has_feature", "tag_name"), &OS::has_feature); + ClassDB::bind_method(D_METHOD("is_sandboxed"), &OS::is_sandboxed); ClassDB::bind_method(D_METHOD("request_permission", "name"), &OS::request_permission); ClassDB::bind_method(D_METHOD("request_permissions"), &OS::request_permissions); ClassDB::bind_method(D_METHOD("get_granted_permissions"), &OS::get_granted_permissions); + ClassDB::bind_method(D_METHOD("revoke_granted_permissions"), &OS::revoke_granted_permissions); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "low_processor_usage_mode"), "set_low_processor_usage_mode", "is_in_low_processor_usage_mode"); ADD_PROPERTY(PropertyInfo(Variant::INT, "low_processor_usage_mode_sleep_usec"), "set_low_processor_usage_mode_sleep_usec", "get_low_processor_usage_mode_sleep_usec"); diff --git a/core/core_bind.h b/core/core_bind.h index 6b25510b14..077bb19c80 100644 --- a/core/core_bind.h +++ b/core/core_bind.h @@ -234,10 +234,12 @@ public: Thread::ID get_main_thread_id() const; bool has_feature(const String &p_feature) const; + bool is_sandboxed() const; bool request_permission(const String &p_name); bool request_permissions(); Vector<String> get_granted_permissions() const; + void revoke_granted_permissions(); static OS *get_singleton() { return singleton; } diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index 3037f603c4..adae468d93 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -1960,6 +1960,8 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant return; } + resource_set.insert(res); + List<PropertyInfo> property_list; res->get_property_list(&property_list); @@ -1983,7 +1985,6 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant } } - resource_set.insert(res); saved_resources.push_back(res); } break; diff --git a/core/object/message_queue.cpp b/core/object/message_queue.cpp index 18ba5d5b30..506f8291eb 100644 --- a/core/object/message_queue.cpp +++ b/core/object/message_queue.cpp @@ -222,62 +222,66 @@ void CallQueue::_call_function(const Callable &p_callable, const Variant *p_args } } -Error CallQueue::flush() { - LOCK_MUTEX; - - // Thread overrides are not meant to be flushed, but appended to the main one. - if (this == MessageQueue::thread_singleton) { - if (pages.size() == 0) { - return OK; - } +Error CallQueue::_transfer_messages_to_main_queue() { + if (pages.size() == 0) { + return OK; + } - CallQueue *mq = MessageQueue::main_singleton; - DEV_ASSERT(!mq->allocator_is_custom && !allocator_is_custom); // Transferring pages is only safe if using the same alloator parameters. - - mq->mutex.lock(); - - // Here we're transferring the data from this queue to the main one. - // However, it's very unlikely big amounts of messages will be queued here, - // so PagedArray/Pool would be overkill. Also, in most cases the data will fit - // an already existing page of the main queue. - - // Let's see if our first (likely only) page fits the current target queue page. - uint32_t src_page = 0; - { - if (mq->pages_used) { - uint32_t dst_page = mq->pages_used - 1; - uint32_t dst_offset = mq->page_bytes[dst_page]; - if (dst_offset + page_bytes[0] < uint32_t(PAGE_SIZE_BYTES)) { - memcpy(mq->pages[dst_page]->data + dst_offset, pages[0]->data, page_bytes[0]); - mq->page_bytes[dst_page] += page_bytes[0]; - src_page++; - } + CallQueue *mq = MessageQueue::main_singleton; + DEV_ASSERT(!mq->allocator_is_custom && !allocator_is_custom); // Transferring pages is only safe if using the same alloator parameters. + + mq->mutex.lock(); + + // Here we're transferring the data from this queue to the main one. + // However, it's very unlikely big amounts of messages will be queued here, + // so PagedArray/Pool would be overkill. Also, in most cases the data will fit + // an already existing page of the main queue. + + // Let's see if our first (likely only) page fits the current target queue page. + uint32_t src_page = 0; + { + if (mq->pages_used) { + uint32_t dst_page = mq->pages_used - 1; + uint32_t dst_offset = mq->page_bytes[dst_page]; + if (dst_offset + page_bytes[0] < uint32_t(PAGE_SIZE_BYTES)) { + memcpy(mq->pages[dst_page]->data + dst_offset, pages[0]->data, page_bytes[0]); + mq->page_bytes[dst_page] += page_bytes[0]; + src_page++; } } + } - // Any other possibly existing source page needs to be added. + // Any other possibly existing source page needs to be added. - if (mq->pages_used + (pages_used - src_page) > mq->max_pages) { - ERR_PRINT("Failed appending thread queue. Message queue out of memory. " + mq->error_text); - mq->statistics(); - mq->mutex.unlock(); - return ERR_OUT_OF_MEMORY; - } + if (mq->pages_used + (pages_used - src_page) > mq->max_pages) { + ERR_PRINT("Failed appending thread queue. Message queue out of memory. " + mq->error_text); + mq->statistics(); + mq->mutex.unlock(); + return ERR_OUT_OF_MEMORY; + } - for (; src_page < pages_used; src_page++) { - mq->_add_page(); - memcpy(mq->pages[mq->pages_used - 1]->data, pages[src_page]->data, page_bytes[src_page]); - mq->page_bytes[mq->pages_used - 1] = page_bytes[src_page]; - } + for (; src_page < pages_used; src_page++) { + mq->_add_page(); + memcpy(mq->pages[mq->pages_used - 1]->data, pages[src_page]->data, page_bytes[src_page]); + mq->page_bytes[mq->pages_used - 1] = page_bytes[src_page]; + } - mq->mutex.unlock(); + mq->mutex.unlock(); - page_bytes[0] = 0; - pages_used = 1; + page_bytes[0] = 0; + pages_used = 1; - return OK; + return OK; +} + +Error CallQueue::flush() { + // Thread overrides are not meant to be flushed, but appended to the main one. + if (unlikely(this == MessageQueue::thread_singleton)) { + return _transfer_messages_to_main_queue(); } + LOCK_MUTEX; + if (pages.size() == 0) { // Never allocated UNLOCK_MUTEX; diff --git a/core/object/message_queue.h b/core/object/message_queue.h index 9f567e4dd0..c2f4ad1643 100644 --- a/core/object/message_queue.h +++ b/core/object/message_queue.h @@ -98,6 +98,8 @@ private: } } + Error _transfer_messages_to_main_queue(); + void _add_page(); void _call_function(const Callable &p_callable, const Variant *p_args, int p_argcount, bool p_show_error); diff --git a/core/object/worker_thread_pool.h b/core/object/worker_thread_pool.h index d4d9387765..9fe8497eaf 100644 --- a/core/object/worker_thread_pool.h +++ b/core/object/worker_thread_pool.h @@ -202,4 +202,25 @@ public: ~WorkerThreadPool(); }; +template <typename F> +static _FORCE_INLINE_ void for_range(int i_begin, int i_end, bool parallel, String name, F f) { + if (!parallel) { + for (int i = i_begin; i < i_end; i++) { + f(i); + } + return; + } + + auto wrapper = [&](int i, void *unused) { + f(i + i_begin); + }; + + WorkerThreadPool *wtp = WorkerThreadPool::get_singleton(); + WorkerThreadPool::GroupID gid = wtp->add_template_group_task( + &wrapper, &decltype(wrapper)::operator(), nullptr, + i_end - i_begin, -1, + true, name); + wtp->wait_for_group_task_completion(gid); +} + #endif // WORKER_THREAD_POOL_H diff --git a/core/os/os.cpp b/core/os/os.cpp index 67423128a3..38ea4a0fdd 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -505,6 +505,10 @@ bool OS::has_feature(const String &p_feature) { return false; } +bool OS::is_sandboxed() const { + return false; +} + void OS::set_restart_on_exit(bool p_restart, const List<String> &p_restart_arguments) { restart_on_exit = p_restart; restart_commandline = p_restart_arguments; diff --git a/core/os/os.h b/core/os/os.h index f2787d6381..965dc1f912 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -295,6 +295,8 @@ public: bool has_feature(const String &p_feature); + virtual bool is_sandboxed() const; + void set_has_server_feature_callback(HasServerFeatureCallback p_callback); void set_restart_on_exit(bool p_restart, const List<String> &p_restart_arguments); @@ -304,6 +306,7 @@ public: virtual bool request_permission(const String &p_name) { return true; } virtual bool request_permissions() { return true; } virtual Vector<String> get_granted_permissions() const { return Vector<String>(); } + virtual void revoke_granted_permissions() {} // For recording / measuring benchmark data. Only enabled with tools void set_use_benchmark(bool p_use_benchmark); diff --git a/core/string/print_string.cpp b/core/string/print_string.cpp index 7b90710308..dcdde3c175 100644 --- a/core/string/print_string.cpp +++ b/core/string/print_string.cpp @@ -164,6 +164,8 @@ void __print_line_rich(String p_string) { p_string_ansi = p_string_ansi.replace("[/fgcolor]", "\u001b[39;49m"); } + p_string_ansi += "\u001b[0m"; // Reset. + OS::get_singleton()->print_rich("%s\n", p_string_ansi.utf8().get_data()); _global_lock(); |