blocksds / sdk

Main BlocksDS SDK repository
https://blocksds.github.io/docs/
155 stars 8 forks source link

Feature request: sleep() function #156

Open IvanVeloz opened 3 months ago

IvanVeloz commented 3 months ago

To complement the growing set of POSIX functions, a sleep() and usleep() functions could be added to BlocksDS, making use of a hardware timer as a monotonic clock.

I understand using up timers this can interfere with some games, but it's so handy for applications (and since we have the monotonic clock, we can also implement a bunch of other time functions). In my opinion, it should be available by default under unistd.h, with an option to be disabled by something like #define NO_MONOTONIC.

AntonioND commented 3 months ago

It seems like a reasonable request. We already have some POSIX functions that work in a relatively special way. I guess the implementation could check if there is any free timer and use that one, or we could hardcode a timer, or even have a helper function that can switch the timer that is used.

I don't expect almost any game to use sleep() for anything, so I guess it doesn't have a big impact outside of helping port Linux applications to BlocksDS.

We would need to document the final behaviour of the function too.

I'm open to suggestions.

asiekierka commented 3 months ago

I think this should wait until at least one broader thing is considered: a system for allocating and freeing hardware resources like timers, DMA, etc., that homebrew in general can be encouraged to use, so we don't fall into conflicts.