added sys_usleep() and sys_msleep()

This commit is contained in:
Richard Aas 2011-11-23 14:16:34 +00:00
parent e054c8e8cf
commit ee78e33c22
5 changed files with 71 additions and 0 deletions

View file

@ -57,6 +57,12 @@ const char *sys_os_get(void);
const char *sys_libre_version_get(void);
int sys_coredump_set(bool enable);
int sys_daemon(void);
void sys_usleep(unsigned int us);
static inline void sys_msleep(unsigned int ms)
{
sys_usleep(ms * 1000);
}
uint16_t sys_htols(uint16_t v);

View file

@ -120,6 +120,7 @@ SOURCE daemon.c
SOURCE endian.c
SOURCE rand.c
SOURCE sys.c
SOURCE symbian\sleep.cpp
SOURCEPATH ..\..\src\telev
SOURCE telev.c

View file

@ -7,4 +7,5 @@
SRCS += sys/daemon.c
SRCS += sys/endian.c
SRCS += sys/rand.c
SRCS += sys/sleep.c
SRCS += sys/sys.c

45
src/sys/sleep.c Normal file
View file

@ -0,0 +1,45 @@
/**
* @file sleep.c System sleep functions
*
* Copyright (C) 2010 Creytiv.com
*/
#include <re_types.h>
#include <re_fmt.h>
#include <re_sys.h>
#ifdef WIN32
#include <windows.h>
#endif
#ifdef HAVE_UNISTD_H
#define _BSD_SOURCE 1
#include <unistd.h>
#endif
#ifdef HAVE_SELECT_H
#include <sys/select.h>
#endif
/**
* Blocking sleep for [us] number of microseconds
*
* @param us Number of microseconds to sleep
*/
void sys_usleep(unsigned int us)
{
if (!us)
return;
#ifdef WIN32
Sleep(us / 1000);
#elif defined(HAVE_SELECT)
do {
struct timeval tv;
tv.tv_sec = us / 1000000;
tv.tv_usec = us % 1000000;
(void)select(0, NULL, NULL, NULL, &tv);
} while (0);
#else
(void)usleep(us);
#endif
}

18
src/sys/symbian/sleep.cpp Normal file
View file

@ -0,0 +1,18 @@
/**
* @file sleep.cpp System sleep for Symbian
*
* Copyright (C) 2010 Creytiv.com
*/
#include <e32std.h>
extern "C" {
#include <re_types.h>
#include <re_sys.h>
}
void sys_usleep(unsigned int us)
{
User::After(us);
}