diff options
Diffstat (limited to 'core/object/message_queue.h')
-rw-r--r-- | core/object/message_queue.h | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/core/object/message_queue.h b/core/object/message_queue.h index 2349c6d869..c6fcccbd58 100644 --- a/core/object/message_queue.h +++ b/core/object/message_queue.h @@ -45,6 +45,14 @@ public: PAGE_SIZE_BYTES = 4096 }; + struct Page { + uint8_t data[PAGE_SIZE_BYTES]; + }; + + // Needs to be public to be able to define it outside the class. + // Needs to lock because there can be multiple of these allocators in several threads. + typedef PagedAllocator<Page, true> Allocator; + private: enum { TYPE_CALL, @@ -56,21 +64,15 @@ private: FLAG_MASK = FLAG_NULL_IS_OK - 1, }; - struct Page { - uint8_t data[PAGE_SIZE_BYTES]; - }; - Mutex mutex; - typedef PagedAllocator<Page, false> Allocator; Allocator *allocator = nullptr; bool allocator_is_custom = false; LocalVector<Page *> pages; - LocalVector<uint32_t> page_messages; + LocalVector<uint32_t> page_bytes; uint32_t max_pages = 0; uint32_t pages_used = 0; - uint32_t page_offset = 0; bool flushing = false; struct Message { @@ -85,7 +87,7 @@ private: _FORCE_INLINE_ void _ensure_first_page() { if (unlikely(pages.is_empty())) { pages.push_back(allocator->alloc()); - page_messages.push_back(0); + page_bytes.push_back(0); pages_used = 1; } } @@ -140,6 +142,8 @@ public: void clear(); void statistics(); + bool has_messages() const; + bool is_flushing() const; int get_max_buffer_usage() const; @@ -148,10 +152,15 @@ public: }; class MessageQueue : public CallQueue { - static MessageQueue *singleton; + static CallQueue *main_singleton; + static thread_local CallQueue *thread_singleton; + friend class CallQueue; public: - _FORCE_INLINE_ static MessageQueue *get_singleton() { return singleton; } + _FORCE_INLINE_ static CallQueue *get_singleton() { return thread_singleton ? thread_singleton : main_singleton; } + + static void set_thread_singleton_override(CallQueue *p_thread_singleton); + MessageQueue(); ~MessageQueue(); }; |