diff --git a/Ryujinx.HLE/HOS/Services/Time/IStaticServiceForPsc.cs b/Ryujinx.HLE/HOS/Services/Time/IStaticServiceForPsc.cs index 5c97bb232c..5ea3910f3b 100644 --- a/Ryujinx.HLE/HOS/Services/Time/IStaticServiceForPsc.cs +++ b/Ryujinx.HLE/HOS/Services/Time/IStaticServiceForPsc.cs @@ -33,7 +33,9 @@ namespace Ryujinx.HLE.HOS.Services.Time // GetStandardUserSystemClock() -> object public ResultCode GetStandardUserSystemClock(ServiceCtx context) { - MakeObject(context, new ISystemClock(_timeManager.StandardUserSystemClock, (_permissions & TimePermissions.UserSystemClockWritableMask) != 0, (_permissions & TimePermissions.BypassUninitialized) != 0)); + MakeObject(context, new ISystemClock(_timeManager.StandardUserSystemClock, + (_permissions & TimePermissions.UserSystemClockWritableMask) != 0, + (_permissions & TimePermissions.BypassUninitialized) != 0)); return ResultCode.Success; } @@ -42,7 +44,9 @@ namespace Ryujinx.HLE.HOS.Services.Time // GetStandardNetworkSystemClock() -> object public ResultCode GetStandardNetworkSystemClock(ServiceCtx context) { - MakeObject(context, new ISystemClock(_timeManager.StandardNetworkSystemClock, (_permissions & TimePermissions.NetworkSystemClockWritableMask) != 0, (_permissions & TimePermissions.BypassUninitialized) != 0)); + MakeObject(context, new ISystemClock(_timeManager.StandardNetworkSystemClock, + (_permissions & TimePermissions.NetworkSystemClockWritableMask) != 0, + (_permissions & TimePermissions.BypassUninitialized) != 0)); return ResultCode.Success; } @@ -51,7 +55,9 @@ namespace Ryujinx.HLE.HOS.Services.Time // GetStandardSteadyClock() -> object public ResultCode GetStandardSteadyClock(ServiceCtx context) { - MakeObject(context, new ISteadyClock(_timeManager.StandardSteadyClock, (_permissions & TimePermissions.SteadyClockWritableMask) != 0, (_permissions & TimePermissions.BypassUninitialized) != 0)); + MakeObject(context, new ISteadyClock(_timeManager.StandardSteadyClock, + (_permissions & TimePermissions.SteadyClockWritableMask) != 0, + (_permissions & TimePermissions.BypassUninitialized) != 0)); return ResultCode.Success; } @@ -60,7 +66,8 @@ namespace Ryujinx.HLE.HOS.Services.Time // GetTimeZoneService() -> object public ResultCode GetTimeZoneService(ServiceCtx context) { - MakeObject(context, new ITimeZoneServiceForPsc(_timeManager.TimeZone.Manager, (_permissions & TimePermissions.TimeZoneWritableMask) != 0)); + MakeObject(context, new ITimeZoneServiceForPsc(_timeManager.TimeZone.Manager, + (_permissions & TimePermissions.TimeZoneWritableMask) != 0)); return ResultCode.Success; } @@ -69,7 +76,9 @@ namespace Ryujinx.HLE.HOS.Services.Time // GetStandardLocalSystemClock() -> object public ResultCode GetStandardLocalSystemClock(ServiceCtx context) { - MakeObject(context, new ISystemClock(_timeManager.StandardLocalSystemClock, (_permissions & TimePermissions.LocalSystemClockWritableMask) != 0, (_permissions & TimePermissions.BypassUninitialized) != 0)); + MakeObject(context, new ISystemClock(_timeManager.StandardLocalSystemClock, + (_permissions & TimePermissions.LocalSystemClockWritableMask) != 0, + (_permissions & TimePermissions.BypassUninitialized) != 0)); return ResultCode.Success; } @@ -78,7 +87,9 @@ namespace Ryujinx.HLE.HOS.Services.Time // GetEphemeralNetworkSystemClock() -> object public ResultCode GetEphemeralNetworkSystemClock(ServiceCtx context) { - MakeObject(context, new ISystemClock(_timeManager.StandardNetworkSystemClock, (_permissions & TimePermissions.NetworkSystemClockWritableMask) != 0, (_permissions & TimePermissions.BypassUninitialized) != 0)); + MakeObject(context, new ISystemClock(_timeManager.StandardNetworkSystemClock, + (_permissions & TimePermissions.NetworkSystemClockWritableMask) != 0, + (_permissions & TimePermissions.BypassUninitialized) != 0)); return ResultCode.Success; } diff --git a/Ryujinx.HLE/HOS/Services/Time/TimeManager.cs b/Ryujinx.HLE/HOS/Services/Time/TimeManager.cs index dc91d07ee0..7c5d716399 100644 --- a/Ryujinx.HLE/HOS/Services/Time/TimeManager.cs +++ b/Ryujinx.HLE/HOS/Services/Time/TimeManager.cs @@ -26,17 +26,17 @@ namespace Ryujinx.HLE.HOS.Services.Time } } - public StandardSteadyClockCore StandardSteadyClock { get; private set; } - public TickBasedSteadyClockCore TickBasedSteadyClock { get; private set; } - public StandardLocalSystemClockCore StandardLocalSystemClock { get; private set; } - public StandardNetworkSystemClockCore StandardNetworkSystemClock { get; private set; } - public StandardUserSystemClockCore StandardUserSystemClock { get; private set; } - public TimeZoneContentManager TimeZone { get; private set; } - public EphemeralNetworkSystemClockCore EphemeralNetworkSystemClock { get; private set; } - public TimeSharedMemory SharedMemory { get; private set; } - public LocalSystemClockContextWriter LocalClockContextWriter { get; private set; } - public NetworkSystemClockContextWriter NetworkClockContextWriter { get; private set; } - public EphemeralNetworkSystemClockContextWriter EphemeralClockContextWriter { get; private set; } + public StandardSteadyClockCore StandardSteadyClock { get; } + public TickBasedSteadyClockCore TickBasedSteadyClock { get; } + public StandardLocalSystemClockCore StandardLocalSystemClock { get; } + public StandardNetworkSystemClockCore StandardNetworkSystemClock { get; } + public StandardUserSystemClockCore StandardUserSystemClock { get; } + public TimeZoneContentManager TimeZone { get; } + public EphemeralNetworkSystemClockCore EphemeralNetworkSystemClock { get; } + public TimeSharedMemory SharedMemory { get; } + public LocalSystemClockContextWriter LocalClockContextWriter { get; } + public NetworkSystemClockContextWriter NetworkClockContextWriter { get; } + public EphemeralNetworkSystemClockContextWriter EphemeralClockContextWriter { get; } // TODO: 9.0.0+ power states and alarms diff --git a/Ryujinx.HLE/HOS/Services/Time/TimeSharedMemory.cs b/Ryujinx.HLE/HOS/Services/Time/TimeSharedMemory.cs index bf3dea419f..f714c66230 100644 --- a/Ryujinx.HLE/HOS/Services/Time/TimeSharedMemory.cs +++ b/Ryujinx.HLE/HOS/Services/Time/TimeSharedMemory.cs @@ -101,6 +101,7 @@ namespace Ryujinx.HLE.HOS.Services.Time long objectOffset = indexOffset + 4 + padding + (index & 1) * Marshal.SizeOf(); result = _device.Memory.ReadStruct(objectOffset); + Thread.MemoryBarrier(); possiblyNewIndex = _device.Memory.ReadUInt32(indexOffset); diff --git a/Ryujinx.HLE/HOS/Services/Time/TimeZone/TimeZoneManager.cs b/Ryujinx.HLE/HOS/Services/Time/TimeZone/TimeZoneManager.cs index b2bfcb59ea..1a80365ad9 100644 --- a/Ryujinx.HLE/HOS/Services/Time/TimeZone/TimeZoneManager.cs +++ b/Ryujinx.HLE/HOS/Services/Time/TimeZone/TimeZoneManager.cs @@ -1,7 +1,6 @@ using Ryujinx.HLE.HOS.Services.Time.Clock; using Ryujinx.HLE.Utilities; using System.IO; -using System.Threading; using static Ryujinx.HLE.HOS.Services.Time.TimeZone.TimeZoneRule; namespace Ryujinx.HLE.HOS.Services.Time.TimeZone @@ -37,22 +36,22 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone public bool IsInitialized() { - Monitor.Enter(_lock); + bool res; - bool res = _isInitialized; - - Monitor.Exit(_lock); + lock (_lock) + { + res = _isInitialized; + } return res; } public void MarkInitialized() { - Monitor.Enter(_lock); - - _isInitialized = true; - - Monitor.Exit(_lock); + lock (_lock) + { + _isInitialized = true; + } } public ResultCode GetDeviceLocationName(out string deviceLocationName) @@ -61,16 +60,15 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone deviceLocationName = null; - Monitor.Enter(_lock); - - if (_isInitialized) + lock (_lock) { - deviceLocationName = _deviceLocationName; - result = ResultCode.Success; + if (_isInitialized) + { + deviceLocationName = _deviceLocationName; + result = ResultCode.Success; + } } - Monitor.Exit(_lock); - return result; } @@ -78,29 +76,27 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone { ResultCode result = ResultCode.TimeZoneConversionFailed; - Monitor.Enter(_lock); - - bool timeZoneConversionSuccess = TimeZone.ParseTimeZoneBinary(out TimeZoneRule rules, timeZoneBinaryStream); - - if (timeZoneConversionSuccess) + lock (_lock) { - _deviceLocationName = locationName; - _myRules = rules; - result = ResultCode.Success; - } + bool timeZoneConversionSuccess = TimeZone.ParseTimeZoneBinary(out TimeZoneRule rules, timeZoneBinaryStream); - Monitor.Exit(_lock); + if (timeZoneConversionSuccess) + { + _deviceLocationName = locationName; + _myRules = rules; + result = ResultCode.Success; + } + } return result; } public void SetTotalLocationNameCount(uint totalLocationNameCount) { - Monitor.Enter(_lock); - - _totalLocationNameCount = totalLocationNameCount; - - Monitor.Exit(_lock); + lock (_lock) + { + _totalLocationNameCount = totalLocationNameCount; + } } public ResultCode GetTotalLocationNameCount(out uint totalLocationNameCount) @@ -109,16 +105,15 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone totalLocationNameCount = 0; - Monitor.Enter(_lock); - - if (_isInitialized) + lock (_lock) { - totalLocationNameCount = _totalLocationNameCount; - result = ResultCode.Success; + if (_isInitialized) + { + totalLocationNameCount = _totalLocationNameCount; + result = ResultCode.Success; + } } - Monitor.Exit(_lock); - return result; } @@ -126,16 +121,15 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone { ResultCode result = ResultCode.UninitializedClock; - Monitor.Enter(_lock); - - if (_isInitialized || bypassUninitialized) + lock (_lock) { - _timeZoneUpdateTimePoint = timeZoneUpdatedTimePoint; - result = ResultCode.Success; + if (_isInitialized || bypassUninitialized) + { + _timeZoneUpdateTimePoint = timeZoneUpdatedTimePoint; + result = ResultCode.Success; + } } - Monitor.Exit(_lock); - return result; } @@ -143,20 +137,19 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone { ResultCode result; - Monitor.Enter(_lock); - - if (_isInitialized) + lock (_lock) { - timeZoneUpdatedTimePoint = _timeZoneUpdateTimePoint; - result = ResultCode.Success; + if (_isInitialized) + { + timeZoneUpdatedTimePoint = _timeZoneUpdateTimePoint; + result = ResultCode.Success; + } + else + { + timeZoneUpdatedTimePoint = SteadyClockTimePoint.GetRandom(); + result = ResultCode.UninitializedClock; + } } - else - { - timeZoneUpdatedTimePoint = SteadyClockTimePoint.GetRandom(); - result = ResultCode.UninitializedClock; - } - - Monitor.Exit(_lock); return result; } @@ -165,45 +158,44 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone { ResultCode result = ResultCode.Success; - Monitor.Enter(_lock); - - bool timeZoneConversionSuccess = TimeZone.ParseTimeZoneBinary(out outRules, timeZoneBinaryStream); - - if (!timeZoneConversionSuccess) + lock (_lock) { - result = ResultCode.TimeZoneConversionFailed; - } + bool timeZoneConversionSuccess = TimeZone.ParseTimeZoneBinary(out outRules, timeZoneBinaryStream); - Monitor.Exit(_lock); + if (!timeZoneConversionSuccess) + { + result = ResultCode.TimeZoneConversionFailed; + } + } return result; } public void SetTimeZoneRuleVersion(UInt128 timeZoneRuleVersion) { - Monitor.Enter(_lock); - _timeZoneRuleVersion = timeZoneRuleVersion; - Monitor.Exit(_lock); + lock (_lock) + { + _timeZoneRuleVersion = timeZoneRuleVersion; + } } public ResultCode GetTimeZoneRuleVersion(out UInt128 timeZoneRuleVersion) { ResultCode result; - Monitor.Enter(_lock); - - if (_isInitialized) + lock (_lock) { - timeZoneRuleVersion = _timeZoneRuleVersion; - result = ResultCode.Success; + if (_isInitialized) + { + timeZoneRuleVersion = _timeZoneRuleVersion; + result = ResultCode.Success; + } + else + { + timeZoneRuleVersion = new UInt128(); + result = ResultCode.UninitializedClock; + } } - else - { - timeZoneRuleVersion = new UInt128(); - result = ResultCode.UninitializedClock; - } - - Monitor.Exit(_lock); return result; } @@ -212,30 +204,30 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone { ResultCode result; - Monitor.Enter(_lock); - - if (_isInitialized) + lock (_lock) { - result = ToCalendarTime(_myRules, time, out calendar); + if (_isInitialized) + { + result = ToCalendarTime(_myRules, time, out calendar); + } + else + { + calendar = new CalendarInfo(); + result = ResultCode.UninitializedClock; + } } - else - { - calendar = new CalendarInfo(); - result = ResultCode.UninitializedClock; - } - - Monitor.Exit(_lock); return result; } public ResultCode ToCalendarTime(TimeZoneRule rules, long time, out CalendarInfo calendar) { - Monitor.Enter(_lock); + ResultCode result; - ResultCode result = TimeZone.ToCalendarTime(rules, time, out calendar); - - Monitor.Exit(_lock); + lock (_lock) + { + result = TimeZone.ToCalendarTime(rules, time, out calendar); + } return result; } @@ -244,30 +236,30 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone { ResultCode result; - Monitor.Enter(_lock); - - if (_isInitialized) + lock (_lock) { - result = ToPosixTime(_myRules, calendarTime, out posixTime); + if (_isInitialized) + { + result = ToPosixTime(_myRules, calendarTime, out posixTime); + } + else + { + posixTime = 0; + result = ResultCode.UninitializedClock; + } } - else - { - posixTime = 0; - result = ResultCode.UninitializedClock; - } - - Monitor.Exit(_lock); return result; } public ResultCode ToPosixTime(TimeZoneRule rules, CalendarTime calendarTime, out long posixTime) { - Monitor.Enter(_lock); + ResultCode result; - ResultCode result = TimeZone.ToPosixTime(rules, calendarTime, out posixTime); - - Monitor.Exit(_lock); + lock (_lock) + { + result = TimeZone.ToPosixTime(rules, calendarTime, out posixTime); + } return result; }