mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-22 12:55:58 +01:00
backend: use time helpers to implement timeouts
Instead of hand-rolling get_current_time_msec(), let's just re-use the helper we already have in "util/time.h".
This commit is contained in:
parent
769cabbadf
commit
21254737bf
2 changed files with 8 additions and 19 deletions
|
@ -18,6 +18,7 @@
|
||||||
#include "backend/multi.h"
|
#include "backend/multi.h"
|
||||||
#include "render/allocator/allocator.h"
|
#include "render/allocator/allocator.h"
|
||||||
#include "util/env.h"
|
#include "util/env.h"
|
||||||
|
#include "util/time.h"
|
||||||
|
|
||||||
#if WLR_HAS_DRM_BACKEND
|
#if WLR_HAS_DRM_BACKEND
|
||||||
#include <wlr/backend/drm.h>
|
#include <wlr/backend/drm.h>
|
||||||
|
@ -66,12 +67,6 @@ void wlr_backend_destroy(struct wlr_backend *backend) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint64_t get_current_time_ms(void) {
|
|
||||||
struct timespec ts = {0};
|
|
||||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
|
||||||
return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000;
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct wlr_session *session_create_and_wait(struct wl_display *disp) {
|
static struct wlr_session *session_create_and_wait(struct wl_display *disp) {
|
||||||
struct wlr_session *session = wlr_session_create(disp);
|
struct wlr_session *session = wlr_session_create(disp);
|
||||||
|
|
||||||
|
@ -83,8 +78,8 @@ static struct wlr_session *session_create_and_wait(struct wl_display *disp) {
|
||||||
if (!session->active) {
|
if (!session->active) {
|
||||||
wlr_log(WLR_INFO, "Waiting for a session to become active");
|
wlr_log(WLR_INFO, "Waiting for a session to become active");
|
||||||
|
|
||||||
uint64_t started_at = get_current_time_ms();
|
int64_t started_at = get_current_time_msec();
|
||||||
uint64_t timeout = WAIT_SESSION_TIMEOUT;
|
int64_t timeout = WAIT_SESSION_TIMEOUT;
|
||||||
struct wl_event_loop *event_loop =
|
struct wl_event_loop *event_loop =
|
||||||
wl_display_get_event_loop(session->display);
|
wl_display_get_event_loop(session->display);
|
||||||
|
|
||||||
|
@ -96,7 +91,7 @@ static struct wlr_session *session_create_and_wait(struct wl_display *disp) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t now = get_current_time_ms();
|
int64_t now = get_current_time_msec();
|
||||||
if (now >= started_at + WAIT_SESSION_TIMEOUT) {
|
if (now >= started_at + WAIT_SESSION_TIMEOUT) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <time.h>
|
|
||||||
#include <wayland-server-core.h>
|
#include <wayland-server-core.h>
|
||||||
#include <wlr/backend/session.h>
|
#include <wlr/backend/session.h>
|
||||||
#include <wlr/config.h>
|
#include <wlr/config.h>
|
||||||
|
@ -17,6 +16,7 @@
|
||||||
#include <xf86drm.h>
|
#include <xf86drm.h>
|
||||||
#include <xf86drmMode.h>
|
#include <xf86drmMode.h>
|
||||||
#include "backend/session/session.h"
|
#include "backend/session/session.h"
|
||||||
|
#include "util/time.h"
|
||||||
|
|
||||||
#include <libseat.h>
|
#include <libseat.h>
|
||||||
|
|
||||||
|
@ -436,12 +436,6 @@ static struct udev_enumerate *enumerate_drm_cards(struct udev *udev) {
|
||||||
return en;
|
return en;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint64_t get_current_time_ms(void) {
|
|
||||||
struct timespec ts = {0};
|
|
||||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
|
||||||
return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct find_gpus_add_handler {
|
struct find_gpus_add_handler {
|
||||||
bool added;
|
bool added;
|
||||||
struct wl_listener listener;
|
struct wl_listener listener;
|
||||||
|
@ -476,8 +470,8 @@ ssize_t wlr_session_find_gpus(struct wlr_session *session,
|
||||||
handler.listener.notify = find_gpus_handle_add;
|
handler.listener.notify = find_gpus_handle_add;
|
||||||
wl_signal_add(&session->events.add_drm_card, &handler.listener);
|
wl_signal_add(&session->events.add_drm_card, &handler.listener);
|
||||||
|
|
||||||
uint64_t started_at = get_current_time_ms();
|
int64_t started_at = get_current_time_msec();
|
||||||
uint64_t timeout = WAIT_GPU_TIMEOUT;
|
int64_t timeout = WAIT_GPU_TIMEOUT;
|
||||||
struct wl_event_loop *event_loop =
|
struct wl_event_loop *event_loop =
|
||||||
wl_display_get_event_loop(session->display);
|
wl_display_get_event_loop(session->display);
|
||||||
while (!handler.added) {
|
while (!handler.added) {
|
||||||
|
@ -489,7 +483,7 @@ ssize_t wlr_session_find_gpus(struct wlr_session *session,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t now = get_current_time_ms();
|
int64_t now = get_current_time_msec();
|
||||||
if (now >= started_at + WAIT_GPU_TIMEOUT) {
|
if (now >= started_at + WAIT_GPU_TIMEOUT) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue