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

Function JobSystemCreate

engine/dlib/src/dlib/jobsystem.cpp:616–660  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

614}
615
616HJobContext JobSystemCreate(const JobSystemCreateParams* create_params)
617{
618 if (create_params == 0)
619 return 0;
620
621 JobContext* context = new JobContext();
622 context->m_Initialized = 1;
623
624 context->m_ThreadContext.m_Context = context;
625 context->m_ThreadContext.m_Generation = 1;
626
627#if defined(DM_HAS_THREADS)
628 uint32_t thread_count = create_params->m_ThreadCount;
629 context->m_UseThreads = thread_count > 0;
630 if (context->m_UseThreads)
631 {
632 context->m_ThreadContext.m_Mutex = dmMutex::New();
633 context->m_ThreadContext.m_WakeupCond = dmConditionVariable::New();
634 context->m_ThreadContext.m_Run = true;
635
636 context->m_Threads.SetCapacity(thread_count);
637 context->m_Threads.SetSize(thread_count);
638
639 for (int i = 0; i < thread_count; ++i)
640 {
641 char name_buf[32];
642 const char* thread_name_prefix = create_params->m_ThreadNamePrefix ? create_params->m_ThreadNamePrefix : "defoldjob";
643 // According to doc for pthread_set_name: https://man7.org/linux/man-pages/man3/pthread_setname_np.3.html
644 assert(strlen(thread_name_prefix) < 16-3); // account for "_00"
645
646 dmSnPrintf(name_buf, sizeof(name_buf), "%s_%d", thread_name_prefix, i);
647 context->m_Threads[i] = dmThread::New(JobThread, 0x80000, (void*)&context->m_ThreadContext, name_buf);
648 }
649 }
650 else
651 {
652 context->m_ThreadContext.m_Mutex = 0;
653 context->m_ThreadContext.m_WakeupCond = 0;
654 context->m_ThreadContext.m_Run = false;
655 }
656#else
657 context->m_UseThreads = false;
658#endif
659 return context;
660}
661
662void JobSystemDestroy(HJobContext context)
663{

Callers 9

InitializeFunction · 0.85
SetUpMethod · 0.85
SetUpMethod · 0.85
engine.cppFile · 0.85
SetUpMethod · 0.85
SetUpMethod · 0.85
SetUpMethod · 0.85
SetUpMethod · 0.85
EngineCreateFunction · 0.85

Calls 5

dmSnPrintfFunction · 0.85
NewFunction · 0.70
assertFunction · 0.50
SetCapacityMethod · 0.45
SetSizeMethod · 0.45

Tested by 7

SetUpMethod · 0.68
SetUpMethod · 0.68
SetUpMethod · 0.68
SetUpMethod · 0.68
SetUpMethod · 0.68
SetUpMethod · 0.68
EngineCreateFunction · 0.68