diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/service/glue/time/worker.cpp | 130 |
1 files changed, 48 insertions, 82 deletions
diff --git a/src/core/hle/service/glue/time/worker.cpp b/src/core/hle/service/glue/time/worker.cpp index f44f3077e..8787f2dcd 100644 --- a/src/core/hle/service/glue/time/worker.cpp +++ b/src/core/hle/service/glue/time/worker.cpp | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | #include "core/hle/service/glue/time/file_timestamp_worker.h" | 7 | #include "core/hle/service/glue/time/file_timestamp_worker.h" |
| 8 | #include "core/hle/service/glue/time/standard_steady_clock_resource.h" | 8 | #include "core/hle/service/glue/time/standard_steady_clock_resource.h" |
| 9 | #include "core/hle/service/glue/time/worker.h" | 9 | #include "core/hle/service/glue/time/worker.h" |
| 10 | #include "core/hle/service/os/multi_wait_utils.h" | ||
| 10 | #include "core/hle/service/psc/time/common.h" | 11 | #include "core/hle/service/psc/time/common.h" |
| 11 | #include "core/hle/service/psc/time/service_manager.h" | 12 | #include "core/hle/service/psc/time/service_manager.h" |
| 12 | #include "core/hle/service/psc/time/static.h" | 13 | #include "core/hle/service/psc/time/static.h" |
| @@ -143,82 +144,46 @@ void TimeWorker::ThreadFunc(std::stop_token stop_token) { | |||
| 143 | Common::SetCurrentThreadName("TimeWorker"); | 144 | Common::SetCurrentThreadName("TimeWorker"); |
| 144 | Common::SetCurrentThreadPriority(Common::ThreadPriority::Low); | 145 | Common::SetCurrentThreadPriority(Common::ThreadPriority::Low); |
| 145 | 146 | ||
| 146 | enum class EventType { | ||
| 147 | Exit = 0, | ||
| 148 | IpmModuleService_GetEvent = 1, | ||
| 149 | PowerStateChange = 2, | ||
| 150 | SignalAlarms = 3, | ||
| 151 | UpdateLocalSystemClock = 4, | ||
| 152 | UpdateNetworkSystemClock = 5, | ||
| 153 | UpdateEphemeralSystemClock = 6, | ||
| 154 | UpdateSteadyClock = 7, | ||
| 155 | UpdateFileTimestamp = 8, | ||
| 156 | AutoCorrect = 9, | ||
| 157 | Max = 10, | ||
| 158 | }; | ||
| 159 | |||
| 160 | s32 num_objs{}; | ||
| 161 | std::array<Kernel::KSynchronizationObject*, static_cast<u32>(EventType::Max)> wait_objs{}; | ||
| 162 | std::array<EventType, static_cast<u32>(EventType::Max)> wait_indices{}; | ||
| 163 | |||
| 164 | const auto AddWaiter{ | ||
| 165 | [&](Kernel::KSynchronizationObject* synchronization_object, EventType type) { | ||
| 166 | // Open a new reference to the object. | ||
| 167 | synchronization_object->Open(); | ||
| 168 | |||
| 169 | // Insert into the list. | ||
| 170 | wait_indices[num_objs] = type; | ||
| 171 | wait_objs[num_objs++] = synchronization_object; | ||
| 172 | }}; | ||
| 173 | |||
| 174 | while (!stop_token.stop_requested()) { | 147 | while (!stop_token.stop_requested()) { |
| 175 | SCOPE_EXIT({ | 148 | enum class EventType : s32 { |
| 176 | for (s32 i = 0; i < num_objs; i++) { | 149 | Exit = 0, |
| 177 | wait_objs[i]->Close(); | 150 | PowerStateChange = 1, |
| 178 | } | 151 | SignalAlarms = 2, |
| 179 | }); | 152 | UpdateLocalSystemClock = 3, |
| 153 | UpdateNetworkSystemClock = 4, | ||
| 154 | UpdateEphemeralSystemClock = 5, | ||
| 155 | UpdateSteadyClock = 6, | ||
| 156 | UpdateFileTimestamp = 7, | ||
| 157 | AutoCorrect = 8, | ||
| 158 | }; | ||
| 159 | |||
| 160 | s32 index{}; | ||
| 180 | 161 | ||
| 181 | num_objs = {}; | ||
| 182 | wait_objs = {}; | ||
| 183 | if (m_pm_state_change_handler.m_priority != 0) { | 162 | if (m_pm_state_change_handler.m_priority != 0) { |
| 184 | AddWaiter(&m_event->GetReadableEvent(), EventType::Exit); | 163 | // TODO: gIPmModuleService::GetEvent() 1 |
| 185 | // TODO | 164 | index = WaitAny(m_system.Kernel(), |
| 186 | // AddWaiter(gIPmModuleService::GetEvent(), 1); | 165 | &m_event->GetReadableEvent(), // 0 |
| 187 | AddWaiter(&m_alarm_worker.GetEvent(), EventType::PowerStateChange); | 166 | &m_alarm_worker.GetEvent() // 1 |
| 167 | ); | ||
| 188 | } else { | 168 | } else { |
| 189 | AddWaiter(&m_event->GetReadableEvent(), EventType::Exit); | 169 | // TODO: gIPmModuleService::GetEvent() 1 |
| 190 | // TODO | 170 | index = WaitAny(m_system.Kernel(), |
| 191 | // AddWaiter(gIPmModuleService::GetEvent(), 1); | 171 | &m_event->GetReadableEvent(), // 0 |
| 192 | AddWaiter(&m_alarm_worker.GetEvent(), EventType::PowerStateChange); | 172 | &m_alarm_worker.GetEvent(), // 1 |
| 193 | AddWaiter(&m_alarm_worker.GetTimerEvent().GetReadableEvent(), EventType::SignalAlarms); | 173 | &m_alarm_worker.GetTimerEvent().GetReadableEvent(), // 2 |
| 194 | AddWaiter(m_local_clock_event, EventType::UpdateLocalSystemClock); | 174 | m_local_clock_event, // 3 |
| 195 | AddWaiter(m_network_clock_event, EventType::UpdateNetworkSystemClock); | 175 | m_network_clock_event, // 4 |
| 196 | AddWaiter(m_ephemeral_clock_event, EventType::UpdateEphemeralSystemClock); | 176 | m_ephemeral_clock_event, // 5 |
| 197 | AddWaiter(&m_timer_steady_clock->GetReadableEvent(), EventType::UpdateSteadyClock); | 177 | &m_timer_steady_clock->GetReadableEvent(), // 6 |
| 198 | AddWaiter(&m_timer_file_system->GetReadableEvent(), EventType::UpdateFileTimestamp); | 178 | &m_timer_file_system->GetReadableEvent(), // 7 |
| 199 | AddWaiter(m_standard_user_auto_correct_clock_event, EventType::AutoCorrect); | 179 | m_standard_user_auto_correct_clock_event // 8 |
| 180 | ); | ||
| 200 | } | 181 | } |
| 201 | 182 | ||
| 202 | s32 out_index{-1}; | 183 | switch (static_cast<EventType>(index)) { |
| 203 | Kernel::KSynchronizationObject::Wait(m_system.Kernel(), &out_index, wait_objs.data(), | ||
| 204 | num_objs, -1); | ||
| 205 | ASSERT(out_index >= 0 && out_index < num_objs); | ||
| 206 | |||
| 207 | if (stop_token.stop_requested()) { | ||
| 208 | return; | ||
| 209 | } | ||
| 210 | |||
| 211 | switch (wait_indices[out_index]) { | ||
| 212 | case EventType::Exit: | 184 | case EventType::Exit: |
| 213 | return; | 185 | return; |
| 214 | 186 | ||
| 215 | case EventType::IpmModuleService_GetEvent: | ||
| 216 | // TODO | ||
| 217 | // IPmModuleService::GetEvent() | ||
| 218 | // clear the event | ||
| 219 | // Handle power state change event | ||
| 220 | break; | ||
| 221 | |||
| 222 | case EventType::PowerStateChange: | 187 | case EventType::PowerStateChange: |
| 223 | m_alarm_worker.GetEvent().Clear(); | 188 | m_alarm_worker.GetEvent().Clear(); |
| 224 | if (m_pm_state_change_handler.m_priority <= 1) { | 189 | if (m_pm_state_change_handler.m_priority <= 1) { |
| @@ -235,19 +200,19 @@ void TimeWorker::ThreadFunc(std::stop_token stop_token) { | |||
| 235 | m_local_clock_event->Clear(); | 200 | m_local_clock_event->Clear(); |
| 236 | 201 | ||
| 237 | Service::PSC::Time::SystemClockContext context{}; | 202 | Service::PSC::Time::SystemClockContext context{}; |
| 238 | auto res = m_local_clock->GetSystemClockContext(&context); | 203 | R_ASSERT(m_local_clock->GetSystemClockContext(&context)); |
| 239 | ASSERT(res == ResultSuccess); | ||
| 240 | 204 | ||
| 241 | m_set_sys->SetUserSystemClockContext(context); | 205 | m_set_sys->SetUserSystemClockContext(context); |
| 242 | |||
| 243 | m_file_timestamp_worker.SetFilesystemPosixTime(); | 206 | m_file_timestamp_worker.SetFilesystemPosixTime(); |
| 244 | } break; | 207 | break; |
| 208 | } | ||
| 245 | 209 | ||
| 246 | case EventType::UpdateNetworkSystemClock: { | 210 | case EventType::UpdateNetworkSystemClock: { |
| 247 | m_network_clock_event->Clear(); | 211 | m_network_clock_event->Clear(); |
| 212 | |||
| 248 | Service::PSC::Time::SystemClockContext context{}; | 213 | Service::PSC::Time::SystemClockContext context{}; |
| 249 | auto res = m_network_clock->GetSystemClockContext(&context); | 214 | R_ASSERT(m_network_clock->GetSystemClockContext(&context)); |
| 250 | ASSERT(res == ResultSuccess); | 215 | |
| 251 | m_set_sys->SetNetworkSystemClockContext(context); | 216 | m_set_sys->SetNetworkSystemClockContext(context); |
| 252 | 217 | ||
| 253 | s64 time{}; | 218 | s64 time{}; |
| @@ -267,7 +232,8 @@ void TimeWorker::ThreadFunc(std::stop_token stop_token) { | |||
| 267 | } | 232 | } |
| 268 | 233 | ||
| 269 | m_file_timestamp_worker.SetFilesystemPosixTime(); | 234 | m_file_timestamp_worker.SetFilesystemPosixTime(); |
| 270 | } break; | 235 | break; |
| 236 | } | ||
| 271 | 237 | ||
| 272 | case EventType::UpdateEphemeralSystemClock: { | 238 | case EventType::UpdateEphemeralSystemClock: { |
| 273 | m_ephemeral_clock_event->Clear(); | 239 | m_ephemeral_clock_event->Clear(); |
| @@ -295,7 +261,8 @@ void TimeWorker::ThreadFunc(std::stop_token stop_token) { | |||
| 295 | if (!g_ig_report_ephemeral_clock_context_set) { | 261 | if (!g_ig_report_ephemeral_clock_context_set) { |
| 296 | g_ig_report_ephemeral_clock_context_set = true; | 262 | g_ig_report_ephemeral_clock_context_set = true; |
| 297 | } | 263 | } |
| 298 | } break; | 264 | break; |
| 265 | } | ||
| 299 | 266 | ||
| 300 | case EventType::UpdateSteadyClock: | 267 | case EventType::UpdateSteadyClock: |
| 301 | m_timer_steady_clock->Clear(); | 268 | m_timer_steady_clock->Clear(); |
| @@ -314,21 +281,20 @@ void TimeWorker::ThreadFunc(std::stop_token stop_token) { | |||
| 314 | m_standard_user_auto_correct_clock_event->Clear(); | 281 | m_standard_user_auto_correct_clock_event->Clear(); |
| 315 | 282 | ||
| 316 | bool automatic_correction{}; | 283 | bool automatic_correction{}; |
| 317 | auto res = m_time_sm->IsStandardUserSystemClockAutomaticCorrectionEnabled( | 284 | R_ASSERT(m_time_sm->IsStandardUserSystemClockAutomaticCorrectionEnabled( |
| 318 | &automatic_correction); | 285 | &automatic_correction)); |
| 319 | ASSERT(res == ResultSuccess); | ||
| 320 | 286 | ||
| 321 | Service::PSC::Time::SteadyClockTimePoint time_point{}; | 287 | Service::PSC::Time::SteadyClockTimePoint time_point{}; |
| 322 | res = m_time_sm->GetStandardUserSystemClockAutomaticCorrectionUpdatedTime(&time_point); | 288 | R_ASSERT( |
| 323 | ASSERT(res == ResultSuccess); | 289 | m_time_sm->GetStandardUserSystemClockAutomaticCorrectionUpdatedTime(&time_point)); |
| 324 | 290 | ||
| 325 | m_set_sys->SetUserSystemClockAutomaticCorrectionEnabled(automatic_correction); | 291 | m_set_sys->SetUserSystemClockAutomaticCorrectionEnabled(automatic_correction); |
| 326 | m_set_sys->SetUserSystemClockAutomaticCorrectionUpdatedTime(time_point); | 292 | m_set_sys->SetUserSystemClockAutomaticCorrectionUpdatedTime(time_point); |
| 327 | } break; | 293 | break; |
| 294 | } | ||
| 328 | 295 | ||
| 329 | default: | 296 | default: |
| 330 | UNREACHABLE(); | 297 | UNREACHABLE(); |
| 331 | break; | ||
| 332 | } | 298 | } |
| 333 | } | 299 | } |
| 334 | } | 300 | } |