Skip to content

Commit

Permalink
Project: Rename the references container to Ref
Browse files Browse the repository at this point in the history
  • Loading branch information
shadergz committed Jan 21, 2024
1 parent 286ea28 commit 0d7e74b
Show file tree
Hide file tree
Showing 36 changed files with 93 additions and 88 deletions.
1 change: 1 addition & 0 deletions app/src/main/cpp/cosmic/common/alias.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace cosmic {
using i64 = std::int64_t;
using u64 = std::uint64_t;

using u128 = uint64x2_t;
using u256 = uint64x1x4_t;

using f32 = float32_t;
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/cpp/cosmic/common/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
#include <common/alias.h>
namespace cosmic {
template <typename T>
class RawReference {
class Ref {
public:
RawReference() = default;
RawReference(T& save) {
Ref() = default;
Ref(T& save) {
safe = save;
}
auto operator=(std::reference_wrapper<T>& wrapper) {
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/cpp/cosmic/console/backdoor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ namespace cosmic {
}
namespace cosmic::console {
BackDoor::BackDoor(vm::EmuVm& aliveVm) {
vm = std::make_unique<RawReference<vm::EmuVm>>(std::ref(aliveVm));
vm = std::make_unique<Ref<vm::EmuVm>>(std::ref(aliveVm));
echo.lock();
vmRefs = 1;
}
RawReference<vm::EmuVm> BackDoor::openVm() {
Ref<vm::EmuVm> BackDoor::openVm() {
std::thread::id nub{};
if (owner == nub && owner != std::this_thread::get_id()) {
while (echo.try_lock()) {
Expand All @@ -22,22 +22,22 @@ namespace cosmic::console {
}
if (owner != std::this_thread::get_id())
throw AppFail("This resource should have the lock held until the object is released");
RawReference<vm::EmuVm> vmRef{};
Ref<vm::EmuVm> vmRef{};
if (vmRefs) {
vmRef = *vm;
vmRefs++;
}
return vmRef;
}
void BackDoor::leaveVm(RawReference<vm::EmuVm> lvm) {
void BackDoor::leaveVm(Ref<vm::EmuVm> lvm) {
if (echo.try_lock()) {
if (owner != std::this_thread::get_id())
throw AppFail("The program flow is broken, review the usage of BackDoor in the code");
}
vmRefs--;
if (!vm || vmRefs <= 0) {
vm.reset();
vm = std::make_unique<RawReference<vm::EmuVm>>(lvm);
vm = std::make_unique<Ref<vm::EmuVm>>(lvm);
vmRefs = 1;
}
owner = {};
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/cpp/cosmic/console/backdoor.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ namespace cosmic::console {
class BackDoor {
public:
BackDoor(vm::EmuVm& aliveVm);
RawReference<vm::EmuVm> openVm();
void leaveVm(RawReference<vm::EmuVm> lvm);
Ref<vm::EmuVm> openVm();
void leaveVm(Ref<vm::EmuVm> lvm);
private:
std::thread::id owner;
std::mutex echo;
std::unique_ptr<RawReference<vm::EmuVm>> vm;
std::unique_ptr<Ref<vm::EmuVm>> vm;
i32 vmRefs;
};
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/cpp/cosmic/creeper/ee/cop_isa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace cosmic::creeper::ee {
cpu->setTlbByIndex();
}
void MipsIvInterpreter::eret(Operands ops) {
RawReference<engine::copctrl::CtrlCop> c0{cpu->cop0};
Ref<engine::copctrl::CtrlCop> c0{cpu->cop0};
if (c0->status.error) {
cpu->chPc(c0->errorPC);
c0->status.error = false;
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/cpp/cosmic/creeper/ee/mipsiv_cached.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace cosmic::creeper::ee {
auto endIterator{std::end(run)};

for (; opIterator != run.end(); executedInst++) {
RawReference<CachedMultiOp> opcInside{*opIterator};
Ref<CachedMultiOp> opcInside{*opIterator};
bool isLastABr{false};
// Todo: May not work as expected
if (opIterator != run.begin()) {
Expand All @@ -45,7 +45,7 @@ namespace cosmic::creeper::ee {
if ((opIterator + 1) != endIterator) {
// Simulating the pipeline execution with the aim of resolving one or more instructions
// within the same cycle
RawReference<CachedMultiOp> opcSuper{*(opIterator + 1)};
Ref<CachedMultiOp> opcSuper{*(opIterator + 1)};
// Execute only two instructions if the operations use different pipelines
if ((opcInside->infoCallable.pipe ^ opcSuper->infoCallable.pipe) != invPipe) {
performOp(opcInside->infoCallable, false);
Expand Down Expand Up @@ -89,7 +89,7 @@ namespace cosmic::creeper::ee {
block = localPc32;
}
}
MipsIvInterpreter::MipsIvInterpreter(RawReference<engine::EeMipsCore> mips) :
MipsIvInterpreter::MipsIvInterpreter(Ref<engine::EeMipsCore> mips) :
engine::EeExecutor(mips) {
lastCleaned = 0;
memset(metrics.data(), 0, sizeof(metrics));
Expand All @@ -112,7 +112,7 @@ namespace cosmic::creeper::ee {
do {
PCs[0] = *cpu->eePc;
PCs[1] = PCs[0] & cleanPcBlock;
RawReference<BlockFrequency> chosen;
Ref<BlockFrequency> chosen;
ranges::for_each(metrics, [&](auto& met){
if (met.blockPc == PCs[1])
chosen = std::ref(met);
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/cpp/cosmic/creeper/ee/mipsiv_cached.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace cosmic::creeper::ee {

class MipsIvInterpreter : public engine::EeExecutor {
public:
MipsIvInterpreter(RawReference<engine::EeMipsCore> mips);
MipsIvInterpreter(Ref<engine::EeMipsCore> mips);
u32 executeCode() override;
void performInvalidation(u32 address) override;
private:
Expand All @@ -84,9 +84,9 @@ namespace cosmic::creeper::ee {
std::map<u32, CachedBlock> cached;
u32 lastCleaned;

RawReference<vm::EmuVm> vm;
RawReference<engine::FpuCop> fpu;
RawReference<engine::copctrl::CtrlCop> control;
Ref<vm::EmuVm> vm;
Ref<engine::FpuCop> fpu;
Ref<engine::copctrl::CtrlCop> control;

void addi(Operands ops);
void slti(Operands ops);
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/cpp/cosmic/creeper/psx/iop_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,9 @@ namespace cosmic::creeper::psx {
}
}
IopInterpreter::IopInterpreter(
RawReference<iop::IoMipsCore> core) :
Ref<iop::IoMipsCore> core) :
IopExecVe(core) {
RawReference<vm::EmuVm> vmInter{outside->openVm()};
Ref<vm::EmuVm> vmInter{outside->openVm()};

vm = vmInter;
outside->leaveVm(vm);
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/cpp/cosmic/creeper/psx/iop_interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace cosmic::vm {
namespace cosmic::creeper::psx {
class IopInterpreter : public iop::IopExecVe {
public:
IopInterpreter(RawReference<iop::IoMipsCore> core);
IopInterpreter(Ref<iop::IoMipsCore> core);
u32 executeCode() override;
u32 execPsx(u32 opcode, std::array<u8, 3> opeRegs);
u32 execCop(u32 opcode, std::array<u8, 3> opeRegs);
Expand All @@ -19,7 +19,7 @@ namespace cosmic::creeper::psx {
CachedFastPc fastPc;

u32 fetchPcInst() override;
RawReference<vm::EmuVm> vm;
Ref<vm::EmuVm> vm;
void issueInterruptSignal();

void sltiu(Operands ops);
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/cpp/cosmic/engine/copctrl/cop0.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ namespace cosmic::engine::copctrl {
bool isIntEnabled();
private:
void incPerfByEvent(u32 mask, u32 cycles, u8 perfEv);
RawReference<CopCacheLine> getCache(u32 mem, bool write, CacheMode mode = Instruction);
Ref<CopCacheLine> getCache(u32 mem, bool write, CacheMode mode = Instruction);

std::array<CopCacheLine, 128> inCache;
std::array<CopCacheLine, 64> dataCache;
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/cpp/cosmic/engine/copctrl/cop_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace cosmic::engine::copctrl {
// We don't check for a cache miss here
os::vec CtrlCop::readCache(u32 address, CacheMode mode) {
u32 tag{getCachePfn(address, mode)};
RawReference<CopCacheLine> cache;
Ref<CopCacheLine> cache;
cache = getCache(address, false, mode);
u8 fix{};
if (cache->tags[0] == tag)
Expand Down Expand Up @@ -43,7 +43,7 @@ namespace cosmic::engine::copctrl {
return {};
}
void CtrlCop::loadCacheLine(u32 address, EeMipsCore& core, CacheMode mode) {
RawReference<CopCacheLine> pear{};
Ref<CopCacheLine> pear{};
u16 logical{getCachePfn(address, mode)};

pear = getCache(address, true, mode);
Expand Down Expand Up @@ -120,7 +120,7 @@ namespace cosmic::engine::copctrl {
eec.tags[assign] |= dirtyBit;
}
}
RawReference<CopCacheLine> CtrlCop::getCache(u32 mem, bool write, CacheMode mode) {
Ref<CopCacheLine> CtrlCop::getCache(u32 mem, bool write, CacheMode mode) {
std::array<u8*, 2> wb;
std::array<bool, 2> valid;
u32 ci;
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/cpp/cosmic/engine/ee_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ namespace cosmic::engine {
cop0.configureGlobalTlb(selectedLb);
cop0.virtCache->mapTlb(selectedLb);
}
RawReference<mio::TlbPageEntry> EeMipsCore::fetchTlbFromCop(u32* c0Regs) {
Ref<mio::TlbPageEntry> EeMipsCore::fetchTlbFromCop(u32* c0Regs) {
u16 c0id{*reinterpret_cast<u16*>(c0Regs[0])};
return cop0.virtCache->entries[c0id];
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/cpp/cosmic/engine/ee_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ namespace cosmic::engine {
void branchByCondition(bool cond, i32 jumpRel);
void branchOnLikely(bool cond, i32 jumpRel);

RawReference<mio::TlbPageEntry> fetchTlbFromCop(u32* c0Regs);
Ref<mio::TlbPageEntry> fetchTlbFromCop(u32* c0Regs);
void updateTlb();
void setTlbByIndex();

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/cpp/cosmic/engine/ee_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ namespace cosmic::engine {
class EeMipsCore;
class EeExecutor {
public:
EeExecutor(RawReference<EeMipsCore> mips) :
EeExecutor(Ref<EeMipsCore> mips) :
cpu(mips) {}
virtual u32 executeCode() = 0;
virtual u32 fetchPcInst(u32 pc) = 0;
virtual void performInvalidation(u32 address) = 0;
virtual ~EeExecutor() = default;
protected:
RawReference<EeMipsCore> cpu;
Ref<EeMipsCore> cpu;
};

enum MipsRegsHw : u8 {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/cpp/cosmic/fs/bios_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ namespace cosmic::fs {
biosf.readFrom(here, 0);
romHeader.release();
}
RawReference<RomEntry> BiosLoader::getModule(const std::string model) {
Ref<RomEntry> BiosLoader::getModule(const std::string model) {
std::span<u8> modelBin{BitCast<u8*>(model.c_str()), model.size()};
std::span<u8> hdrBin{romHeader->operator*(), hdrSize};
auto indexInt{ranges::search(hdrBin, modelBin)};

return *BitCast<RomEntry*>(indexInt.data());
}
bool BiosLoader::loadVersionInfo(RawReference<RomEntry>, std::span<u8> info) {
bool BiosLoader::loadVersionInfo(Ref<RomEntry>, std::span<u8> info) {
auto reset{getModule("RESET")};
auto directory{getModule("ROMDIR")};

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/cpp/cosmic/fs/bios_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ namespace cosmic::fs {
private:
bool isABios();

RawReference<RomEntry> getModule(const std::string model);
bool loadVersionInfo(RawReference<RomEntry> entry, std::span<u8> info);
Ref<RomEntry> getModule(const std::string model);
bool loadVersionInfo(Ref<RomEntry> entry, std::span<u8> info);
void fillVersion(JNIEnv* android, hle::BiosInfo& bios, std::span<char> info);

DescriptorRaii biosf{};
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/cpp/cosmic/gpu/vulcano/vram_allocator.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <gpu/vulcano/vram_allocator.h>

namespace cosmic::gpu::vulcano {
VramManager::VramManager(RawReference<GraphicsLayer> gpu) : graphics(gpu) {
VramManager::VramManager(Ref<GraphicsLayer> gpu) : graphics(gpu) {
VmaAllocatorCreateInfo allocatorInfo{};
vmaCreateAllocator(&allocatorInfo, &vma);
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/cpp/cosmic/gpu/vulcano/vram_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ namespace cosmic::gpu::vulcano {
class GraphicsLayer;
class VramManager {
public:
VramManager(RawReference<GraphicsLayer> gpu);
VramManager(Ref<GraphicsLayer> gpu);
~VramManager();
private:
VmaAllocator vma{VK_NULL_HANDLE};
RawReference<GraphicsLayer> graphics;
Ref<GraphicsLayer> graphics;
};
}
2 changes: 1 addition & 1 deletion app/src/main/cpp/cosmic/gs/gif_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace cosmic::gs {
void resumeDmacPath();
void reqADmacAtPath(u8 path, bool intPath3 = false);
private:
RawReference<GsEngine> gs;
Ref<GsEngine> gs;
std::array<GifPath, 4> paths;

GifStatus status;
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/cpp/cosmic/hle/syscall_gate.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ namespace cosmic::hle {
void doSyscall(SyscallOrigin origin, i16 sys);
private:
void resetEe();
RawReference<vm::EmuVm> vm;
Ref<vm::EmuVm> vm;
};
}
2 changes: 1 addition & 1 deletion app/src/main/cpp/cosmic/iop/iop_dma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace cosmic::iop {
void IopDma::pulseSpu2Chain() {
// When true, it means that we will write into the SPU2 device
bool write2Spu;
RawReference<IopChan> channel;
Ref<IopChan> channel;
std::array<u32, 2> packet;

channel = std::ref(channels[IopSpu2]);
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/cpp/cosmic/iop/iop_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ namespace cosmic::iop {

class IopExecVe {
public:
IopExecVe(RawReference<IoMipsCore> mips) :
IopExecVe(Ref<IoMipsCore> mips) :
cpu(mips) {}

virtual u32 executeCode() = 0;
virtual u32 fetchPcInst() = 0;
virtual ~IopExecVe() = default;
protected:
RawReference<IoMipsCore> cpu;
Ref<IoMipsCore> cpu;
};

enum IopSpecial {
Expand Down
Loading

0 comments on commit 0d7e74b

Please sign in to comment.