MCPcopy Create free account
hub / github.com/decaf-emu/decaf-emu / IOS_CreateTimer

Function IOS_CreateTimer

src/libdecaf/src/ios/kernel/ios_kernel_timer.cpp:52–114  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50}
51
52Error
53IOS_CreateTimer(std::chrono::microseconds delay,
54 std::chrono::microseconds period,
55 MessageQueueId queue,
56 Message message)
57{
58 auto &timerManager = sData->timerManager;
59
60 // Verify the message queue exists.
61 auto error = internal::getMessageQueueSafe(queue, nullptr);
62 if (error < Error::OK) {
63 return error;
64 }
65
66 // Check the process has not exceeded its maximum number of processes.
67 auto pid = internal::getCurrentProcessId();
68 if (timerManager.numProcessTimers[pid] >= MaxNumTimersPerProcess) {
69 return Error::Max;
70 }
71
72 if (timerManager.firstFreeIdx < 0) {
73 return Error::FailAlloc;
74 }
75
76 auto timerIdx = timerManager.firstFreeIdx;
77 auto &timer = timerManager.timers[timerIdx];
78 auto nextFreeIdx = timer.nextTimerIdx;
79
80 if (nextFreeIdx < 0) {
81 timerManager.firstFreeIdx = int16_t { -1 };
82 timerManager.lastFreeIdx = int16_t { -1 };
83 } else {
84 auto &nextTimer = timerManager.timers[nextFreeIdx];
85 nextTimer.prevTimerIdx = int16_t { -1 };
86 timerManager.firstFreeIdx = nextFreeIdx;
87 }
88
89 timerManager.totalCreatedTimers++;
90
91 timer.uid = timerIdx | static_cast<int32_t>((timerManager.totalCreatedTimers << 12) & 0x7FFFFFFF);
92 timer.state = TimerState::Ready;
93 timer.nextTriggerTime = TimerTicks { 0 };
94 timer.period = static_cast<TimeMicroseconds32>(period.count());
95 timer.queueId = queue;
96 timer.message = message;
97 timer.processId = pid;
98 timer.prevTimerIdx = int16_t { -1 };
99 timer.nextTimerIdx = int16_t { -1 };
100
101 timerManager.numRegistered++;
102 if (timerManager.numRegistered > timerManager.mostRegistered) {
103 timerManager.mostRegistered = timerManager.numRegistered;
104 }
105
106 if (delay.count() || period.count()) {
107 timer.nextTriggerTime = internal::getUpTime64() + internal::durationToTicks(delay);
108 if (internal::startTimer(phys_addrof(timer)) == 0) {
109 internal::setAlarm(timer.nextTriggerTime);

Callers 3

initialiseMethod · 0.85
startPmThreadFunction · 0.85
initialiseRootThreadFunction · 0.85

Calls 7

getMessageQueueSafeFunction · 0.85
getCurrentProcessIdFunction · 0.85
getUpTime64Function · 0.85
durationToTicksFunction · 0.85
startTimerFunction · 0.85
phys_addrofFunction · 0.85
setAlarmFunction · 0.85

Tested by

no test coverage detected