| 189 | } |
| 190 | |
| 191 | Result ProfileManager::initialize() { |
| 192 | std::uint64_t size; |
| 193 | if (auto rc = svcQueryMemoryMapping(&this->clock_va_base, &size, CLOCK_IO_BASE, CLOCK_IO_SIZE); R_FAILED(rc)) |
| 194 | diagAbortWithResult(rc); |
| 195 | |
| 196 | if (auto rc = svcQueryMemoryMapping(&this->disp_va_base, &size, DISP_IO_BASE, DISP_IO_SIZE); R_FAILED(rc)) |
| 197 | diagAbortWithResult(rc); |
| 198 | |
| 199 | if (auto rc = ommGetOperationModeChangeEvent(&this->operation_mode_event, false); R_FAILED(rc)) |
| 200 | diagAbortWithResult(rc); |
| 201 | |
| 202 | if (auto rc = ommGetOperationMode(&this->operation_mode); R_FAILED(rc)) |
| 203 | diagAbortWithResult(rc); |
| 204 | |
| 205 | if (auto rc = insrGetReadableEvent(ins_evt_id, &this->activity_event); R_FAILED(rc)) |
| 206 | diagAbortWithResult(rc); |
| 207 | |
| 208 | if (auto rc = insrGetLastTick(ins_evt_id, &this->activity_tick); R_FAILED(rc)) |
| 209 | diagAbortWithResult(rc); |
| 210 | |
| 211 | ueventCreate(&this->thread_exit_event, false); |
| 212 | |
| 213 | // The event monitor thread should have a higher priority than the transition thread to ensure it wins on mutex races |
| 214 | if (auto rc = threadCreate(&this->event_monitor_thread, &ProfileManager::event_monitor_thread_func, this, |
| 215 | this->event_monitor_thread_stack, sizeof(this->event_monitor_thread_stack), 0x3d, -2); R_FAILED(rc)) |
| 216 | diagAbortWithResult(rc); |
| 217 | |
| 218 | if (auto rc = threadStart(&this->event_monitor_thread); R_FAILED(rc)) |
| 219 | diagAbortWithResult(rc); |
| 220 | |
| 221 | if (auto rc = threadCreate(&this->transition_thread, &ProfileManager::transition_thread_func, this, |
| 222 | this->transition_thread_stack, sizeof(this->transition_thread_stack), 0x3e, -2); R_FAILED(rc)) |
| 223 | diagAbortWithResult(rc); |
| 224 | |
| 225 | if (auto rc = threadStart(&this->transition_thread); R_FAILED(rc)) |
| 226 | diagAbortWithResult(rc); |
| 227 | |
| 228 | return 0; |
| 229 | } |
| 230 | |
| 231 | Result ProfileManager::finalize() { |
| 232 | ueventSignal(&this->thread_exit_event); |
no test coverage detected