diff --git a/include/mgba/core/lockstep.h b/include/mgba/core/lockstep.h index 8936d263e..b83d17657 100644 --- a/include/mgba/core/lockstep.h +++ b/include/mgba/core/lockstep.h @@ -61,6 +61,17 @@ struct mLockstepUser { 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 #endif diff --git a/src/core/lockstep.c b/src/core/lockstep.c index 587cff2b5..c058a80fc 100644 --- a/src/core/lockstep.c +++ b/src/core/lockstep.c @@ -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 * 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/. */ #include +#ifndef DISABLE_THREADING +#include +#endif + void mLockstepInit(struct mLockstep* lockstep) { lockstep->attached = 0; lockstep->transferActive = 0; @@ -19,4 +23,21 @@ void mLockstepDeinit(struct mLockstep* 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