MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / ServiceThreadInitialize

Function ServiceThreadInitialize

modules/piu/PC/piuService.c:277–331  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

275}
276
277void ServiceThreadInitialize(void* it, void* context)
278{
279 static xsStringValue signature = PIU_DOT_SIGNATURE;
280 ServiceThread thread = it;
281 //fprintf(stderr, "ServiceThreadInitialize thread %p\n", thread);
282 txMachine* root = &ServiceRoot;
283 txPreparation* preparation = xsPreparation();
284
285 txCreation creation = preparation->creation;
286 txCreation override = thread->creation;
287
288 if (override.initialChunkSize > 0) creation.initialChunkSize = override.initialChunkSize;
289 if (override.incrementalChunkSize > 0) creation.incrementalChunkSize = override.incrementalChunkSize;
290 if (override.initialHeapCount > 0) creation.initialHeapCount = override.initialHeapCount;
291 if (override.incrementalHeapCount > 0) creation.incrementalHeapCount = override.incrementalHeapCount;
292 if (override.stackCount > 0) creation.stackCount = override.stackCount;
293 if (override.parserBufferSize > 0) creation.parserBufferSize = override.parserBufferSize;
294
295 thread->the = fxCloneMachine(&creation, root, thread->name[0] ? thread->name : strrchr(signature, '.') + 1, context);
296 xsBeginHost(thread->the);
297 {
298 xsVars(3);
299 xsVar(0) = xsNewHostObject(NULL);
300 xsVar(1) = xsNewHostConstructor(ServiceThreadCreate, 1, xsVar(0));
301 xsVar(2) = xsNewHostObject(NULL);
302 xsSetHostData(xsVar(2), thread);
303 xsSetHostHooks(xsVar(2), &ServiceThreadHooks);
304 xsSet(xsVar(1), xsID_current, xsVar(2));
305 xsVar(2) = xsNewHostObject(NULL);
306 xsSetHostData(xsVar(2), &MainThread);
307 xsSet(xsVar(1), xsID_main, xsVar(2));
308 xsSet(xsGlobal, xsID_Thread, xsVar(1));
309 }
310 xsEndHost(thread->the);
311#if mxAndroid
312 pipe2(thread->pipe, O_NONBLOCK | O_CLOEXEC);
313 ALooper_addFd(ALooper_forThread(), thread->pipe[0], ALOOPER_POLL_CALLBACK, ALOOPER_EVENT_INPUT, ServiceThreadPerform, thread);
314#elif mxLinux
315 thread->main_context = g_main_context_get_thread_default();
316#elif mxWindows
317 thread->the->thread = thread;
318 thread->the->threadCallback = ServiceThreadPerform;
319 InitializeCriticalSection(&thread->lock);
320 if (thread->event)
321 SetEvent(thread->event);
322#else
323 CFRunLoopSourceContext runLoopSourceContext = {0, thread, NULL, NULL, NULL, NULL, NULL, ServiceThreadSchedule, NULL, ServiceThreadPerform};
324 thread->runLoop = CFRunLoopGetCurrent();
325 thread->runLoopSource = CFRunLoopSourceCreate(NULL, 0, &runLoopSourceContext);
326 CFRunLoopAddSource(thread->runLoop, thread->runLoopSource, kCFRunLoopDefaultMode);
327#endif
328#if mxInstrument
329 fxDescribeInstrumentation(thread->the, 0, NULL, NULL);
330#endif
331}
332
333txMachine* ServiceThreadMain(void* context)
334{

Callers 3

ServiceThreadLoopFunction · 0.85
ServiceThreadMainFunction · 0.85

Calls 2

fxCloneMachineFunction · 0.85

Tested by

no test coverage detected