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

Function workerConstructor

modules/base/worker/modWorker.c:159–360  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

157}
158
159static void workerConstructor(xsMachine *the, xsBooleanValue shared)
160{
161 modCriticalSectionDeclare;
162 modWorker worker;
163 char *module = xsmcToString(xsArg(0));
164#ifdef INC_FREERTOS_H
165 xsIntegerValue priority = 0, core = -1; // core tskNO_AFFINITY
166#endif
167
168 xsmcVars(2);
169
170 worker = c_calloc(sizeof(modWorkerRecord) + c_strlen(module), 1);
171 if (!worker)
172 xsUnknownError("no memory");
173
174 worker->parent = the;
175 worker->owner = xsThis;
176 c_strcpy(worker->module, module);
177 worker->shared = shared;
178
179 if (!shared)
180 worker->ownerPort = xsThis;
181 else {
182 xsVar(0) = xsNewHostObject(xs_emptyworker_destructor);
183 xsmcSetHostData(xsVar(0), worker);
184 worker->ownerPort = xsVar(0);
185 xsmcSet(xsThis, xsID_port, xsVar(0));
186
187 xsVar(1) = xsNewHostFunction(xs_worker_postfromsharedinstantiator, 1);
188 xsmcSet(xsVar(0), xsID_postMessage, xsVar(1));
189 }
190
191 xsmcSetHostData(xsThis, worker);
192
193 if (shared) {
194 modWorker walker, target = NULL;
195
196 modCriticalSectionBegin();
197 for (walker = gWorkers; NULL != walker; walker = walker->next) {
198 if (!walker->shared || (0 != c_strcmp(walker->module, worker->module)))
199 continue;
200 target = walker;
201 break;
202 }
203
204 modCriticalSectionEnd();
205
206 if (target) {
207 worker->the = target->the;
208#ifdef INC_FREERTOS_H
209 worker->task = target->task;
210#elif __ZEPHYR__
211 worker->thread = target->thread; //@@
212 worker->stack = target->stack;
213 worker->threadID = target->threadID;
214#endif
215 doModMessagePostToMachine(the, worker->the, NULL, (modMessageDeliver)workerDeliverConnect, worker);
216 goto done;

Callers 2

xs_workerFunction · 0.85
xs_sharedworkerFunction · 0.85

Calls 4

getIntegerPropertyFunction · 0.85
workerStartFunction · 0.85
modMachineTaskWaitFunction · 0.50

Tested by

no test coverage detected