mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Implement os_microdelay and os_delay on top of it
This commit is contained in:
parent
b6d458e137
commit
f8970e1c7c
@ -3,13 +3,14 @@
|
||||
|
||||
#include <uv.h>
|
||||
|
||||
#include "os/time.h"
|
||||
#include "vim.h"
|
||||
#include "term.h"
|
||||
|
||||
static uv_mutex_t delay_mutex;
|
||||
static uv_cond_t delay_cond;
|
||||
|
||||
static void delay(uint64_t ms);
|
||||
static void microdelay(uint64_t ms);
|
||||
|
||||
void time_init()
|
||||
{
|
||||
@ -17,7 +18,12 @@ void time_init()
|
||||
uv_cond_init(&delay_cond);
|
||||
}
|
||||
|
||||
void os_delay(uint64_t ms, bool ignoreinput)
|
||||
void os_delay(uint64_t milliseconds, bool ignoreinput)
|
||||
{
|
||||
os_microdelay(milliseconds * 1000, ignoreinput);
|
||||
}
|
||||
|
||||
void os_microdelay(uint64_t microseconds, bool ignoreinput)
|
||||
{
|
||||
int old_tmode;
|
||||
|
||||
@ -31,19 +37,19 @@ void os_delay(uint64_t ms, bool ignoreinput)
|
||||
if (curr_tmode == TMODE_RAW)
|
||||
settmode(TMODE_SLEEP);
|
||||
|
||||
delay(ms);
|
||||
microdelay(microseconds);
|
||||
|
||||
settmode(old_tmode);
|
||||
in_os_delay = false;
|
||||
} else {
|
||||
delay(ms);
|
||||
microdelay(microseconds);
|
||||
}
|
||||
}
|
||||
|
||||
static void delay(uint64_t ms)
|
||||
static void microdelay(uint64_t microseconds)
|
||||
{
|
||||
uint64_t hrtime;
|
||||
int64_t ns = ms * 1000000; // convert to nanoseconds
|
||||
int64_t ns = microseconds * 1000; // convert to nanoseconds
|
||||
|
||||
uv_mutex_lock(&delay_mutex);
|
||||
|
||||
|
@ -5,6 +5,8 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
void time_init(void);
|
||||
void os_delay(uint64_t ms, bool ignoreinput);
|
||||
void os_delay(uint64_t milliseconds, bool ignoreinput);
|
||||
void os_microdelay(uint64_t microseconds, bool ignoreinput);
|
||||
|
||||
#endif // NEOVIM_OS_TIME_H
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user