oxr_event.cpp: rewrite in C

This commit is contained in:
Drew DeVault 2019-10-08 10:28:15 -04:00 committed by Jakob Bornecrantz
parent 904d58d365
commit 6c275f0aae
2 changed files with 15 additions and 18 deletions

View file

@ -15,7 +15,7 @@ lib_st_oxr = static_library(
'oxr_api_verify.h', 'oxr_api_verify.h',
'oxr_binding.c', 'oxr_binding.c',
'oxr_chain.h', 'oxr_chain.h',
'oxr_event.cpp', 'oxr_event.c',
'oxr_extension_support.h', 'oxr_extension_support.h',
'oxr_handle_base.c', 'oxr_handle_base.c',
'oxr_input.c', 'oxr_input.c',

View file

@ -7,9 +7,9 @@
* @ingroup oxr_main * @ingroup oxr_main
*/ */
#include <cstdio> #include <stdio.h>
#include <cstring> #include <string.h>
#include <cstdlib> #include <stdlib.h>
#include "util/u_misc.h" #include "util/u_misc.h"
@ -20,18 +20,9 @@
struct oxr_event struct oxr_event
{ {
public:
struct oxr_event *next; struct oxr_event *next;
size_t length; size_t length;
XrResult result; XrResult result;
public:
inline void *
ptr()
{
return &this[1];
}
}; };
@ -43,10 +34,16 @@ void
unlock(struct oxr_instance *inst) unlock(struct oxr_instance *inst)
{} {}
void *
oxr_event_extra(struct oxr_event *event)
{
return &event[1];
}
struct oxr_event * struct oxr_event *
pop(struct oxr_instance *inst) pop(struct oxr_instance *inst)
{ {
auto ret = inst->next_event; struct oxr_event *ret = inst->next_event;
if (ret == NULL) { if (ret == NULL) {
return NULL; return NULL;
} }
@ -64,7 +61,7 @@ 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)
{ {
auto last = inst->last_event; struct oxr_event *last = inst->last_event;
if (last != NULL) { if (last != NULL) {
last->next = event; last->next = event;
} }
@ -82,7 +79,7 @@ push(struct oxr_instance *inst, struct oxr_event *event)
if (ret != XR_SUCCESS) { \ if (ret != XR_SUCCESS) { \
return ret; \ return ret; \
} \ } \
*extra = (typeof(*extra))(*event)->ptr(); \ *((void **)extra) = oxr_event_extra(*event); \
} while (false) } while (false)
static XrResult static XrResult
@ -148,14 +145,14 @@ oxr_poll_event(struct oxr_logger *log,
} }
lock(inst); lock(inst);
auto event = pop(inst); struct oxr_event *event = pop(inst);
unlock(inst); unlock(inst);
if (event == NULL) { if (event == NULL) {
return XR_EVENT_UNAVAILABLE; return XR_EVENT_UNAVAILABLE;
} }
memcpy(eventData, event->ptr(), event->length); memcpy(eventData, oxr_event_extra(event), event->length);
free(event); free(event);
return event->result; return event->result;