Refactor/fix/document the default port implementation (#2317)
- Various constructs could be expressed with simpler and/or more readable code. - The jerry_port_log implementation for the debugger case was prone to buffer overflow error. - Some documentation was still missing (even from jerryscript-port.h). JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
This commit is contained in:
@@ -13,27 +13,30 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "jerryscript-port.h"
|
||||
#include "jerryscript-port-default.h"
|
||||
|
||||
#ifdef HAVE_TIME_H
|
||||
#include <time.h>
|
||||
#elif defined (HAVE_UNISTD_H)
|
||||
#include <unistd.h>
|
||||
#endif /* HAVE_TIME_H */
|
||||
|
||||
#ifdef JERRY_DEBUGGER
|
||||
void jerry_port_sleep (uint32_t sleep_time)
|
||||
#include "jerryscript-port.h"
|
||||
#include "jerryscript-port-default.h"
|
||||
|
||||
/**
|
||||
* Default implementation of jerry_port_sleep. Uses 'nanosleep' or 'usleep' if
|
||||
* available on the system, does nothing otherwise.
|
||||
*/
|
||||
void jerry_port_sleep (uint32_t sleep_time) /**< milliseconds to sleep */
|
||||
{
|
||||
#ifdef HAVE_TIME_H
|
||||
nanosleep (&(const struct timespec)
|
||||
{
|
||||
(time_t) sleep_time / 1000, ((long int) sleep_time % 1000) * 1000000L /* Seconds, nanoseconds */
|
||||
}
|
||||
, NULL);
|
||||
struct timespec sleep_timespec;
|
||||
sleep_timespec.tv_sec = (time_t) sleep_time / 1000;
|
||||
sleep_timespec.tv_nsec = ((long int) sleep_time % 1000) * 1000000L;
|
||||
|
||||
nanosleep (&sleep_timespec, NULL);
|
||||
#elif defined (HAVE_UNISTD_H)
|
||||
usleep ((useconds_t) sleep_time * 1000);
|
||||
#endif /* HAVE_TIME_H */
|
||||
#else
|
||||
(void) sleep_time;
|
||||
#endif /* HAVE_TIME_H */
|
||||
} /* jerry_port_sleep */
|
||||
#endif /* JERRY_DEBUGGER */
|
||||
|
||||
Reference in New Issue
Block a user