mirror of
https://github.com/zeldaret/botw
synced 2026-07-11 14:38:41 -04:00
ksys/act: Finish BaseProcLinkData
This commit is contained in:
@@ -2,11 +2,30 @@
|
||||
#include <prim/seadScopedLock.h>
|
||||
#include <thread/seadThread.h>
|
||||
#include "KingSystem/ActorSystem/actBaseProc.h"
|
||||
#include "KingSystem/ActorSystem/actBaseProcMgr.h"
|
||||
|
||||
namespace ksys::act {
|
||||
|
||||
SEAD_SINGLETON_DISPOSER_IMPL(BaseProcLinkDataMgr)
|
||||
|
||||
BaseProc* BaseProcLinkData::getProc(u32 id, bool allow_deleted) const {
|
||||
if (id == u32(-1) || mId != id)
|
||||
return nullptr;
|
||||
|
||||
if (!allow_deleted && mProc && mProc->getState() == BaseProc::State::Delete)
|
||||
return nullptr;
|
||||
|
||||
return mProc;
|
||||
}
|
||||
|
||||
sead::CriticalSection* BaseProcLinkData::lockIfNeeded() {
|
||||
if (BaseProcMgr::instance()->isHighPriorityThread())
|
||||
return nullptr;
|
||||
|
||||
mCS.lock();
|
||||
return &mCS;
|
||||
}
|
||||
|
||||
bool BaseProcLinkDataMgr::acquireLink(BaseProc* proc) {
|
||||
auto lock = sead::makeScopedLock(mCS);
|
||||
s32 index = mIndex;
|
||||
|
||||
@@ -13,9 +13,20 @@ class BaseProc;
|
||||
class BaseProcLinkData {
|
||||
public:
|
||||
u32 id() const { return mId; }
|
||||
BaseProc* proc() const { return mProc; }
|
||||
s32 refCount() const { return mRefCount; }
|
||||
|
||||
/// Get the stored BaseProc.
|
||||
BaseProc* getProc() const { return mProc; }
|
||||
/// Get the stored BaseProc or nullptr if its ID or state are unexpected.
|
||||
/// @param id The expected ID.
|
||||
/// @param allow_deleted Whether to allow the BaseProc to be in the Delete state.
|
||||
BaseProc* getProc(u32 id, bool allow_deleted) const;
|
||||
|
||||
/// Locks the critical section if on a low priority thread and returns it;
|
||||
/// unlocking it is the responsibility of the caller.
|
||||
/// Returns nullptr if on a high priority thread. In that case, nothing needs to be done.
|
||||
sead::CriticalSection* lockIfNeeded();
|
||||
|
||||
private:
|
||||
friend class BaseProcLinkDataMgr;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user