stride icon indicating copy to clipboard operation
stride copied to clipboard

Replace native ThreadSleep with .NET Thread.Sleep

Open Jklawreszuk opened this issue 1 year ago • 6 comments

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.

Jklawreszuk avatar Sep 11 '22 10:09 Jklawreszuk

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Sep 11 '22 10:09 CLAassistant

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

tebjan avatar Sep 11 '22 14:09 tebjan

Hi, I tested it only on Windows. Sadly, I'm currently have no opportunity to test mobile platforms at the moment.

Jklawreszuk avatar Sep 11 '22 16:09 Jklawreszuk

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.

ericwj avatar Sep 11 '22 20:09 ericwj

Looks cool, I didn't notice these changes.Close then?

Jklawreszuk avatar Sep 11 '22 20:09 Jklawreszuk

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.

ericwj avatar Sep 11 '22 21:09 ericwj

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.

Jklawreszuk avatar Sep 25 '22 16:09 Jklawreszuk

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.

ericwj avatar Sep 25 '22 23:09 ericwj

Ok,I've undone changes.

Jklawreszuk avatar Sep 26 '22 16:09 Jklawreszuk