MCPcopy Create free account
hub / github.com/defold/defold / InternalDispatch

Function InternalDispatch

engine/dlib/src/dlib/message.cpp:545–610  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

543 }
544
545 uint32_t InternalDispatch(HSocket socket, DispatchCallback dispatch_callback, void* user_ptr, bool blocking)
546 {
547 MessageSocket* s = AcquireSocket(socket);
548 if (s == 0)
549 {
550 return 0;
551 }
552
553 dmMutex::Lock(s->m_Mutex);
554
555 MemoryAllocator* allocator = &s->m_Allocator;
556
557 if (!s->m_Header)
558 {
559 if (blocking) {
560 dmConditionVariable::Wait(s->m_Condition, s->m_Mutex);
561 } else {
562 dmMutex::Unlock(s->m_Mutex);
563 ReleaseSocket(s);
564 return 0;
565 }
566 }
567
568
569 char buffer[128];
570 const char* profiler_string = GetProfilerString(s->m_Name, buffer, sizeof(buffer));
571 DM_PROFILE_DYN(profiler_string, 0);
572
573 uint32_t dispatch_count = 0;
574
575 Message *message_object = s->m_Header;
576 s->m_Header = 0;
577 s->m_Tail = 0;
578
579 // Unlink full pages
580 MemoryPage* full_pages = allocator->m_FullPages;
581 allocator->m_FullPages = 0;
582
583 dmMutex::Unlock(s->m_Mutex);
584
585 while (message_object)
586 {
587 dispatch_callback(message_object, user_ptr);
588 if (message_object->m_DestroyCallback) {
589 message_object->m_DestroyCallback(message_object);
590 }
591 message_object = message_object->m_Next;
592 dispatch_count++;
593 }
594
595 // Reclaim all full pages active when dispatch started
596 dmMutex::Lock(s->m_Mutex);
597 MemoryPage* p = full_pages;
598 while (p)
599 {
600 MemoryPage* next = p->m_NextPage;
601 p->m_NextPage = allocator->m_FreePages;
602 allocator->m_FreePages = p;

Callers 2

DispatchFunction · 0.85
DispatchBlockingFunction · 0.85

Calls 6

AcquireSocketFunction · 0.85
ReleaseSocketFunction · 0.85
LockFunction · 0.70
WaitFunction · 0.70
UnlockFunction · 0.70
GetProfilerStringFunction · 0.70

Tested by

no test coverage detected