Use datatype monotonic_t instead of double to keep track of time
The time is stored in a signed 64 bit integer with nanosecond accuracy. This eliminates the possibility of floating-point inaccuracies. `monotonic_t` can currently hold values large enough to work correctly for more than 200 years into the future. Using a typedef instead of directly using `int64_t` everywhere will also allow easily changing the datatype in the future should the need arise for more precise or bigger time values.
This commit is contained in:
+3
-2
@@ -9,6 +9,7 @@
|
||||
#include "screen.h"
|
||||
#include "graphics.h"
|
||||
#include "charsets.h"
|
||||
#include "monotonic.h"
|
||||
#include <time.h>
|
||||
|
||||
extern PyTypeObject Screen_Type;
|
||||
@@ -1196,7 +1197,7 @@ end:
|
||||
}
|
||||
|
||||
static inline void
|
||||
do_parse_bytes(Screen *screen, const uint8_t *read_buf, const size_t read_buf_sz, double now, PyObject *dump_callback DUMP_UNUSED) {
|
||||
do_parse_bytes(Screen *screen, const uint8_t *read_buf, const size_t read_buf_sz, monotonic_t now, PyObject *dump_callback DUMP_UNUSED) {
|
||||
enum STATE {START, PARSE_PENDING, PARSE_READ_BUF, QUEUE_PENDING};
|
||||
enum STATE state = START;
|
||||
size_t read_buf_pos = 0;
|
||||
@@ -1272,7 +1273,7 @@ FNAME(parse_bytes)(PyObject UNUSED *self, PyObject *args) {
|
||||
|
||||
|
||||
void
|
||||
FNAME(parse_worker)(Screen *screen, PyObject *dump_callback, double now) {
|
||||
FNAME(parse_worker)(Screen *screen, PyObject *dump_callback, monotonic_t now) {
|
||||
#ifdef DUMP_COMMANDS
|
||||
if (screen->read_buf_sz) {
|
||||
Py_XDECREF(PyObject_CallFunction(dump_callback, "sy#", "bytes", screen->read_buf, screen->read_buf_sz)); PyErr_Clear();
|
||||
|
||||
Reference in New Issue
Block a user