stride
stride copied to clipboard
Replace native ThreadSleep with .NET Thread.Sleep
PR Details
Description
This PR removes native ThreadSleep function and replaces with .NET Thread.Sleep
Related Issue
#1394
Types of changes
- [x] Docs change / refactoring / dependency upgrade
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [x] Breaking change (fix or feature that would cause existing functionality to change)
Checklist
- [x] My change requires a change to the documentation.
- [ ] I have added tests to cover my changes.
- [ ] All new and existing tests passed.
Thanks for the PR. Did you check whether the .NET Thread.Sleep
also works on Android and iOS in a standard way?
At the top of the NativeInvoke.cs
file there is this IFDEF
:
#if STRIDE_PLATFORM_IOS
internal const string Library = "__Internal";
internal const string LibraryName = "libcore.so";
#else
internal const string Library = "libcore";
#if STRIDE_PLATFORM_WINDOWS
internal const string LibraryName = "libcore.dll";
#else
internal const string LibraryName = "libcore.so";
#endif
#endif
Hi, I tested it only on Windows. Sadly, I'm currently have no opportunity to test mobile platforms at the moment.
There is already this which changes Utilities
to use Thread.Sleep
.
I also checked the implementation of Thread.Sleep
on source.dot.net
and you can find comments about that in that PR in this comment.
Looks cool, I didn't notice these changes.Close then?
I think this PR does a nice cleanup so I would say no keep it.
It is preferable to have Thread.Sleep
in code, which my PR doesn't change. Also I don't think I have actually removed any of the native code which effectively became dead code, which you did here.
The only thing is there might be occurrences of Utilities.Sleep
that might receive negative values depending on the code surrounding the call if the value is not constant. You should probably verify the call sites to rule that out.
Alright, So I decided to bring back the Sleep method and rename it Usleep, since it no longer accepts negative values. Logic is very inspired to the one in eric's pr (hope you don't mind :D ). But I found that it is enough to check that the specified value is equal to -1. Otherwise it will throw an ArgumentException anyway.
This is C# not C++. Usleep
is a horrible name. And I proposed to remove this method entirely and keep your changes, not to keep it because it is (still) in my PR. So I would revert those latest changes.
Ok,I've undone changes.