sys_thread_try_release
This commit is contained in:
parent
0b3767df3a
commit
84b0caf379
@ -209,8 +209,9 @@ void host_release(struct host *host)
|
||||
{
|
||||
atomic_i32_eval_exchange(&host->receiver_thread_shutdown_flag, 1);
|
||||
sock_wake(host->sock);
|
||||
sys_thread_wait_release(&host->receiver_thread);
|
||||
|
||||
while (!sys_thread_try_release(&host->receiver_thread, 0.001)) {
|
||||
sock_wake(host->sock);
|
||||
}
|
||||
sys_mutex_release(&host->rcv_buffer_write_mutex);
|
||||
|
||||
sock_release(host->sock);
|
||||
|
||||
@ -566,18 +566,30 @@ void sim_step(struct sim_step_ctx *ctx)
|
||||
struct sim_control *control = &player->player_control;
|
||||
*control = cmd_ent->cmd_control;
|
||||
{
|
||||
u32 flags = control->flags;
|
||||
|
||||
player->player_cursor_pos = control->dbg_cursor;
|
||||
player->player_hovered_ent = cmd_ent->cmd_control_hovered_ent;
|
||||
player->player_dbg_drag_start = false;
|
||||
player->player_dbg_drag_stop = false;
|
||||
|
||||
if (v2_len_sq(control->move) > 1) {
|
||||
/* Cap movement vector magnitude at 1 */
|
||||
if (v2_len_sq(control->move) > 1) {
|
||||
control->move = v2_norm(control->move);
|
||||
}
|
||||
|
||||
player->player_hovered_ent = cmd_ent->cmd_control_hovered_ent;
|
||||
if (flags & SIM_CONTROL_FLAG_TELEPORT_TEST) {
|
||||
if (!(old_control.flags & SIM_CONTROL_FLAG_TELEPORT_TEST)) {
|
||||
logf_info("Teleport (test)");
|
||||
struct sim_ent *ent = sim_ent_from_id(world, player->player_control_ent);
|
||||
if (ent->valid) {
|
||||
test_teleport(ent, player->player_cursor_pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
u32 flags = control->flags;
|
||||
/* Non-predicted cmds */
|
||||
if (ctx->is_master) {
|
||||
if (flags & SIM_CONTROL_FLAG_DRAG) {
|
||||
if (!(old_control.flags & SIM_CONTROL_FLAG_DRAG)) {
|
||||
player->player_dbg_drag_start = true;
|
||||
@ -610,14 +622,6 @@ void sim_step(struct sim_step_ctx *ctx)
|
||||
spawn_test_explosion(world, player->player_cursor_pos, 1);
|
||||
}
|
||||
}
|
||||
if (flags & SIM_CONTROL_FLAG_TELEPORT_TEST) {
|
||||
if (!(old_control.flags & SIM_CONTROL_FLAG_TELEPORT_TEST)) {
|
||||
logf_info("Teleport (test)");
|
||||
struct sim_ent *ent = sim_ent_from_id(world, player->player_control_ent);
|
||||
if (ent->valid) {
|
||||
test_teleport(ent, player->player_cursor_pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (flags & SIM_CONTROL_FLAG_TILE_TEST) {
|
||||
|
||||
@ -345,8 +345,8 @@ void sock_release(struct sock *sock)
|
||||
win32_sock_release(ws);
|
||||
}
|
||||
|
||||
/* Send an empty dummy packet to wake anyone blocking on read (dumb hack since
|
||||
* winsock doesn't have eventfd).
|
||||
/* Send an empty dummy packet to wake anyone blocking on read.
|
||||
* This is hack since winsock doesn't have eventfd.
|
||||
*
|
||||
* TODO: Use WSAEvent and WSAWaitForMultipleEvents instead */
|
||||
void sock_wake(struct sock *sock)
|
||||
|
||||
@ -442,6 +442,7 @@ struct sys_thread sys_thread_alloc(
|
||||
);
|
||||
|
||||
void sys_thread_wait_release(struct sys_thread *thread);
|
||||
b32 sys_thread_try_release(struct sys_thread *thread, f32 timeout_seconds); /* Returns false if the thread could not release in specified timeout (e.g. because it is still running) */
|
||||
void sys_thread_force_release(struct sys_thread *thread);
|
||||
|
||||
/* Gets the current executing thread's ID */
|
||||
|
||||
@ -1976,20 +1976,30 @@ struct sys_thread sys_thread_alloc(sys_thread_entry_point_func *entry_point, voi
|
||||
void sys_thread_wait_release(struct sys_thread *thread)
|
||||
{
|
||||
__prof;
|
||||
b32 success = sys_thread_try_release(thread, F32_INFINITY);
|
||||
ASSERT(success);
|
||||
(UNUSED)success;
|
||||
}
|
||||
|
||||
b32 sys_thread_try_release(struct sys_thread *thread, f32 timeout_seconds)
|
||||
{
|
||||
__prof;
|
||||
b32 success = false;
|
||||
struct win32_thread *t = (struct win32_thread *)thread->handle;
|
||||
HANDLE handle = t->handle;
|
||||
|
||||
/* Wait for thread to stop */
|
||||
if (handle) {
|
||||
DWORD res = WaitForSingleObject(handle, INFINITE);
|
||||
DWORD timeout_ms = (timeout_seconds == F32_INFINITY) ? INFINITE : math_round_to_int(timeout_seconds * 1000);
|
||||
DWORD wait_res = WaitForSingleObject(handle, timeout_ms);
|
||||
if (wait_res == WAIT_OBJECT_0) {
|
||||
success = true;
|
||||
CloseHandle(handle);
|
||||
|
||||
ASSERT(res != WAIT_FAILED);
|
||||
(UNUSED)res;
|
||||
win32_thread_release(t);
|
||||
}
|
||||
}
|
||||
|
||||
/* Release thread struct */
|
||||
win32_thread_release(t);
|
||||
return success;
|
||||
}
|
||||
|
||||
void sys_thread_force_release(struct sys_thread *thread)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user