Monado OpenXR Runtime
OS-Wrappers

Wrapper around OS functions and structs. More...

Collaboration diagram for OS-Wrappers:

Modules

 Portable Timekeeping
 Unifying wrapper around system time retrieval functions.
 

Files

file  os_ble.h
 Wrapper around OS native BLE functions.
 
file  os_ble_dbus.c
 BLE implementation based on Linux Bluez/dbus.
 
file  os_ble_stubs.c
 Stub BLE functions.
 
file  os_documentation.h
 Documentation.
 
file  os_hid.h
 Wrapper around OS native hid functions.
 
file  os_hid_hidraw.c
 Hid implementation based on hidraw.
 
file  os_threading.h
 Wrapper around OS threading native functions.
 
file  os_time.cpp
 Wrapper around OS native time functions.
 
file  os_time.h
 Wrapper around OS native time functions.
 
file  u_windows.c
 Various helpers for doing Windows specific things.
 
file  u_windows.h
 Various helpers for doing Windows specific things.
 

Data Structures

struct  os_mutex
 A wrapper around a native mutex. More...
 
struct  os_cond
 A wrapper around a native conditional variable. More...
 
struct  os_thread
 A wrapper around a native thread. More...
 
struct  os_semaphore
 A wrapper around a native semaphore. More...
 
struct  os_thread_helper
 All in one helper that handles locking, waiting for change and starting a thread. More...
 
interface  os_ble_device
 Representing a single ble notify attribute on a device. More...
 

Typedefs

typedef void *(* os_thread::os_run_func_t) (void *)
 Run function. More...
 

Functions

static XRT_MAYBE_UNUSED int os_ble_read (struct os_ble_device *ble_dev, uint8_t *data, size_t size, int milliseconds)
 Read data from the ble file descriptor, if any, from the given bledevice. More...
 
static XRT_MAYBE_UNUSED void os_ble_destroy (struct os_ble_device **ble_dev_ptr)
 Close and free the given device, does null checking and zeroing. More...
 
int os_ble_notify_open (const char *dev_uuid, const char *char_uuid, struct os_ble_device **out_ble)
 Returns a notification endpoint from the given device uuid and char uuid. More...
 
int os_ble_broadcast_write_value (const char *service_uuid, const char *char_uuid, uint8_t value)
 Returns write startpoints from the given device uuid and char uuid. More...
 
static int os_mutex::os_mutex_init (struct os_mutex *om)
 Init. More...
 
static void os_mutex::os_mutex_lock (struct os_mutex *om)
 Lock. More...
 
static int os_mutex::os_mutex_trylock (struct os_mutex *om)
 Try to lock, but do not block. More...
 
static void os_mutex::os_mutex_unlock (struct os_mutex *om)
 Unlock. More...
 
static void os_mutex::os_mutex_destroy (struct os_mutex *om)
 Clean up. More...
 
static int os_mutex::os_mutex_recursive_init (struct os_mutex *om)
 Init. More...
 
static void os_mutex::os_mutex_recursive_destroy (struct os_mutex *om)
 Clean up. More...
 
static int os_cond::os_cond_init (struct os_cond *oc)
 Init. More...
 
static void os_cond::os_cond_signal (struct os_cond *oc)
 Signal. More...
 
static void os_cond::os_cond_wait (struct os_cond *oc, struct os_mutex *om)
 Wait. More...
 
static void os_cond::os_cond_destroy (struct os_cond *oc)
 Clean up. More...
 
static int os_thread::os_thread_init (struct os_thread *ost)
 Init. More...
 
static int os_thread::os_thread_start (struct os_thread *ost, os_run_func_t func, void *ptr)
 Start thread. More...
 
static void os_thread::os_thread_join (struct os_thread *ost)
 Join. More...
 
static void os_thread::os_thread_destroy (struct os_thread *ost)
 Destruction. More...
 
static void os_thread::os_thread_name (struct os_thread *ost, const char *name)
 Make a best effort to name our thread. More...
 
static int os_semaphore::os_semaphore_init (struct os_semaphore *os, int count)
 Init. More...
 
static void os_semaphore::os_semaphore_release (struct os_semaphore *os)
 Release. More...
 
static int os_semaphore::os_semaphore_get_realtime_clock (struct timespec *ts, uint64_t timeout_ns)
 Set ts to the current time, plus the timeout_ns value. More...
 
static void os_semaphore::os_semaphore_wait (struct os_semaphore *os, uint64_t timeout_ns)
 Wait, if timeout_ns is zero then waits forever. More...
 
static void os_semaphore::os_semaphore_destroy (struct os_semaphore *os)
 Clean up. More...
 
static int os_thread_helper::os_thread_helper_init (struct os_thread_helper *oth)
 Initialize the thread helper. More...
 
