mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-01-04 06:06:17 +00:00
st/oxr: Protoct event queue with a mutex
This commit is contained in:
parent
76e4092e30
commit
b3523a7259
2
doc/changes/state_trackers/mr.359.4.md
Normal file
2
doc/changes/state_trackers/mr.359.4.md
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
OpenXR: Make the event queue thread safe, all done with a simple mutex that is
|
||||||
|
not held for long at all.
|
|
@ -7,17 +7,24 @@
|
||||||
* @ingroup oxr_main
|
* @ingroup oxr_main
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include "os/os_threading.h"
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include "util/u_misc.h"
|
#include "util/u_misc.h"
|
||||||
|
|
||||||
#include "oxr_objects.h"
|
#include "oxr_objects.h"
|
||||||
#include "oxr_logger.h"
|
#include "oxr_logger.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Struct and defines.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
struct oxr_event
|
struct oxr_event
|
||||||
{
|
{
|
||||||
struct oxr_event *next;
|
struct oxr_event *next;
|
||||||
|
@ -26,13 +33,23 @@ struct oxr_event
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Internal helpers.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
void
|
void
|
||||||
lock(struct oxr_instance *inst)
|
lock(struct oxr_instance *inst)
|
||||||
{}
|
{
|
||||||
|
os_mutex_lock(&inst->event.mutex);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
unlock(struct oxr_instance *inst)
|
unlock(struct oxr_instance *inst)
|
||||||
{}
|
{
|
||||||
|
os_mutex_unlock(&inst->event.mutex);
|
||||||
|
}
|
||||||
|
|
||||||
void *
|
void *
|
||||||
oxr_event_extra(struct oxr_event *event)
|
oxr_event_extra(struct oxr_event *event)
|
||||||
|
@ -43,16 +60,16 @@ oxr_event_extra(struct oxr_event *event)
|
||||||
struct oxr_event *
|
struct oxr_event *
|
||||||
pop(struct oxr_instance *inst)
|
pop(struct oxr_instance *inst)
|
||||||
{
|
{
|
||||||
struct oxr_event *ret = inst->next_event;
|
struct oxr_event *ret = inst->event.next;
|
||||||
if (ret == NULL) {
|
if (ret == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
inst->next_event = ret->next;
|
inst->event.next = ret->next;
|
||||||
ret->next = NULL;
|
ret->next = NULL;
|
||||||
|
|
||||||
if (ret == inst->last_event) {
|
if (ret == inst->event.last) {
|
||||||
inst->last_event = NULL;
|
inst->event.last = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -61,14 +78,14 @@ pop(struct oxr_instance *inst)
|
||||||
void
|
void
|
||||||
push(struct oxr_instance *inst, struct oxr_event *event)
|
push(struct oxr_instance *inst, struct oxr_event *event)
|
||||||
{
|
{
|
||||||
struct oxr_event *last = inst->last_event;
|
struct oxr_event *last = inst->event.last;
|
||||||
if (last != NULL) {
|
if (last != NULL) {
|
||||||
last->next = event;
|
last->next = event;
|
||||||
}
|
}
|
||||||
inst->last_event = event;
|
inst->event.last = event;
|
||||||
|
|
||||||
if (inst->next_event == NULL) {
|
if (inst->event.next == NULL) {
|
||||||
inst->next_event = event;
|
inst->event.next = event;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,6 +122,13 @@ oxr_event_alloc(struct oxr_logger *log,
|
||||||
return XR_SUCCESS;
|
return XR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* 'Exported' functions.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
XrResult
|
XrResult
|
||||||
oxr_event_push_XrEventDataSessionStateChanged(struct oxr_logger *log,
|
oxr_event_push_XrEventDataSessionStateChanged(struct oxr_logger *log,
|
||||||
struct oxr_session *sess,
|
struct oxr_session *sess,
|
||||||
|
@ -142,7 +166,7 @@ oxr_event_remove_session_events(struct oxr_logger *log,
|
||||||
|
|
||||||
lock(inst);
|
lock(inst);
|
||||||
|
|
||||||
struct oxr_event *e = inst->next_event;
|
struct oxr_event *e = inst->event.next;
|
||||||
while (e != NULL) {
|
while (e != NULL) {
|
||||||
struct oxr_event *cur = e;
|
struct oxr_event *cur = e;
|
||||||
e = e->next;
|
e = e->next;
|
||||||
|
@ -156,12 +180,12 @@ oxr_event_remove_session_events(struct oxr_logger *log,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cur == inst->next_event) {
|
if (cur == inst->event.next) {
|
||||||
inst->next_event = cur->next;
|
inst->event.next = cur->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cur == inst->last_event) {
|
if (cur == inst->event.last) {
|
||||||
inst->last_event = NULL;
|
inst->event.last = NULL;
|
||||||
}
|
}
|
||||||
free(cur);
|
free(cur);
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,6 +76,9 @@ oxr_instance_destroy(struct oxr_logger *log, struct oxr_handle_base *hb)
|
||||||
// Does null checking and sets to null.
|
// Does null checking and sets to null.
|
||||||
time_state_destroy(&inst->timekeeping);
|
time_state_destroy(&inst->timekeeping);
|
||||||
|
|
||||||
|
// Mutex goes last.
|
||||||
|
os_mutex_destroy(&inst->event.mutex);
|
||||||
|
|
||||||
free(inst);
|
free(inst);
|
||||||
|
|
||||||
return XR_SUCCESS;
|
return XR_SUCCESS;
|
||||||
|
@ -99,7 +102,7 @@ oxr_instance_create(struct oxr_logger *log,
|
||||||
{
|
{
|
||||||
struct oxr_instance *inst = NULL;
|
struct oxr_instance *inst = NULL;
|
||||||
struct xrt_device *xdevs[NUM_XDEVS] = {0};
|
struct xrt_device *xdevs[NUM_XDEVS] = {0};
|
||||||
int xinst_ret;
|
int xinst_ret, m_ret;
|
||||||
XrResult ret;
|
XrResult ret;
|
||||||
|
|
||||||
OXR_ALLOCATE_HANDLE_OR_RETURN(log, inst, OXR_XR_DEBUG_INSTANCE,
|
OXR_ALLOCATE_HANDLE_OR_RETURN(log, inst, OXR_XR_DEBUG_INSTANCE,
|
||||||
|
@ -110,14 +113,20 @@ oxr_instance_create(struct oxr_logger *log,
|
||||||
inst->debug_views = debug_get_bool_option_debug_views();
|
inst->debug_views = debug_get_bool_option_debug_views();
|
||||||
inst->debug_bindings = debug_get_bool_option_debug_bindings();
|
inst->debug_bindings = debug_get_bool_option_debug_bindings();
|
||||||
|
|
||||||
|
m_ret = os_mutex_init(&inst->event.mutex);
|
||||||
|
if (m_ret < 0) {
|
||||||
|
ret = oxr_error(log, XR_ERROR_RUNTIME_FAILURE,
|
||||||
|
"Failed to init mutex");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/* ---- HACK ---- */
|
/* ---- HACK ---- */
|
||||||
oxr_sdl2_hack_create(&inst->hack);
|
oxr_sdl2_hack_create(&inst->hack);
|
||||||
/* ---- HACK ---- */
|
/* ---- HACK ---- */
|
||||||
|
|
||||||
ret = oxr_path_init(log, inst);
|
ret = oxr_path_init(log, inst);
|
||||||
if (ret != XR_SUCCESS) {
|
if (ret != XR_SUCCESS) {
|
||||||
free(inst);
|
return ret;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cache certain often looked up paths.
|
// Cache certain often looked up paths.
|
||||||
|
|
|
@ -14,11 +14,15 @@
|
||||||
#include "xrt/xrt_compositor.h"
|
#include "xrt/xrt_compositor.h"
|
||||||
#include "xrt/xrt_vulkan_includes.h"
|
#include "xrt/xrt_vulkan_includes.h"
|
||||||
#include "xrt/xrt_openxr_includes.h"
|
#include "xrt/xrt_openxr_includes.h"
|
||||||
|
|
||||||
|
#include "os/os_threading.h"
|
||||||
|
|
||||||
#include "util/u_hashset.h"
|
#include "util/u_hashset.h"
|
||||||
#include "util/u_hashmap.h"
|
#include "util/u_hashmap.h"
|
||||||
|
|
||||||
#include "oxr_extension_support.h"
|
#include "oxr_extension_support.h"
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
@ -965,8 +969,12 @@ struct oxr_instance
|
||||||
size_t path_num;
|
size_t path_num;
|
||||||
|
|
||||||
// Event queue.
|
// Event queue.
|
||||||
struct oxr_event *last_event;
|
struct
|
||||||
struct oxr_event *next_event;
|
{
|
||||||
|
struct os_mutex mutex;
|
||||||
|
struct oxr_event *last;
|
||||||
|
struct oxr_event *next;
|
||||||
|
} event;
|
||||||
|
|
||||||
struct oxr_interaction_profile **profiles;
|
struct oxr_interaction_profile **profiles;
|
||||||
size_t num_profiles;
|
size_t num_profiles;
|
||||||
|
|
Loading…
Reference in a new issue