mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-01-01 04:36:07 +00:00
u/var: Put in a namespace and add some documentation
This commit is contained in:
parent
812c6e46b0
commit
cf9c5b9dc7
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2019, Collabora, Ltd.
|
||||
// Copyright 2019-2022, Collabora, Ltd.
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
/*!
|
||||
* @file
|
||||
|
@ -19,19 +19,27 @@
|
|||
#include <unordered_map>
|
||||
|
||||
|
||||
namespace xrt::auxiliary::util {
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* Enums, Classes and Defines.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
* Simple container for the variable information.
|
||||
*/
|
||||
class Var
|
||||
{
|
||||
public:
|
||||
struct u_var_info info = {};
|
||||
};
|
||||
|
||||
/*!
|
||||
* Object that has a series of tracked variables.
|
||||
*/
|
||||
class Obj
|
||||
{
|
||||
public:
|
||||
|
@ -39,6 +47,9 @@ public:
|
|||
std::vector<Var> vars = {};
|
||||
};
|
||||
|
||||
/*!
|
||||
* Object that has a series of tracked variables.
|
||||
*/
|
||||
class Tracker
|
||||
{
|
||||
public:
|
||||
|
@ -59,7 +70,10 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
static class Tracker tracker;
|
||||
/*!
|
||||
* Global variable tracking state.
|
||||
*/
|
||||
static class Tracker gTracker;
|
||||
|
||||
|
||||
/*
|
||||
|
@ -71,20 +85,20 @@ static class Tracker tracker;
|
|||
static bool
|
||||
get_on()
|
||||
{
|
||||
if (tracker.tested) {
|
||||
return tracker.on;
|
||||
if (gTracker.tested) {
|
||||
return gTracker.on;
|
||||
}
|
||||
tracker.on = debug_get_bool_option("XRT_TRACK_VARIABLES", false);
|
||||
tracker.tested = true;
|
||||
gTracker.on = debug_get_bool_option("XRT_TRACK_VARIABLES", false);
|
||||
gTracker.tested = true;
|
||||
|
||||
return tracker.on;
|
||||
return gTracker.on;
|
||||
}
|
||||
|
||||
static void
|
||||
add_var(void *root, void *ptr, u_var_kind kind, const char *c_name)
|
||||
{
|
||||
auto s = tracker.map.find((ptrdiff_t)root);
|
||||
if (s == tracker.map.end()) {
|
||||
auto s = gTracker.map.find((ptrdiff_t)root);
|
||||
if (s == gTracker.map.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -106,8 +120,8 @@ add_var(void *root, void *ptr, u_var_kind kind, const char *c_name)
|
|||
extern "C" void
|
||||
u_var_force_on(void)
|
||||
{
|
||||
tracker.on = true;
|
||||
tracker.tested = true;
|
||||
gTracker.on = true;
|
||||
gTracker.tested = true;
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
|
@ -120,14 +134,14 @@ u_var_add_root(void *root, const char *c_name, bool number)
|
|||
auto name = std::string(c_name);
|
||||
|
||||
if (number) {
|
||||
int count = tracker.getNumber(name);
|
||||
int count = gTracker.getNumber(name);
|
||||
|
||||
std::stringstream ss;
|
||||
ss << name << " #" << count;
|
||||
name = ss.str();
|
||||
}
|
||||
|
||||
auto &obj = tracker.map[(ptrdiff_t)root] = Obj();
|
||||
auto &obj = gTracker.map[(ptrdiff_t)root] = Obj();
|
||||
obj.name = name;
|
||||
}
|
||||
|
||||
|
@ -138,12 +152,12 @@ u_var_remove_root(void *root)
|
|||
return;
|
||||
}
|
||||
|
||||
auto s = tracker.map.find((ptrdiff_t)root);
|
||||
if (s == tracker.map.end()) {
|
||||
auto s = gTracker.map.find((ptrdiff_t)root);
|
||||
if (s == gTracker.map.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
tracker.map.erase(s);
|
||||
gTracker.map.erase(s);
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
|
@ -154,9 +168,9 @@ u_var_visit(u_var_root_cb enter_cb, u_var_root_cb exit_cb, u_var_elm_cb elem_cb,
|
|||
}
|
||||
|
||||
std::vector<Obj *> tmp;
|
||||
tmp.reserve(tracker.map.size());
|
||||
tmp.reserve(gTracker.map.size());
|
||||
|
||||
for (auto &n : tracker.map) {
|
||||
for (auto &n : gTracker.map) {
|
||||
tmp.push_back(&n.second);
|
||||
}
|
||||
|
||||
|
@ -183,3 +197,5 @@ u_var_visit(u_var_root_cb enter_cb, u_var_root_cb exit_cb, u_var_elm_cb elem_cb,
|
|||
U_VAR_ADD_FUNCS()
|
||||
|
||||
#undef ADD_FUNC
|
||||
|
||||
} // namespace xrt::auxiliary::util
|
||||
|
|
Loading…
Reference in a new issue