| 468 | } |
| 469 | |
| 470 | int workerStart(modWorker worker) |
| 471 | { |
| 472 | xsMachine *the; |
| 473 | int result = 0; |
| 474 | |
| 475 | the = modCloneMachine(&worker->creation, worker->module); |
| 476 | if (!the) |
| 477 | return -1; |
| 478 | |
| 479 | #ifdef mxInstrument |
| 480 | modInstrumentMachineBegin(the, workerSampleInstrumentation, 0, NULL, NULL); |
| 481 | #endif |
| 482 | |
| 483 | xsBeginHost(the); |
| 484 | |
| 485 | xsmcVars(2); |
| 486 | |
| 487 | xsTry { |
| 488 | if (!worker->shared) { |
| 489 | xsVar(0) = xsNewHostObject(xs_emptyworker_destructor); |
| 490 | xsmcSetHostData(xsVar(0), worker); |
| 491 | xsmcSet(xsGlobal, xsID_self, xsVar(0)); |
| 492 | worker->workerPort = xsVar(0); |
| 493 | xsRemember(worker->workerPort); |
| 494 | |
| 495 | xsVar(1) = xsNewHostFunction(xs_worker_postfromworker, 1); |
| 496 | xsmcSet(xsVar(0), xsID_postMessage, xsVar(1)); |
| 497 | |
| 498 | xsVar(1) = xsNewHostFunction(xs_worker_close, 0); |
| 499 | xsmcSet(xsVar(0), xsID_close, xsVar(1)); |
| 500 | } |
| 501 | |
| 502 | xsVar(0) = xsAwaitImport(worker->module, XS_IMPORT_DEFAULT); |
| 503 | if (xsmcTest(xsVar(0)) && xsmcIsInstanceOf(xsVar(0), xsFunctionPrototype)) |
| 504 | xsCallFunction0(xsVar(0), xsGlobal); |
| 505 | |
| 506 | if (worker->shared) |
| 507 | workerDeliverConnect(the, worker, NULL, 0); |
| 508 | } |
| 509 | xsCatch { |
| 510 | result = -1; |
| 511 | } |
| 512 | xsEndHost(the); |
| 513 | |
| 514 | if (result) { |
| 515 | xsDeleteMachine(the); |
| 516 | the = NULL; |
| 517 | } |
| 518 | |
| 519 | worker->the = the; |
| 520 | |
| 521 | return result; |
| 522 | } |
| 523 | |
| 524 | void workerTerminate(xsMachine *the, modWorker worker, uint8_t *message, uint16_t messageLength) |
| 525 | { |
no test coverage detected