Move client/src/* to client/*
This commit is contained in:
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2022 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
* Copyright (C) 2022 Patrick Nicolas <patricknicolas@laposte.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "backtrace.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <cxxabi.h>
|
||||
#include <dlfcn.h>
|
||||
#include <span>
|
||||
#include <spdlog/fmt/fmt.h>
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unwind.h>
|
||||
#include <vector>
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
#include <link.h>
|
||||
|
||||
struct bt_state
|
||||
{
|
||||
struct lib_info
|
||||
{
|
||||
std::string name;
|
||||
uintptr_t address;
|
||||
std::span<const Elf64_Phdr> headers;
|
||||
};
|
||||
|
||||
size_t max_size;
|
||||
std::vector<void *> trace;
|
||||
std::unordered_map<std::string, lib_info> libs;
|
||||
};
|
||||
|
||||
static _Unwind_Reason_Code unwind_callback(struct _Unwind_Context * context, void * arg)
|
||||
{
|
||||
bt_state & state = *static_cast<bt_state *>(arg);
|
||||
uintptr_t pc = _Unwind_GetIP(context);
|
||||
if (pc)
|
||||
{
|
||||
if (state.trace.size() >= state.max_size)
|
||||
{
|
||||
return _URC_END_OF_STACK;
|
||||
}
|
||||
else
|
||||
{
|
||||
state.trace.push_back(reinterpret_cast<void *>(pc));
|
||||
}
|
||||
}
|
||||
return _URC_NO_REASON;
|
||||
}
|
||||
|
||||
static int iterate_phdr_callback(dl_phdr_info * info, size_t size, void * arg)
|
||||
{
|
||||
bt_state & state = *static_cast<bt_state *>(arg);
|
||||
|
||||
std::string library = info->dlpi_name;
|
||||
auto slash = library.find_last_of('/');
|
||||
if (slash != std::string::npos)
|
||||
library = library.substr(slash + 1);
|
||||
|
||||
state.libs.emplace(library, bt_state::lib_info{library, info->dlpi_addr, {info->dlpi_phdr, info->dlpi_phdr + info->dlpi_phnum}});
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// static std::string unmangle(const char * function)
|
||||
// {
|
||||
// if (!function)
|
||||
// return "(null)";
|
||||
//
|
||||
// int status;
|
||||
// char * demangled = abi::__cxa_demangle(function, nullptr, nullptr, &status);
|
||||
//
|
||||
// if (status != 0)
|
||||
// return function;
|
||||
//
|
||||
// std::string s = demangled;
|
||||
// free(demangled);
|
||||
// return s;
|
||||
// }
|
||||
|
||||
std::vector<utils::backtrace_entry> utils::backtrace(size_t max)
|
||||
{
|
||||
bt_state state;
|
||||
state.max_size = max;
|
||||
|
||||
dl_iterate_phdr(iterate_phdr_callback, &state);
|
||||
|
||||
_Unwind_Backtrace(unwind_callback, &state);
|
||||
|
||||
std::vector<backtrace_entry> trace;
|
||||
trace.reserve(state.trace.size());
|
||||
for (void * pc: state.trace)
|
||||
{
|
||||
Dl_info info;
|
||||
if (dladdr(pc, &info))
|
||||
{
|
||||
// size_t offset = (size_t)pc - (size_t)info.dli_saddr;
|
||||
// std::string function = unmangle(info.dli_sname);
|
||||
std::string library = info.dli_fname;
|
||||
|
||||
auto slash = library.find_last_of('/');
|
||||
if (slash != std::string::npos)
|
||||
library = library.substr(slash + 1);
|
||||
|
||||
auto it = state.libs.find(library);
|
||||
uintptr_t library_base = 0;
|
||||
if (it != state.libs.end())
|
||||
library_base = it->second.address;
|
||||
|
||||
trace.push_back(backtrace_entry{
|
||||
.library = library,
|
||||
.library_base = library_base,
|
||||
.pc = (uintptr_t)pc,
|
||||
});
|
||||
// fmt::format("{:#016x}: {}, {}+{:#x}", (uintptr_t)pc, library, function, offset));
|
||||
}
|
||||
}
|
||||
|
||||
return trace;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2022 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
* Copyright (C) 2022 Patrick Nicolas <patricknicolas@laposte.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace utils
|
||||
{
|
||||
struct backtrace_entry
|
||||
{
|
||||
std::string library;
|
||||
uintptr_t library_base;
|
||||
uintptr_t pc;
|
||||
};
|
||||
|
||||
std::vector<backtrace_entry> backtrace(size_t max = 10);
|
||||
} // namespace utils
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2022 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
* Copyright (C) 2022 Patrick Nicolas <patricknicolas@laposte.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdexcept>
|
||||
#include <system_error>
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
#if __has_include(<vulkan/vk_enum_string_helper.h>)
|
||||
#include <vulkan/vk_enum_string_helper.h>
|
||||
#else
|
||||
#include "external/magic_enum.hpp"
|
||||
#define string_VkResult(x) std::string(magic_enum::enum_name((VkResult)(x)))
|
||||
#endif
|
||||
|
||||
namespace xr
|
||||
{
|
||||
const std::error_category & error_category();
|
||||
}
|
||||
|
||||
namespace vk
|
||||
{
|
||||
const std::error_category & error_category();
|
||||
}
|
||||
|
||||
static inline VkResult check(VkResult result, const char * statement)
|
||||
{
|
||||
if (result != VK_SUCCESS)
|
||||
throw std::system_error(result, vk::error_category(), statement);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline VkResult check(VkResult result, const char * /*statement*/, const char * message)
|
||||
{
|
||||
if (result != VK_SUCCESS)
|
||||
throw std::system_error(result, vk::error_category(), message);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline XrResult check(XrResult result, const char * statement)
|
||||
{
|
||||
if (!XR_SUCCEEDED(result))
|
||||
throw std::system_error(result, xr::error_category(), statement);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline XrResult check(XrResult result, const char * /*statement*/, const char * message)
|
||||
{
|
||||
if (!XR_SUCCEEDED(result))
|
||||
throw std::system_error(result, xr::error_category(), message);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#define CHECK_VK(result, ...) check(result, #result __VA_OPT__(, ) __VA_ARGS__)
|
||||
#define CHECK_XR(result, ...) check(result, #result __VA_OPT__(, ) __VA_ARGS__)
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2022 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
* Copyright (C) 2022 Patrick Nicolas <patricknicolas@laposte.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace utils
|
||||
{
|
||||
template <typename T>
|
||||
class handle
|
||||
{
|
||||
protected:
|
||||
static const inline T null_value = 0;
|
||||
|
||||
T id = null_value;
|
||||
|
||||
handle() {}
|
||||
~handle() {}
|
||||
|
||||
public:
|
||||
handle(handle && other) noexcept :
|
||||
id(other.id)
|
||||
{
|
||||
other.id = null_value;
|
||||
}
|
||||
|
||||
handle & operator=(handle && other) noexcept
|
||||
{
|
||||
std::swap(id, other.id);
|
||||
return *this;
|
||||
}
|
||||
|
||||
handle(const handle &) = delete;
|
||||
handle & operator=(const handle &) = delete;
|
||||
|
||||
operator T() const
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
operator bool() const
|
||||
{
|
||||
return id != null_value;
|
||||
}
|
||||
|
||||
T release()
|
||||
{
|
||||
T r = id;
|
||||
id = null_value;
|
||||
return r;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
bool operator==(const handle<T> & lhs, const T & rhs)
|
||||
{
|
||||
return (T)lhs == rhs;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool operator==(const T & lhs, const handle<T> & rhs)
|
||||
{
|
||||
return lhs == (T)rhs;
|
||||
}
|
||||
|
||||
} // namespace utils
|
||||
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2022 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
* Copyright (C) 2022 Patrick Nicolas <patricknicolas@laposte.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
namespace utils
|
||||
{
|
||||
template <typename T>
|
||||
struct enumerate_range
|
||||
{
|
||||
struct iterator
|
||||
{
|
||||
using underlying_iterator = std::conditional_t<std::is_const_v<T>, typename T::const_iterator, typename T::iterator>;
|
||||
using underlying_value_type = std::conditional_t<std::is_const_v<T>, const typename T::value_type, typename T::value_type>;
|
||||
|
||||
size_t index;
|
||||
underlying_iterator it;
|
||||
|
||||
std::pair<size_t, underlying_value_type &> operator*() const
|
||||
{
|
||||
return {index, *it};
|
||||
}
|
||||
|
||||
iterator & operator++()
|
||||
{
|
||||
++it;
|
||||
++index;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator==(const iterator & other) const
|
||||
{
|
||||
return it == other.it;
|
||||
}
|
||||
|
||||
bool operator!=(const iterator & other) const
|
||||
{
|
||||
return it != other.it;
|
||||
}
|
||||
};
|
||||
|
||||
T & range;
|
||||
|
||||
iterator begin() const
|
||||
{
|
||||
if constexpr (std::is_const_v<T>)
|
||||
return iterator{0, std::cbegin(range)};
|
||||
else
|
||||
return iterator{0, std::begin(range)};
|
||||
}
|
||||
|
||||
iterator end() const
|
||||
{
|
||||
if constexpr (std::is_const_v<T>)
|
||||
return iterator{0, std::cend(range)};
|
||||
else
|
||||
return iterator{0, std::end(range)};
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
enumerate_range<const T> enumerate(const T & t)
|
||||
{
|
||||
return {t};
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
enumerate_range<T> enumerate(T & t)
|
||||
{
|
||||
return {t};
|
||||
}
|
||||
|
||||
template <typename T1, typename T2>
|
||||
struct zip_range
|
||||
{
|
||||
struct iterator
|
||||
{
|
||||
using iterator1 = decltype(std::begin(std::declval<T1 &>()));
|
||||
using iterator2 = decltype(std::begin(std::declval<T2 &>()));
|
||||
|
||||
using value1 = decltype(*std::declval<iterator1>());
|
||||
using value2 = decltype(*std::declval<iterator2>());
|
||||
|
||||
iterator1 iter1;
|
||||
iterator2 iter2;
|
||||
|
||||
std::pair<value1 &, value2 &> operator*() const
|
||||
{
|
||||
return {*iter1, *iter2};
|
||||
}
|
||||
|
||||
iterator & operator++()
|
||||
{
|
||||
++iter1;
|
||||
++iter2;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator==(const iterator & other) const
|
||||
{
|
||||
return iter1 == other.iter1 || iter2 == other.iter2;
|
||||
}
|
||||
|
||||
bool operator!=(const iterator & other) const
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
};
|
||||
|
||||
T1 & range1;
|
||||
T2 & range2;
|
||||
|
||||
iterator begin() const
|
||||
{
|
||||
return iterator{std::begin(range1), std::begin(range2)};
|
||||
}
|
||||
|
||||
iterator end() const
|
||||
{
|
||||
return iterator{std::end(range1), std::end(range2)};
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T1, typename T2>
|
||||
zip_range<T1, T2> zip(T1 & range1, T2 & range2)
|
||||
{
|
||||
return zip_range<T1, T2>{range1, range2};
|
||||
}
|
||||
} // namespace utils
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2022 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
* Copyright (C) 2022 Patrick Nicolas <patricknicolas@laposte.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "strings.h"
|
||||
|
||||
std::string utils::trim(std::string input)
|
||||
{
|
||||
input.resize(input.find_last_not_of("\n ") + 1);
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
std::vector<std::string> utils::split(const std::string & s, const std::string & sep)
|
||||
{
|
||||
std::string::size_type i = 0;
|
||||
std::vector<std::string> v;
|
||||
|
||||
while (true)
|
||||
{
|
||||
std::string::size_type j = s.find_first_not_of(sep, i);
|
||||
if (j == std::string::npos)
|
||||
{
|
||||
v.push_back(s.substr(i + 1));
|
||||
return v;
|
||||
}
|
||||
|
||||
v.push_back(s.substr(i, j - i));
|
||||
i = j + 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2022 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
* Copyright (C) 2022 Patrick Nicolas <patricknicolas@laposte.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace utils
|
||||
{
|
||||
std::string trim(std::string input);
|
||||
|
||||
template <typename T>
|
||||
std::string join(const std::vector<T> & vec, const std::string & sep = ", ")
|
||||
{
|
||||
std::stringstream s;
|
||||
|
||||
if (!vec.empty())
|
||||
{
|
||||
s << vec[0];
|
||||
|
||||
for (size_t i = 1, n = vec.size(); i < n; i++)
|
||||
{
|
||||
s << sep << vec[i];
|
||||
}
|
||||
}
|
||||
|
||||
return s.str();
|
||||
}
|
||||
|
||||
std::vector<std::string> split(const std::string & s, const std::string & sep = "\n");
|
||||
|
||||
} // namespace utils
|
||||
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2022 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
* Copyright (C) 2022 Patrick Nicolas <patricknicolas@laposte.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cassert>
|
||||
#include <condition_variable>
|
||||
#include <deque>
|
||||
#include <exception>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
|
||||
namespace utils
|
||||
{
|
||||
class sync_queue_closed : public std::exception
|
||||
{
|
||||
public:
|
||||
const char * what() const noexcept override
|
||||
{
|
||||
return "sync_queue_closed";
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class sync_queue
|
||||
{
|
||||
std::deque<T> queue;
|
||||
std::condition_variable cv;
|
||||
std::mutex mutex;
|
||||
bool closed = false;
|
||||
|
||||
public:
|
||||
void push(T && item)
|
||||
{
|
||||
std::lock_guard lock(mutex);
|
||||
|
||||
queue.push_back(std::move(item));
|
||||
cv.notify_one();
|
||||
}
|
||||
|
||||
void push(const T & item)
|
||||
{
|
||||
std::lock_guard lock(mutex);
|
||||
|
||||
queue.push_back(item);
|
||||
cv.notify_one();
|
||||
}
|
||||
|
||||
template <typename Pred>
|
||||
std::optional<T> pop_if(Pred && pred)
|
||||
{
|
||||
std::unique_lock lock(mutex);
|
||||
|
||||
cv.wait(lock, [&]() { return !queue.empty() || closed; });
|
||||
|
||||
if (closed)
|
||||
throw sync_queue_closed{};
|
||||
|
||||
assert(!queue.empty());
|
||||
|
||||
if (pred(queue.front()))
|
||||
{
|
||||
T item = std::move(queue.front());
|
||||
queue.pop_front();
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
T pop()
|
||||
{
|
||||
std::unique_lock lock(mutex);
|
||||
|
||||
cv.wait(lock, [&]() { return !queue.empty() || closed; });
|
||||
|
||||
if (closed)
|
||||
throw sync_queue_closed{};
|
||||
|
||||
assert(!queue.empty());
|
||||
T item = std::move(queue.front());
|
||||
queue.pop_front();
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
template <typename Pred>
|
||||
void drop_until(Pred && pred)
|
||||
{
|
||||
std::unique_lock lock(mutex);
|
||||
|
||||
while (!queue.empty() && !pred(queue.front()))
|
||||
queue.pop_front();
|
||||
}
|
||||
|
||||
T & peek()
|
||||
{
|
||||
std::unique_lock lock(mutex);
|
||||
|
||||
cv.wait(lock, [&]() { return !queue.empty() || closed; });
|
||||
|
||||
if (closed)
|
||||
throw sync_queue_closed{};
|
||||
|
||||
assert(!queue.empty());
|
||||
return queue.front();
|
||||
}
|
||||
|
||||
void close()
|
||||
{
|
||||
std::lock_guard lock(mutex);
|
||||
closed = true;
|
||||
cv.notify_all();
|
||||
}
|
||||
};
|
||||
} // namespace utils
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2022 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
* Copyright (C) 2022 Patrick Nicolas <patricknicolas@laposte.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cassert>
|
||||
#include <cxxabi.h>
|
||||
#include <string>
|
||||
|
||||
template <typename T>
|
||||
std::string type_name()
|
||||
{
|
||||
int status;
|
||||
char * demangled = abi::__cxa_demangle(typeid(T).name(), nullptr, nullptr, &status);
|
||||
assert(status == 0);
|
||||
|
||||
std::string s = demangled;
|
||||
free(demangled);
|
||||
return s;
|
||||
}
|
||||
Reference in New Issue
Block a user