Monado OpenXR Runtime
Loading...
Searching...
No Matches
oxr_pair_hashset.h
Go to the documentation of this file.
1// Copyright 2018-2024, Collabora, Ltd.
2// Copyright 2023-2026, NVIDIA CORPORATION.
3// SPDX-License-Identifier: BSL-1.0
4/*!
5 * @file
6 * @brief Pair of name/localized hashets with atomic erase helper.
7 * @ingroup oxr_main
8 */
9
10#pragma once
11
12#include "xrt/xrt_compiler.h"
13
14#include "os/os_threading.h"
15
17#include "oxr_extension_support.h"
18
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24
25struct u_hashset;
26struct u_hashset_item;
27
28
29/*!
30 * A pair of hashets (name_store and loc_store) with an optional mutex
31 * so that both members can be removed atomically.
32 *
33 * @ingroup oxr_main
34 */
36{
37 struct u_hashset *name_store;
38 struct u_hashset *loc_store;
39 struct os_mutex mutex;
40};
41
42/*!
43 * Initialize the pair: create both hashets and the mutex.
44 *
45 * @param log Logger for error reporting
46 * @param pair Pair to initialize
47 * @return XR_SUCCESS or XR_ERROR_RUNTIME_FAILURE
48 * @public @memberof oxr_pair_hashset
49 */
50XRT_NONNULL_ALL XRT_CHECK_RESULT XrResult
51oxr_pair_hashset_init(struct oxr_logger *log, struct oxr_pair_hashset *pair);
52
53/*!
54 * Finalize the pair: destroy mutex and both hashets.
55 *
56 * @param pair Pair to finalize
57 * @public @memberof oxr_pair_hashset
58 */
59XRT_NONNULL_ALL void
60oxr_pair_hashset_fini(struct oxr_pair_hashset *pair);
61
62/*!
63 * Insert a name/localized string pair into both hashets under lock.
64 * On success, @p out_name_item and @p out_loc_item are set to the
65 * inserted items.
66 *
67 * @param pair Pair to insert into
68 * @param name_cstr Name string (null-terminated)
69 * @param loc_cstr Localized string (null-terminated)
70 * @param out_name_item Output for the name store item
71 * @param out_loc_item Output for the loc store item
72 * @return 0 on success, non-zero on failure
73 * @public @memberof oxr_pair_hashset
74 */
75XRT_NONNULL_ALL XRT_CHECK_RESULT int
76oxr_pair_hashset_insert_str_c(struct oxr_pair_hashset *pair,
77 const char *name_cstr,
78 const char *loc_cstr,
79 struct u_hashset_item **out_name_item,
80 struct u_hashset_item **out_loc_item);
81
82/*!
83 * Erase and free both items from the pair under lock, and set the
84 * pointed-to pointers to NULL. Either pointer may be NULL to skip
85 * that side.
86 *
87 * @param pair Pair to remove from
88 * @param name_item_ptr Pointer to name item pointer (erased, freed, set to NULL)
89 * @param loc_item_ptr Pointer to loc item pointer (erased, freed, set to NULL)
90 * @public @memberof oxr_pair_hashset
91 */
92XRT_NONNULL_ALL void
93oxr_pair_hashset_erase_and_free(struct oxr_pair_hashset *pair,
94 struct u_hashset_item **name_item_ptr,
95 struct u_hashset_item **loc_item_ptr);
96
97/*!
98 * Check both name and loc stores under a single lock (atomic).
99 * Writes true to @p out_has_name if the name is present, and to
100 * @p out_has_loc if the localized name is present.
101 *
102 * @param pair Pair whose stores to search
103 * @param name Null-terminated name string
104 * @param loc Null-terminated localized string
105 * @param out_has_name Output: true if name is present (duplicate)
106 * @param out_has_loc Output: true if loc is present (duplicate)
107 * @return XR_SUCCESS if the check completed successfully
108 * @public @memberof oxr_pair_hashset
109 */
110XRT_NONNULL_ALL XRT_CHECK_RESULT XrResult
111oxr_pair_hashset_has_name_and_loc(
112 struct oxr_pair_hashset *pair, const char *name, const char *loc, bool *out_has_name, bool *out_has_loc);
113
114
115#ifdef __cplusplus
116}
117#endif
Wrapper around OS threading native functions.
Forward declarations for OpenXR state tracker structs.
A wrapper around a native mutex.
Definition os_threading.h:69
Logger struct that lives on the stack, one for each call client call.
Definition oxr_logger.h:44
A pair of hashets (name_store and loc_store) with an optional mutex so that both members can be remov...
Definition oxr_pair_hashset.h:36
A embeddable hashset item, note that the string directly follows the u_hashset_item.
Definition u_hashset.h:37
Kind of bespoke hashset implementation, where the user is responsible for allocating and freeing the ...
Definition u_hashset.cpp:26
Header holding common defines.