fix precise sleep inaccurate because scheduler period not set
This commit is contained in:
parent
65211946e0
commit
dcbabbdfd1
@ -1023,7 +1023,7 @@ INTERNAL SYS_THREAD_ENTRY_POINT_FUNC_DEF(host_receiver_thread_entry_point, arg)
|
|||||||
|
|
||||||
struct atomic_i32 *shutdown = &host->receiver_thread_shutdown_flag;
|
struct atomic_i32 *shutdown = &host->receiver_thread_shutdown_flag;
|
||||||
while (!atomic_i32_eval(shutdown)) {
|
while (!atomic_i32_eval(shutdown)) {
|
||||||
struct sock *sock = sock_wait_for_available_read(socks, NULL, F32_INFINITY);
|
struct sock *sock = sock_wait_for_available_read(socks, F32_INFINITY);
|
||||||
struct sock_read_result res;
|
struct sock_read_result res;
|
||||||
while (!atomic_i32_eval(shutdown) && sock && (res = sock_read(sock, read_buff)).valid) {
|
while (!atomic_i32_eval(shutdown) && sock && (res = sock_read(sock, read_buff)).valid) {
|
||||||
struct sock_address address = res.address;
|
struct sock_address address = res.address;
|
||||||
|
|||||||
@ -59,7 +59,6 @@ struct host_event_array {
|
|||||||
struct host {
|
struct host {
|
||||||
struct arena arena;
|
struct arena arena;
|
||||||
|
|
||||||
struct sock_signal *sock_signal;
|
|
||||||
struct sock *sock;
|
struct sock *sock;
|
||||||
|
|
||||||
struct buddy_ctx *buddy; /* For storing msg assembler data */
|
struct buddy_ctx *buddy; /* For storing msg assembler data */
|
||||||
|
|||||||
@ -9,7 +9,6 @@ enum sock_address_family {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct sock;
|
struct sock;
|
||||||
struct sock_signal;
|
|
||||||
|
|
||||||
struct sock_array {
|
struct sock_array {
|
||||||
struct sock **socks;
|
struct sock **socks;
|
||||||
@ -47,7 +46,7 @@ void sock_release(struct sock *sock);
|
|||||||
/* Wake anyone blocking on sock read */
|
/* Wake anyone blocking on sock read */
|
||||||
void sock_wake(struct sock *sock);
|
void sock_wake(struct sock *sock);
|
||||||
|
|
||||||
struct sock *sock_wait_for_available_read(struct sock_array socks, struct sock_signal *signal, f32 timeout);
|
struct sock *sock_wait_for_available_read(struct sock_array socks, f32 timeout);
|
||||||
struct sock_read_result sock_read(struct sock *sock, struct string read_buff);
|
struct sock_read_result sock_read(struct sock *sock, struct string read_buff);
|
||||||
void sock_write(struct sock *sock, struct sock_address address, struct string data);
|
void sock_write(struct sock *sock, struct sock_address address, struct string data);
|
||||||
|
|
||||||
|
|||||||
@ -372,11 +372,10 @@ void sock_wake(struct sock *sock)
|
|||||||
* Read
|
* Read
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
struct sock *sock_wait_for_available_read(struct sock_array socks, struct sock_signal *signal, f32 timeout)
|
struct sock *sock_wait_for_available_read(struct sock_array socks, f32 timeout)
|
||||||
{
|
{
|
||||||
struct sock *res = NULL;
|
struct sock *res = NULL;
|
||||||
|
|
||||||
u64 num_fds = socks.count + (signal != NULL);
|
|
||||||
WSAPOLLFD fds[MAX_POLL_FDS] = ZI;
|
WSAPOLLFD fds[MAX_POLL_FDS] = ZI;
|
||||||
for (u32 i = 0; i < socks.count; ++i) {
|
for (u32 i = 0; i < socks.count; ++i) {
|
||||||
struct win32_sock *ws = (struct win32_sock *)socks.socks[i];
|
struct win32_sock *ws = (struct win32_sock *)socks.socks[i];
|
||||||
@ -390,20 +389,15 @@ struct sock *sock_wait_for_available_read(struct sock_array socks, struct sock_s
|
|||||||
} else {
|
} else {
|
||||||
timeout_ms = (i32)(timeout * 1000);
|
timeout_ms = (i32)(timeout * 1000);
|
||||||
}
|
}
|
||||||
WSAPoll(fds, num_fds, timeout_ms);
|
WSAPoll(fds, socks.count, timeout_ms);
|
||||||
|
|
||||||
b32 none = true;
|
for (u64 i = 0; i < socks.count; ++i) {
|
||||||
for (u64 i = 0; i < num_fds; ++i) {
|
|
||||||
if (fds[i].revents & POLLRDNORM) {
|
if (fds[i].revents & POLLRDNORM) {
|
||||||
res = socks.socks[i];
|
res = socks.socks[i];
|
||||||
none = false;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (none) {
|
|
||||||
DEBUGBREAKABLE;
|
|
||||||
}
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1926,9 +1926,9 @@ INTERNAL void win32_precise_sleep_timer(f64 seconds, HANDLE timer)
|
|||||||
i64 target_qpc = (i64)(qpc.QuadPart + seconds * qpc_per_second);
|
i64 target_qpc = (i64)(qpc.QuadPart + seconds * qpc_per_second);
|
||||||
|
|
||||||
/* TODO: Maybe increase tolerance for higher precision but more power usage */
|
/* TODO: Maybe increase tolerance for higher precision but more power usage */
|
||||||
//const f64 tolerance = 0.001200 * scheduler_period_ms;
|
//const f64 tolerance = scheduler_period_ms * 0.001200;
|
||||||
const f64 tolerance = 0.000520 * scheduler_period_ms;
|
const f64 tolerance = scheduler_period_ms * 0.000520;
|
||||||
//const f64 tolerance = 1 * scheduler_period_ms;
|
//const f64 tolerance = scheduler_period_ms * 1;
|
||||||
|
|
||||||
i64 max_ticks = (i64)scheduler_period_ms * 9500;
|
i64 max_ticks = (i64)scheduler_period_ms * 9500;
|
||||||
while (true) {
|
while (true) {
|
||||||
@ -2066,6 +2066,7 @@ int CALLBACK wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev_instance,
|
|||||||
|
|
||||||
TIMECAPS caps;
|
TIMECAPS caps;
|
||||||
timeGetDevCaps(&caps, sizeof(caps));
|
timeGetDevCaps(&caps, sizeof(caps));
|
||||||
|
G.scheduler_period_ms = (i32)caps.wPeriodMin;
|
||||||
|
|
||||||
/* Set up timing period */
|
/* Set up timing period */
|
||||||
timeBeginPeriod(G.scheduler_period_ms);
|
timeBeginPeriod(G.scheduler_period_ms);
|
||||||
|
|||||||
@ -1313,6 +1313,7 @@ INTERNAL void user_update(void)
|
|||||||
|
|
||||||
/* Draw crosshair or show cursor */
|
/* Draw crosshair or show cursor */
|
||||||
if (!G.debug_camera) {
|
if (!G.debug_camera) {
|
||||||
|
__profscope(draw_crosshair);
|
||||||
struct v2 crosshair_pos = G.ui_cursor;
|
struct v2 crosshair_pos = G.ui_cursor;
|
||||||
u32 tint = RGBA_32_F(1, 1, 1, 1);
|
u32 tint = RGBA_32_F(1, 1, 1, 1);
|
||||||
|
|
||||||
@ -1331,6 +1332,7 @@ INTERNAL void user_update(void)
|
|||||||
sys_window_cursor_hide(G.window);
|
sys_window_cursor_hide(G.window);
|
||||||
sys_window_cursor_enable_clip(G.window, cursor_clip);
|
sys_window_cursor_enable_clip(G.window, cursor_clip);
|
||||||
} else {
|
} else {
|
||||||
|
__profscope(update_window_cursor);
|
||||||
sys_window_cursor_disable_clip(G.window);
|
sys_window_cursor_disable_clip(G.window);
|
||||||
sys_window_cursor_show(G.window);
|
sys_window_cursor_show(G.window);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user