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

Function fxWorkerInitialize

modules/base/worker/pcWorker.c:118–154  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

116#endif
117
118void fxWorkerInitialize(txWorker* worker)
119{
120 void* preparation = xsPreparation();
121 worker->machine = fxPrepareMachine(NULL, preparation, worker->name, worker, NULL);
122 worker->machine->host = worker->ownerMachine->host;
123 fxSetArchive(worker->machine, worker->ownerMachine->archive);
124 xsBeginHost(worker->machine);
125 {
126 xsVars(3);
127 xsVar(0) = xsNewHostObject(NULL);
128 xsSetHostData(xsVar(0), worker);
129 xsVar(1) = xsNewHostFunction(xs_worker_postfromworker, 1);
130 xsSet(xsVar(0), xsID_postMessage, xsVar(1));
131// xsVar(1) = xsNewHostFunction(xs_worker_close, 0);
132// xsSet(xsVar(0), xsID_close, xsVar(1));
133 xsSet(xsGlobal, xsID_self, xsVar(0));
134 worker->reference = xsVar(0);
135 xsRemember(worker->reference);
136
137 xsVar(0) = xsAwaitImport(worker->name, XS_IMPORT_DEFAULT);
138 if (xsTest(xsVar(0)) && xsIsInstanceOf(xsVar(0), xsFunctionPrototype))
139 xsCallFunction0(xsVar(0), xsGlobal);
140 }
141 xsEndHost(worker->machine);
142#if defined(mxInstrument) && mxMacOSX
143 fxDescribeInstrumentation(worker->machine, 0, NULL, NULL);
144
145 CFRunLoopTimerContext context = {0};
146 context.info = worker->machine;
147 worker->cfTimer = CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent() + 1.0, 1.0, 0, 0, fxWorkerInstrumentationTimer, &context);
148 CFRunLoopAddTimer(CFRunLoopGetCurrent(), worker->cfTimer, kCFRunLoopCommonModes);
149#endif
150 mxLockMutex(&worker->runningMutex);
151 worker->running = 1;
152 mxSignalCondition(&worker->runningCondition);
153 mxUnlockMutex(&worker->runningMutex);
154}
155
156void fxWorkerMessage(void* machine, void* it)
157{

Callers 1

fxWorkerLoopFunction · 0.85

Calls 3

fxPrepareMachineFunction · 0.85
fxSetArchiveFunction · 0.85

Tested by

no test coverage detected