all repos — mgba @ 31b9100f381fb7ee75ba8ee006a86ab65e6e0b35

mGBA Game Boy Advance Emulator

src/platform/qt/CoreController.cpp (view raw)

  1/* Copyright (c) 2013-2017 Jeffrey Pfau
  2 *
  3 * This Source Code Form is subject to the terms of the Mozilla Public
  4 * License, v. 2.0. If a copy of the MPL was not distributed with this
  5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  6#include "CoreController.h"
  7
  8#include "ConfigController.h"
  9#include "InputController.h"
 10#include "LogController.h"
 11#include "MultiplayerController.h"
 12#include "Override.h"
 13
 14#include <QDateTime>
 15#include <QMutexLocker>
 16
 17#include <mgba/core/serialize.h>
 18#include <mgba/feature/video-logger.h>
 19#ifdef M_CORE_GBA
 20#include <mgba/internal/gba/gba.h>
 21#include <mgba/internal/gba/renderers/tile-cache.h>
 22#include <mgba/internal/gba/sharkport.h>
 23#endif
 24#ifdef M_CORE_GB
 25#include <mgba/internal/gb/gb.h>
 26#include <mgba/internal/gb/renderers/tile-cache.h>
 27#endif
 28#include <mgba-util/vfs.h>
 29
 30using namespace QGBA;
 31
 32
 33CoreController::CoreController(mCore* core, QObject* parent)
 34	: QObject(parent)
 35	, m_saveStateFlags(SAVESTATE_SCREENSHOT | SAVESTATE_SAVEDATA | SAVESTATE_CHEATS | SAVESTATE_RTC)
 36	, m_loadStateFlags(SAVESTATE_SCREENSHOT | SAVESTATE_RTC)
 37{
 38	m_threadContext.core = core;
 39	m_threadContext.userData = this;
 40
 41	QSize size = screenDimensions();
 42	m_buffers[0].resize(size.width() * size.height() * sizeof(color_t));
 43	m_buffers[1].resize(size.width() * size.height() * sizeof(color_t));
 44	m_activeBuffer = &m_buffers[0];
 45
 46	m_threadContext.core->setVideoBuffer(m_threadContext.core, reinterpret_cast<color_t*>(m_activeBuffer->data()), size.width());
 47
 48	m_threadContext.startCallback = [](mCoreThread* context) {
 49		CoreController* controller = static_cast<CoreController*>(context->userData);
 50
 51		switch (context->core->platform(context->core)) {
 52#ifdef M_CORE_GBA
 53		case PLATFORM_GBA:
 54			context->core->setPeripheral(context->core, mPERIPH_GBA_LUMINANCE, controller->m_inputController->luminance());
 55			break;
 56#endif
 57		default:
 58			break;
 59		}
 60
 61		if (controller->m_override) {
 62			controller->m_override->identify(context->core);
 63			controller->m_override->apply(context->core);
 64		}
 65
 66		if (mCoreLoadState(context->core, 0, controller->m_loadStateFlags)) {
 67			mCoreDeleteState(context->core, 0);
 68		}
 69
 70		if (controller->m_multiplayer) {
 71			controller->m_multiplayer->attachGame(controller);
 72		}
 73
 74		QMetaObject::invokeMethod(controller, "started");
 75	};
 76
 77	m_threadContext.resetCallback = [](mCoreThread* context) {
 78		CoreController* controller = static_cast<CoreController*>(context->userData);
 79		for (auto action : controller->m_resetActions) {
 80			action();
 81		}
 82		controller->m_resetActions.clear();
 83
 84		controller->m_activeBuffer->fill(0xFF);
 85		controller->finishFrame();
 86	};
 87
 88	m_threadContext.frameCallback = [](mCoreThread* context) {
 89		CoreController* controller = static_cast<CoreController*>(context->userData);
 90
 91		controller->finishFrame();
 92	};
 93
 94	m_threadContext.cleanCallback = [](mCoreThread* context) {
 95		CoreController* controller = static_cast<CoreController*>(context->userData);
 96
 97		controller->clearMultiplayerController();
 98		QMetaObject::invokeMethod(controller, "stopping");
 99	};
100
101	m_threadContext.logger.d.log = [](mLogger* logger, int category, enum mLogLevel level, const char* format, va_list args) {
102		mThreadLogger* logContext = reinterpret_cast<mThreadLogger*>(logger);
103		mCoreThread* context = logContext->p;
104
105		static const char* savestateMessage = "State %i loaded";
106		static const char* savestateFailedMessage = "State %i failed to load";
107		static int biosCat = -1;
108		static int statusCat = -1;
109		if (!context) {
110			return;
111		}
112		CoreController* controller = static_cast<CoreController*>(context->userData);
113		QString message;
114		if (biosCat < 0) {
115			biosCat = mLogCategoryById("gba.bios");
116		}
117		if (statusCat < 0) {
118			statusCat = mLogCategoryById("core.status");
119		}
120#ifdef M_CORE_GBA
121		if (level == mLOG_STUB && category == biosCat) {
122			va_list argc;
123			va_copy(argc, args);
124			int immediate = va_arg(argc, int);
125			va_end(argc);
126			QMetaObject::invokeMethod(controller, "unimplementedBiosCall", Q_ARG(int, immediate));
127		} else
128#endif
129		if (category == statusCat) {
130			// Slot 0 is reserved for suspend points
131			if (strncmp(savestateMessage, format, strlen(savestateMessage)) == 0) {
132				va_list argc;
133				va_copy(argc, args);
134				int slot = va_arg(argc, int);
135				va_end(argc);
136				if (slot == 0) {
137					format = "Loaded suspend state";
138				}
139			} else if (strncmp(savestateFailedMessage, format, strlen(savestateFailedMessage)) == 0) {
140				va_list argc;
141				va_copy(argc, args);
142				int slot = va_arg(argc, int);
143				va_end(argc);
144				if (slot == 0) {
145					return;
146				}
147			}
148			message = QString().vsprintf(format, args);
149			QMetaObject::invokeMethod(controller, "statusPosted", Q_ARG(const QString&, message));
150		}
151		if (level == mLOG_FATAL) {
152			mCoreThreadMarkCrashed(controller->thread());
153			QMetaObject::invokeMethod(controller, "crashed", Q_ARG(const QString&, QString().vsprintf(format, args)));
154		}
155		message = QString().vsprintf(format, args);
156		QMetaObject::invokeMethod(controller, "logPosted", Q_ARG(int, level), Q_ARG(int, category), Q_ARG(const QString&, message));
157	};
158}
159
160CoreController::~CoreController() {
161	endVideoLog();
162	stop();
163	disconnect();
164
165	if (m_tileCache) {
166		mTileCacheDeinit(m_tileCache.get());
167		m_tileCache.reset();
168	}
169
170	mCoreThreadJoin(&m_threadContext);
171
172	mCoreConfigDeinit(&m_threadContext.core->config);
173	m_threadContext.core->deinit(m_threadContext.core);
174}
175
176color_t* CoreController::drawContext() {
177	QMutexLocker locker(&m_mutex);
178	if (!m_completeBuffer) {
179		return nullptr;
180	}
181	return reinterpret_cast<color_t*>(m_completeBuffer->data());
182}
183
184bool CoreController::isPaused() {
185	return mCoreThreadIsPaused(&m_threadContext);
186}
187
188mPlatform CoreController::platform() const {
189	return m_threadContext.core->platform(m_threadContext.core);
190}
191
192QSize CoreController::screenDimensions() const {
193	unsigned width, height;
194	m_threadContext.core->desiredVideoDimensions(m_threadContext.core, &width, &height);
195
196	return QSize(width, height);
197}
198
199void CoreController::loadConfig(ConfigController* config) {
200	Interrupter interrupter(this);
201	m_loadStateFlags = config->getOption("loadStateExtdata").toInt();
202	m_saveStateFlags = config->getOption("saveStateExtdata").toInt();
203	m_fastForwardRatio = config->getOption("fastForwardRatio").toFloat();
204	m_videoSync = config->getOption("videoSync").toInt();
205	m_audioSync = config->getOption("audioSync").toInt();
206	m_fpsTarget = config->getOption("fpsTarget").toFloat();
207	updateFastForward();
208	mCoreLoadForeignConfig(m_threadContext.core, config->config());
209	mCoreThreadRewindParamsChanged(&m_threadContext);
210}
211
212#ifdef USE_DEBUGGERS
213void CoreController::setDebugger(mDebugger* debugger) {
214	Interrupter interrupter(this);
215	if (debugger) {
216		mDebuggerAttach(debugger, m_threadContext.core);
217	} else {
218		m_threadContext.core->detachDebugger(m_threadContext.core);
219	}
220}
221#endif
222
223void CoreController::setMultiplayerController(MultiplayerController* controller) {
224	if (controller == m_multiplayer) {
225		return;
226	}
227	clearMultiplayerController();
228	m_multiplayer = controller;
229	if (!mCoreThreadHasStarted(&m_threadContext)) {
230		return;
231	}
232	mCoreThreadRunFunction(&m_threadContext, [](mCoreThread* thread) {
233		CoreController* controller = static_cast<CoreController*>(thread->userData);
234		controller->m_multiplayer->attachGame(controller);
235	});
236}
237
238void CoreController::clearMultiplayerController() {
239	if (!m_multiplayer) {
240		return;
241	}
242	m_multiplayer->detachGame(this);
243	m_multiplayer = nullptr;
244}
245
246mTileCache* CoreController::tileCache() {
247	if (m_tileCache) {
248		return m_tileCache.get();
249	}
250	Interrupter interrupter(this);
251	switch (platform()) {
252#ifdef M_CORE_GBA
253	case PLATFORM_GBA: {
254		GBA* gba = static_cast<GBA*>(m_threadContext.core->board);
255		m_tileCache = std::make_unique<mTileCache>();
256		GBAVideoTileCacheInit(m_tileCache.get());
257		GBAVideoTileCacheAssociate(m_tileCache.get(), &gba->video);
258		mTileCacheSetPalette(m_tileCache.get(), 0);
259		break;
260	}
261#endif
262#ifdef M_CORE_GB
263	case PLATFORM_GB: {
264		GB* gb = static_cast<GB*>(m_threadContext.core->board);
265		m_tileCache = std::make_unique<mTileCache>();
266		GBVideoTileCacheInit(m_tileCache.get());
267		GBVideoTileCacheAssociate(m_tileCache.get(), &gb->video);
268		mTileCacheSetPalette(m_tileCache.get(), 0);
269		break;
270	}
271#endif
272	default:
273		return nullptr;
274	}
275	return m_tileCache.get();
276}
277
278void CoreController::setOverride(std::unique_ptr<Override> override) {
279	Interrupter interrupter(this);
280	m_override = std::move(override);
281	m_override->identify(m_threadContext.core);
282}
283
284void CoreController::setInputController(InputController* inputController) {
285	m_inputController = inputController;
286	m_threadContext.core->setPeripheral(m_threadContext.core, mPERIPH_ROTATION, m_inputController->rotationSource());
287	m_threadContext.core->setPeripheral(m_threadContext.core, mPERIPH_RUMBLE, m_inputController->rumble());
288	m_threadContext.core->setPeripheral(m_threadContext.core, mPERIPH_IMAGE_SOURCE, m_inputController->imageSource());
289}
290
291void CoreController::setLogger(LogController* logger) {
292	disconnect(m_log);
293	m_log = logger;
294	m_threadContext.logger.d.filter = logger->filter();
295	connect(this, &CoreController::logPosted, m_log, &LogController::postLog);
296}
297
298void CoreController::start() {
299	if (!m_patched) {
300		mCoreAutoloadPatch(m_threadContext.core);
301	}
302	if (!mCoreThreadStart(&m_threadContext)) {
303		emit failed();
304		emit stopping();
305	}
306}
307
308void CoreController::stop() {
309#ifdef USE_DEBUGGERS
310	setDebugger(nullptr);
311#endif
312	setPaused(false);
313	mCoreThreadEnd(&m_threadContext);
314	emit stopping();
315}
316
317void CoreController::reset() {
318	bool wasPaused = isPaused();
319	setPaused(false);
320	Interrupter interrupter(this);
321	mCoreThreadReset(&m_threadContext);
322	if (wasPaused) {
323		setPaused(true);
324	}
325}
326
327void CoreController::setPaused(bool paused) {
328	if (paused == isPaused()) {
329		return;
330	}
331	if (paused) {
332		QMutexLocker locker(&m_mutex);
333		m_frameActions.append([this]() {
334			mCoreThreadPauseFromThread(&m_threadContext);
335			QMetaObject::invokeMethod(this, "paused");
336		});
337	} else {
338		mCoreThreadUnpause(&m_threadContext);
339		emit unpaused();
340	}
341}
342
343void CoreController::frameAdvance() {
344	QMutexLocker locker(&m_mutex);
345	m_frameActions.append([this]() {
346		mCoreThreadPauseFromThread(&m_threadContext);
347	});
348	setPaused(false);
349}
350
351void CoreController::setSync(bool sync) {
352	if (sync) {
353		m_threadContext.impl->sync.audioWait = m_audioSync;
354		m_threadContext.impl->sync.videoFrameWait = m_videoSync;
355	} else {
356		m_threadContext.impl->sync.audioWait = false;
357		m_threadContext.impl->sync.videoFrameWait = false;
358	}
359}
360
361void CoreController::setRewinding(bool rewind) {
362	if (!m_threadContext.core->opts.rewindEnable) {
363		return;
364	}
365	if (rewind && m_multiplayer && m_multiplayer->attached() > 1) {
366		return;
367	}
368
369	if (rewind && isPaused()) {
370		setPaused(false);
371		// TODO: restore autopausing
372	}
373	mCoreThreadSetRewinding(&m_threadContext, rewind);
374}
375
376void CoreController::rewind(int states) {
377	{
378		Interrupter interrupter(this);
379		if (!states) {
380			states = INT_MAX;
381		}
382		for (int i = 0; i < states; ++i) {
383			if (!mCoreRewindRestore(&m_threadContext.impl->rewind, m_threadContext.core)) {
384				break;
385			}
386		}
387	}
388	emit frameAvailable();
389	emit rewound();
390}
391
392void CoreController::setFastForward(bool enable) {
393	m_fastForward = enable;
394	updateFastForward();
395}
396
397void CoreController::forceFastForward(bool enable) {
398	m_fastForwardForced = enable;
399	updateFastForward();
400}
401
402void CoreController::loadState(int slot) {
403	if (slot > 0 && slot != m_stateSlot) {
404		m_stateSlot = slot;
405		m_backupSaveState.clear();
406	}
407	mCoreThreadRunFunction(&m_threadContext, [](mCoreThread* context) {
408		CoreController* controller = static_cast<CoreController*>(context->userData);
409		if (!controller->m_backupLoadState.isOpen()) {
410			controller->m_backupLoadState = VFileMemChunk(nullptr, 0);
411		}
412		mCoreSaveStateNamed(context->core, controller->m_backupLoadState, controller->m_saveStateFlags);
413		if (mCoreLoadState(context->core, controller->m_stateSlot, controller->m_loadStateFlags)) {
414			emit controller->frameAvailable();
415			emit controller->stateLoaded();
416		}
417	});
418}
419
420void CoreController::saveState(int slot) {
421	if (slot > 0) {
422		m_stateSlot = slot;
423	}
424	mCoreThreadRunFunction(&m_threadContext, [](mCoreThread* context) {
425		CoreController* controller = static_cast<CoreController*>(context->userData);
426		VFile* vf = mCoreGetState(context->core, controller->m_stateSlot, false);
427		if (vf) {
428			controller->m_backupSaveState.resize(vf->size(vf));
429			vf->read(vf, controller->m_backupSaveState.data(), controller->m_backupSaveState.size());
430			vf->close(vf);
431		}
432		mCoreSaveState(context->core, controller->m_stateSlot, controller->m_saveStateFlags);
433	});
434}
435
436void CoreController::loadBackupState() {
437	if (!m_backupLoadState.isOpen()) {
438		return;
439	}
440
441	mCoreThreadRunFunction(&m_threadContext, [](mCoreThread* context) {
442		CoreController* controller = static_cast<CoreController*>(context->userData);
443		controller->m_backupLoadState.seek(0);
444		if (mCoreLoadStateNamed(context->core, controller->m_backupLoadState, controller->m_loadStateFlags)) {
445			mLOG(STATUS, INFO, "Undid state load");
446			controller->frameAvailable();
447			controller->stateLoaded();
448		}
449		controller->m_backupLoadState.close();
450	});
451}
452
453void CoreController::saveBackupState() {
454	if (m_backupSaveState.isEmpty()) {
455		return;
456	}
457
458	mCoreThreadRunFunction(&m_threadContext, [](mCoreThread* context) {
459		CoreController* controller = static_cast<CoreController*>(context->userData);
460		VFile* vf = mCoreGetState(context->core, controller->m_stateSlot, true);
461		if (vf) {
462			vf->write(vf, controller->m_backupSaveState.constData(), controller->m_backupSaveState.size());
463			vf->close(vf);
464			mLOG(STATUS, INFO, "Undid state save");
465		}
466		controller->m_backupSaveState.clear();
467	});
468}
469
470void CoreController::loadSave(const QString& path, bool temporary) {
471	m_resetActions.append([this, path, temporary]() {
472		VFile* vf = VFileDevice::open(path, temporary ? O_RDONLY : O_RDWR);
473		if (!vf) {
474			LOG(QT, ERROR) << tr("Failed to open save file: %1").arg(path);
475			return;
476		}
477
478		if (temporary) {
479			m_threadContext.core->loadTemporarySave(m_threadContext.core, vf);
480		} else {
481			m_threadContext.core->loadSave(m_threadContext.core, vf);
482		}
483	});
484	reset();
485}
486
487void CoreController::loadPatch(const QString& patchPath) {
488	Interrupter interrupter(this);
489	VFile* patch = VFileDevice::open(patchPath, O_RDONLY);
490	if (patch) {
491		m_threadContext.core->loadPatch(m_threadContext.core, patch);
492		m_patched = true;
493	}
494	patch->close(patch);
495	if (mCoreThreadHasStarted(&m_threadContext)) {
496		reset();
497	}
498}
499
500void CoreController::replaceGame(const QString& path) {
501	QFileInfo info(path);
502	if (!info.isReadable()) {
503		LOG(QT, ERROR) << tr("Failed to open game file: %1").arg(path);
504		return;
505	}
506	QString fname = info.canonicalFilePath();
507	Interrupter interrupter(this);
508	mDirectorySetDetachBase(&m_threadContext.core->dirs);
509	mCoreLoadFile(m_threadContext.core, fname.toLocal8Bit().constData());
510}
511
512void CoreController::yankPak() {
513#ifdef M_CORE_GBA
514	if (platform() != PLATFORM_GBA) {
515		return;
516	}
517	Interrupter interrupter(this);
518	GBAYankROM(static_cast<GBA*>(m_threadContext.core->board));
519#endif
520}
521
522void CoreController::addKey(int key) {
523	m_activeKeys |= 1 << key;
524}
525
526void CoreController::clearKey(int key) {
527	m_activeKeys &= ~(1 << key);
528}
529
530void CoreController::setAutofire(int key, bool enable) {
531	if (key >= 32 || key < 0) {
532		return;
533	}
534
535	m_autofire[key] = enable;
536	m_autofireStatus[key] = 0;
537}
538
539#ifdef USE_PNG
540void CoreController::screenshot() {
541	mCoreThreadRunFunction(&m_threadContext, [](mCoreThread* context) {
542		mCoreTakeScreenshot(context->core);
543	});
544}
545#endif
546
547void CoreController::setRealTime() {
548	m_threadContext.core->rtc.override = RTC_NO_OVERRIDE;
549}
550
551void CoreController::setFixedTime(const QDateTime& time) {
552	m_threadContext.core->rtc.override = RTC_FIXED;
553	m_threadContext.core->rtc.value = time.toMSecsSinceEpoch();
554}
555
556void CoreController::setFakeEpoch(const QDateTime& time) {
557	m_threadContext.core->rtc.override = RTC_FAKE_EPOCH;
558	m_threadContext.core->rtc.value = time.toMSecsSinceEpoch();
559}
560
561void CoreController::importSharkport(const QString& path) {
562#ifdef M_CORE_GBA
563	if (platform() != PLATFORM_GBA) {
564		return;
565	}
566	VFile* vf = VFileDevice::open(path, O_RDONLY);
567	if (!vf) {
568		LOG(QT, ERROR) << tr("Failed to open snapshot file for reading: %1").arg(path);
569		return;
570	}
571	Interrupter interrupter(this);
572	GBASavedataImportSharkPort(static_cast<GBA*>(m_threadContext.core->board), vf, false);
573	vf->close(vf);
574#endif
575}
576
577void CoreController::exportSharkport(const QString& path) {
578#ifdef M_CORE_GBA
579	if (platform() != PLATFORM_GBA) {
580		return;
581	}
582	VFile* vf = VFileDevice::open(path, O_WRONLY | O_CREAT | O_TRUNC);
583	if (!vf) {
584		LOG(QT, ERROR) << tr("Failed to open snapshot file for writing: %1").arg(path);
585		return;
586	}
587	Interrupter interrupter(this);
588	GBASavedataExportSharkPort(static_cast<GBA*>(m_threadContext.core->board), vf);
589	vf->close(vf);
590#endif
591}
592
593void CoreController::setAVStream(mAVStream* stream) {
594	Interrupter interrupter(this);
595	m_threadContext.core->setAVStream(m_threadContext.core, stream);
596}
597
598void CoreController::clearAVStream() {
599	Interrupter interrupter(this);
600	m_threadContext.core->setAVStream(m_threadContext.core, nullptr);
601}
602
603void CoreController::clearOverride() {
604	m_override.reset();
605}
606
607void CoreController::startVideoLog(const QString& path) {
608	if (m_vl) {
609		return;
610	}
611
612	Interrupter interrupter(this);
613	m_vl = mVideoLogContextCreate(m_threadContext.core);
614	m_vlVf = VFileDevice::open(path, O_WRONLY | O_CREAT | O_TRUNC);
615	mVideoLogContextSetOutput(m_vl, m_vlVf);
616	mVideoLogContextWriteHeader(m_vl, m_threadContext.core);
617}
618
619void CoreController::endVideoLog() {
620	if (!m_vl) {
621		return;
622	}
623
624	Interrupter interrupter(this);
625	mVideoLogContextDestroy(m_threadContext.core, m_vl);
626	if (m_vlVf) {
627		m_vlVf->close(m_vlVf);
628		m_vlVf = nullptr;
629	}
630	m_vl = nullptr;
631}
632
633void CoreController::updateKeys() {
634	int activeKeys = m_activeKeys | updateAutofire() | m_inputController->pollEvents();
635	m_threadContext.core->setKeys(m_threadContext.core, activeKeys);
636}
637
638int CoreController::updateAutofire() {
639	int active = 0;
640	for (int k = 0; k < 32; ++k) {
641		if (!m_autofire[k]) {
642			continue;
643		}
644		++m_autofireStatus[k];
645		if (m_autofireStatus[k]) {
646			m_autofireStatus[k] = 0;
647			active |= 1 << k;
648		}
649	}
650	return active;
651}
652
653void CoreController::finishFrame() {
654	QMutexLocker locker(&m_mutex);
655	m_completeBuffer = m_activeBuffer;
656
657	// TODO: Generalize this to triple buffering?
658	m_activeBuffer = &m_buffers[0];
659	if (m_activeBuffer == m_completeBuffer) {
660		m_activeBuffer = &m_buffers[1];
661	}
662	m_threadContext.core->setVideoBuffer(m_threadContext.core, reinterpret_cast<color_t*>(m_activeBuffer->data()), screenDimensions().width());
663
664	for (auto& action : m_frameActions) {
665		action();
666	}
667	m_frameActions.clear();
668	updateKeys();
669
670	QMetaObject::invokeMethod(this, "frameAvailable");
671}
672
673void CoreController::updateFastForward() {
674	if (m_fastForward || m_fastForwardForced) {
675		if (m_fastForwardRatio > 0) {
676			m_threadContext.impl->sync.fpsTarget = m_fpsTarget * m_fastForwardRatio;
677		} else {
678			setSync(false);
679		}
680	} else {
681		m_threadContext.impl->sync.fpsTarget = m_fpsTarget;
682		setSync(true);
683	}
684}
685
686CoreController::Interrupter::Interrupter(CoreController* parent, bool fromThread)
687	: m_parent(parent)
688{
689	if (!m_parent->thread()->impl) {
690		return;
691	}
692	if (!fromThread) {
693		mCoreThreadInterrupt(m_parent->thread());
694	} else {
695		mCoreThreadInterruptFromThread(m_parent->thread());
696	}
697}
698
699CoreController::Interrupter::Interrupter(std::shared_ptr<CoreController> parent, bool fromThread)
700	: m_parent(parent.get())
701{
702	if (!m_parent->thread()->impl) {
703		return;
704	}
705	if (!fromThread) {
706		mCoreThreadInterrupt(m_parent->thread());
707	} else {
708		mCoreThreadInterruptFromThread(m_parent->thread());
709	}
710}
711
712CoreController::Interrupter::Interrupter(const Interrupter& other)
713	: m_parent(other.m_parent)
714{
715	if (!m_parent->thread()->impl) {
716		return;
717	}
718	mCoreThreadInterrupt(m_parent->thread());
719}
720
721CoreController::Interrupter::~Interrupter() {
722	if (!m_parent->thread()->impl) {
723		return;
724	}
725	mCoreThreadContinue(m_parent->thread());
726}