Core: Implement mLockstepUser for mCoreThread

This commit is contained in:
Vicki Pfau 2024-08-22 22:23:27 -07:00
parent 3180d432e5
commit 36c1a8cfbc
2 changed files with 34 additions and 2 deletions

View File

@ -61,6 +61,17 @@ struct mLockstepUser {
void (*playerIdChanged)(struct mLockstepUser*, int id); void (*playerIdChanged)(struct mLockstepUser*, int id);
}; };
#ifndef DISABLE_THREADING
struct mCoreThread;
struct mLockstepThreadUser {
struct mLockstepUser d;
struct mCoreThread* thread;
};
void mLockstepThreadUserInit(struct mLockstepThreadUser* lockstep, struct mCoreThread* thread);
#endif
CXX_GUARD_END CXX_GUARD_END
#endif #endif

View File

@ -1,10 +1,14 @@
/* Copyright (c) 2013-2016 Jeffrey Pfau /* Copyright (c) 2013-2024 Jeffrey Pfau
* *
* This Source Code Form is subject to the terms of the Mozilla Public * This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <mgba/core/lockstep.h> #include <mgba/core/lockstep.h>
#ifndef DISABLE_THREADING
#include <mgba/core/thread.h>
#endif
void mLockstepInit(struct mLockstep* lockstep) { void mLockstepInit(struct mLockstep* lockstep) {
lockstep->attached = 0; lockstep->attached = 0;
lockstep->transferActive = 0; lockstep->transferActive = 0;
@ -19,4 +23,21 @@ void mLockstepDeinit(struct mLockstep* lockstep) {
UNUSED(lockstep); UNUSED(lockstep);
} }
// TODO: Migrate nodes #ifndef DISABLE_THREADING
static void mLockstepThreadUserSleep(struct mLockstepUser* user) {
struct mLockstepThreadUser* lockstep = (struct mLockstepThreadUser*) user;
mCoreThreadWaitFromThread(lockstep->thread);
}
static void mLockstepThreadUserWake(struct mLockstepUser* user) {
struct mLockstepThreadUser* lockstep = (struct mLockstepThreadUser*) user;
mCoreThreadStopWaiting(lockstep->thread);
}
void mLockstepThreadUserInit(struct mLockstepThreadUser* lockstep, struct mCoreThread* thread) {
memset(lockstep, 0, sizeof(*lockstep));
lockstep->d.sleep = mLockstepThreadUserSleep;
lockstep->d.wake = mLockstepThreadUserWake;
lockstep->thread = thread;
}
#endif