Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert ticks to 64-bit, added nanosecond precision to the API #6734

Merged
merged 4 commits into from
Dec 2, 2022
Merged

Convert ticks to 64-bit, added nanosecond precision to the API #6734

merged 4 commits into from
Dec 2, 2022

Conversation

slouken
Copy link
Collaborator

@slouken slouken commented Dec 2, 2022

Existing Issue(s)

#1000
#5512
#6602
#6731

@slouken slouken requested review from icculus, 1bsyl and a team and removed request for icculus and 1bsyl December 2, 2022 09:23
@slouken
Copy link
Collaborator Author

slouken commented Dec 2, 2022

@FtZPetruska, @mupfdev, @isage, can you take a look at my timing and threading changes here for your platforms?

@isage
Copy link
Contributor

isage commented Dec 2, 2022

Looks ok to me

@mupfdev
Copy link
Contributor

mupfdev commented Dec 2, 2022

As far as I can apparently tell, everything looks OK.

…rom the public API

It's not clear applications need this level of precision yet, so let's leave these private for now.
LightSemaphore_Acquire(&sem->semaphore, 1);
retval = 0;
} else {
int return_code = LightSemaphore_TryAcquire(&sem->semaphore, 1);
if (return_code != 0) {
/* FIXME: Does this code guarantee a wall clock timeout here?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there isn't a function to wait on a LightSemaphore, this was just a hack to simulate it.

The 3DS seems to allow for sub-millisecond delays, so we could have:

Uint64 timeout = SDL_GetTicksNS() + timeout;
while (SDL_GetTicksNS() < timeout) {
  /* Try acquire semaphore */
  /* SDL_DelayNS(1)? */
}

In the best scenario, SDL_DelayNS(1) takes about 9-10µs.

Other than that, the rest works great!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure if that short of a wait might starve whatever code would release the semaphore, but I can certainly change it to that if you want.

…re possible

Currently implemented for Windows and Apple platforms
@slouken slouken merged commit 0a3262e into libsdl-org:main Dec 2, 2022
@slouken slouken deleted the nanoseconds branch December 2, 2022 20:37
@slembcke
Copy link

slembcke commented Dec 8, 2022

Ah, Perfect! I was just about to ask for a "get nanoseconds" function. Timing is one of the few places where I usually ignore SDL's functionality and look elsewhere. This is great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants