| 116 | #endif |
| 117 | |
| 118 | void 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 | |
| 156 | void fxWorkerMessage(void* machine, void* it) |
| 157 | { |
no test coverage detected