Skip to content

Commit

Permalink
Implement nanosleep
Browse files Browse the repository at this point in the history
  • Loading branch information
v-atamanenko authored and d3m3vilurr committed Jul 16, 2022
1 parent db8a907 commit b532fb8
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions newlib/libc/sys/vita/clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ DEALINGS IN THE SOFTWARE.

#include <psp2/rtc.h>
#include <psp2/kernel/processmgr.h>
#include <psp2/kernel/threadmgr.h>

#include "vitaerror.h"

Expand Down Expand Up @@ -83,10 +84,12 @@ int clock_gettime(clockid_t clk_id, struct timespec *tp)

int clock_settime(clockid_t clk_id, const struct timespec *tp)
{
if (!tp) {
if (!tp)
{
errno = EFAULT;
return -1;
}

errno = EPERM;
return -1;
}
Expand Down Expand Up @@ -129,7 +132,7 @@ int timer_create (clockid_t clock_id,

int timer_delete (timer_t timerid)
{
errno = EINVAL; // because we can't create timers - any timerid would be invalid
errno = EINVAL; // since we can't create timers, any id would be invalid
return -1;
}

Expand All @@ -153,8 +156,22 @@ int timer_getoverrun (timer_t timerid)
return -1;
}

int nanosleep (const struct timespec *rqtp, struct timespec *rmtp)
int nanosleep (const struct timespec *rqtp, struct timespec *rmtp)
{
errno = ENOSYS;
return -1;
if (!rqtp)
{
errno = EFAULT;
return -1;
}

if (rqtp->tv_sec < 0 || rqtp->tv_nsec < 0 || rqtp->tv_nsec > 999999999)
{
errno = EINVAL;
return -1;
}

const uint32_t us = rqtp->tv_sec * 1000000 + (rqtp->tv_nsec+999) / 1000;

sceKernelDelayThread(us);
return 0;
}

0 comments on commit b532fb8

Please sign in to comment.