static int os_thread_helper::os_thread_helper_start (struct os_thread_helper *oth, os_run_func_t func, void *ptr)
 Start the internal thread. More...
 
static int os_thread_helper::os_thread_helper_signal_stop (struct os_thread_helper *oth)
 Signal from within the thread that we are stopping. More...
 
static int os_thread_helper::os_thread_helper_stop_and_wait (struct os_thread_helper *oth)
 Stop the thread and wait for it to exit. More...
 
static void os_thread_helper::os_thread_helper_destroy (struct os_thread_helper *oth)
 Destroy the thread helper, externally synchronizable. More...
 
static void os_thread_helper::os_thread_helper_lock (struct os_thread_helper *oth)
 Lock the helper. More...
 
static void os_thread_helper::os_thread_helper_unlock (struct os_thread_helper *oth)
 Unlock the helper. More...
 
static bool os_thread_helper::os_thread_helper_is_running (struct os_thread_helper *oth)
 Is the thread running, or supposed to be running. More...
 
static bool os_thread_helper::os_thread_helper_is_running_locked (struct os_thread_helper *oth)
 Is the thread running, or supposed to be running. More...
 
static void os_thread_helper::os_thread_helper_wait_locked (struct os_thread_helper *oth)
 Wait for a signal. More...
 
static void os_thread_helper::os_thread_helper_signal_locked (struct os_thread_helper *oth)
 Signal a waiting thread to wake up. More...
 
static void os_thread_helper::os_thread_helper_name (struct os_thread_helper *oth, const char *name)
 Make a best effort to name our thread. More...
 

Detailed Description

Wrapper around OS functions and structs.

Typedef Documentation

◆ os_run_func_t

typedef void*(* os_run_func_t) (void *)

Run function.

Function Documentation

◆ os_ble_broadcast_write_value()

int os_ble_broadcast_write_value ( const char *  service_uuid,
const char *  char_uuid,
uint8_t  value 
)

#include <auxiliary/os/os_ble.h>

Returns write startpoints from the given device uuid and char uuid.

Returns
Negative on failure, zero on no device found and positive if a device has been found.

◆ os_ble_destroy()

static XRT_MAYBE_UNUSED void os_ble_destroy ( struct os_ble_device **  ble_dev_ptr)
inlinestatic

#include <auxiliary/os/os_ble.h>

Close and free the given device, does null checking and zeroing.

◆ os_ble_notify_open()

int os_ble_notify_open ( const char *  dev_uuid,
const char *  char_uuid,
struct os_ble_device **  out_ble 
)

#include <auxiliary/os/os_ble.h>

Returns a notification endpoint from the given device uuid and char uuid.

Returns
Negative on failure, zero on no device found and positive if a device has been found.

References U_TYPED_CALLOC.

◆ os_ble_read()

static XRT_MAYBE_UNUSED int os_ble_read ( struct os_ble_device ble_dev,
uint8_t *  data,
size_t  size,
int  milliseconds 
)
inlinestatic

#include <auxiliary/os/os_ble.h>

Read data from the ble file descriptor, if any, from the given bledevice.

If milliseconds are negative, this call blocks indefinitely, 0 polls, and positive will block for that amount of milliseconds.

Referenced by arduino_read_one_packet(), and daydream_read_one_packet().

◆ os_cond_destroy()

static void os_cond_destroy ( struct os_cond oc)
inline

Clean up.

◆ os_cond_init()

static int os_cond_init ( struct os_cond oc)
inline

Init.

◆ os_cond_signal()

static void os_cond_signal ( struct os_cond oc)
inline

Signal.

Referenced by locked_pool_wake_worker_if_allowed().

◆ os_cond_wait()

static void os_cond_wait ( struct os_cond oc,
struct os_mutex om 
)
inline

Wait.

Be sure to call this in a loop, testing some other condition that you are actually waiting for, as condition variable waits are subject to spurious wakeups.

Must be called with the mutex om locked.

Once the wait begins, the mutex om is unlocked, to allow another thread access to change the thing you're monitoring. By the time this returns, you once again own the lock.

◆ os_mutex_destroy()

◆ os_mutex_init()

static int os_mutex_init ( struct os_mutex om)
inline

◆ os_mutex_lock()

◆ os_mutex_recursive_destroy()

static void os_mutex_recursive_destroy ( struct os_mutex om)
inline

Clean up.

◆ os_mutex_recursive_init()

static int os_mutex_recursive_init ( struct os_mutex om)
inline

Init.

◆ os_mutex_trylock()

static int os_mutex_trylock ( struct os_mutex om)
inline

Try to lock, but do not block.

◆ os_mutex_unlock()

