static int g_fd = 0;
_Thread_local volatile void *g_shm_ptr = 0;
_Thread_local int g_tid = 0;
+_Thread_local uint64_t last_ts = 0;
extern int (*write_to_log)(log_id_t log_id, log_priority prio, const char *tag, const char *msg, struct timespec *tp_mono);
extern void (*destroy_backend)(void);
if ((char *)entry + entry_size > (char *)block + ZLOGGER_BLOCK_SIZE)
return -1;
+ /* Ensure that the timestamp is increasing, as opposed to
+ * merely not decreasing. This is done to make sure that
+ * logs can be sorted (which can be ambiguous if there are
+ * multiple valid logs with the same timestamp). */
+ if (last_ts >= ts)
+ ts = last_ts + 1;
+ last_ts = ts;
+
uint16_t *slt = (uint16_t *)&ts;
struct zlogger_entry tmp = {ts, slt[0] + slt[1] + slt[2] + slt[3], (uint16_t)entry_size - hd_size};
memcpy(entry, &tmp, hd_size);