mirror of
https://github.com/zebrajr/ladybird.git
synced 2026-01-15 12:15:15 +00:00
LibCore: Allow checking for a ThreadEventQueue without creating one
This commit is contained in:
@@ -48,7 +48,7 @@ struct ThreadEventQueue::Private {
|
||||
static pthread_key_t s_current_thread_event_queue_key;
|
||||
static pthread_once_t s_current_thread_event_queue_key_once = PTHREAD_ONCE_INIT;
|
||||
|
||||
ThreadEventQueue& ThreadEventQueue::current()
|
||||
ThreadEventQueue* ThreadEventQueue::current_or_null()
|
||||
{
|
||||
pthread_once(&s_current_thread_event_queue_key_once, [] {
|
||||
pthread_key_create(&s_current_thread_event_queue_key, [](void* value) {
|
||||
@@ -57,7 +57,12 @@ ThreadEventQueue& ThreadEventQueue::current()
|
||||
});
|
||||
});
|
||||
|
||||
auto* ptr = static_cast<ThreadEventQueue*>(pthread_getspecific(s_current_thread_event_queue_key));
|
||||
return static_cast<ThreadEventQueue*>(pthread_getspecific(s_current_thread_event_queue_key));
|
||||
}
|
||||
|
||||
ThreadEventQueue& ThreadEventQueue::current()
|
||||
{
|
||||
auto* ptr = current_or_null();
|
||||
if (!ptr) {
|
||||
ptr = new ThreadEventQueue;
|
||||
pthread_setspecific(s_current_thread_event_queue_key, ptr);
|
||||
|
||||
@@ -20,6 +20,7 @@ class ThreadEventQueue {
|
||||
AK_MAKE_NONMOVABLE(ThreadEventQueue);
|
||||
|
||||
public:
|
||||
static ThreadEventQueue* current_or_null();
|
||||
static ThreadEventQueue& current();
|
||||
|
||||
// Process all queued events. Returns the number of events that were processed.
|
||||
|
||||
Reference in New Issue
Block a user