◆ os_semaphore_destroy()

static void os_semaphore_destroy ( struct os_semaphore os)
inline

Clean up.

◆ os_semaphore_get_realtime_clock()

static int os_semaphore_get_realtime_clock ( struct timespec *  ts,
uint64_t  timeout_ns 
)
inline

Set ts to the current time, plus the timeout_ns value.

Intended for use by the threading code only: the timestamps are not interchangeable with other sources of time.

References os_ns_to_timespec(), and os_timespec_to_ns().

Referenced by os_semaphore::os_semaphore_wait().

◆ os_semaphore_init()

static int os_semaphore_init ( struct os_semaphore os,
int  count 
)
inline

Init.

◆ os_semaphore_release()

static void os_semaphore_release ( struct os_semaphore os)
inline

Release.

◆ os_semaphore_wait()

static void os_semaphore_wait ( struct os_semaphore os,
uint64_t  timeout_ns 
)
inline

Wait, if timeout_ns is zero then waits forever.

References os_semaphore::os_semaphore_get_realtime_clock().

◆ os_thread_destroy()

static void os_thread_destroy ( struct os_thread ost)
inline

Destruction.

◆ os_thread_helper_destroy()

static void os_thread_helper_destroy ( struct os_thread_helper oth)
inline

Destroy the thread helper, externally synchronizable.

Integrates a call to os_thread_helper_stop_and_wait, so you may just call this for full cleanup

References os_thread_helper::os_thread_helper_stop_and_wait().

Referenced by comp_window_mswin_destroy().

◆ os_thread_helper_init()

static int os_thread_helper_init ( struct os_thread_helper oth)
inline

Initialize the thread helper.

References U_ZERO.

◆ os_thread_helper_is_running()

static bool os_thread_helper_is_running ( struct os_thread_helper oth)
inline

Is the thread running, or supposed to be running.

Call with mutex unlocked - it takes and releases the lock internally. If you already have a lock, use os_thread_helper_is_running_locked().

References os_thread_helper::os_thread_helper_lock(), and os_thread_helper::os_thread_helper_unlock().

◆ os_thread_helper_is_running_locked()

static bool os_thread_helper_is_running_locked ( struct os_thread_helper oth)
inline

Is the thread running, or supposed to be running.

Must be called with the helper locked. If you don't have the helper locked for some other reason already, you can use os_thread_helper_is_running()

Referenced by arduino_read_one_packet(), daydream_read_one_packet(), psmv_read_one_packet(), and pssense_read_one_packet().

◆ os_thread_helper_lock()

◆ os_thread_helper_name()

static void os_thread_helper_name ( struct os_thread_helper oth,
const char *  name 
)
inline

Make a best effort to name our thread.

◆ os_thread_helper_signal_locked()

static void os_thread_helper_signal_locked ( struct os_thread_helper oth)
inline

Signal a waiting thread to wake up.

Must be called with the helper locked.

◆ os_thread_helper_signal_stop()

static int os_thread_helper_signal_stop ( struct os_thread_helper oth)
inline

Signal from within the thread that we are stopping.

Call with mutex unlocked - it takes and releases the lock internally.

◆ os_thread_helper_start()

static int os_thread_helper_start ( struct os_thread_helper oth,
os_run_func_t  func,
void *  ptr 
)
inline

Start the internal thread.

◆ os_thread_helper_stop_and_wait()

static int os_thread_helper_stop_and_wait ( struct os_thread_helper oth)
inline

Stop the thread and wait for it to exit.

Call with mutex unlocked - it takes and releases the lock internally.

Referenced by os_thread_helper::os_thread_helper_destroy().

◆ os_thread_helper_unlock()

static void os_thread_helper_unlock ( struct os_thread_helper oth)
inline

◆ os_thread_helper_wait_locked()

static void os_thread_helper_wait_locked ( struct os_thread_helper oth)
inline

Wait for a signal.

Be sure to call this in a loop, testing some other condition that you are actually waiting for, as this is backed by a condition variable wait and is thus subject to spurious wakeups.

Must be called with the helper locked.

As this wraps a cond-var wait, once the wait begins, the helper is unlocked, to allow another thread access to change the thing you're monitoring. By the time this returns, you once again own the lock.

◆ os_thread_init()

static int os_thread_init ( struct os_thread ost)
inline

Init.

◆ os_thread_join()

static void os_thread_join ( struct os_thread ost)
inline

Join.

References U_ZERO.

◆ os_thread_name()

static void os_thread_name ( struct os_thread ost,
const char *  name 
)
inline

Make a best effort to name our thread.

◆ os_thread_start()

static int os_thread_start ( struct os_thread ost,
os_run_func_t  func,
void *  ptr 
)
inline

Start thread.