LibCore: Add System::sleep_ms

This commit is contained in:
stasoid 2024-12-14 19:25:55 +05:00 committed by Andrew Kaster
commit a291a7f770
Notes: github-actions[bot] 2025-02-06 22:17:55 +00:00
3 changed files with 14 additions and 0 deletions

View file

@ -1010,4 +1010,11 @@ bool is_socket(int fd)
return !result.is_error() && S_ISSOCK(result.value().st_mode); return !result.is_error() && S_ISSOCK(result.value().st_mode);
} }
ErrorOr<void> sleep_ms(u32 milliseconds)
{
if (usleep(1000 * milliseconds) != 0)
return Error::from_syscall("usleep"sv, -errno);
return {};
}
} }

View file

@ -181,5 +181,6 @@ ErrorOr<void> set_resource_limits(int resource, rlim_t limit);
int getpid(); int getpid();
bool is_socket(int fd); bool is_socket(int fd);
ErrorOr<void> sleep_ms(u32 milliseconds);
} }

View file

@ -225,4 +225,10 @@ bool is_socket(int handle)
return GetFileType(to_handle(handle)) == FILE_TYPE_PIPE; return GetFileType(to_handle(handle)) == FILE_TYPE_PIPE;
} }
ErrorOr<void> sleep_ms(u32 milliseconds)
{
Sleep(milliseconds);
return {};
}
} }