内核态usleep

This commit is contained in:
fslongjin 2022-07-18 21:19:45 +08:00
parent 16d6b94c46
commit e7fb6df203
3 changed files with 32 additions and 1 deletions

View File

@ -37,6 +37,14 @@ struct timespec
*/ */
extern int nanosleep(const struct timespec *rqtp, struct timespec *rmtp); extern int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
/**
* @brief
*
* @param usec
* @return int
*/
extern int usleep(useconds_t usec);
/** /**
* @brief CPU时间 * @brief CPU时间
* *

View File

@ -59,4 +59,20 @@ int nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
} }
return 0; return 0;
} }
/**
* @brief
*
* @param usec
* @return int
*/
int usleep(useconds_t usec)
{
struct timespec ts = {
tv_sec : (long int)(usec / 1000000),
tv_nsec : (long int)(usec % 1000000) * 1000UL
};
return nanosleep(&ts, NULL);
}

View File

@ -14,3 +14,10 @@
*/ */
int nanosleep(const struct timespec *rqtp, struct timespec *rmtp); int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
/**
* @brief
*
* @param usec
* @return int
*/
int usleep(useconds_t usec);