Files
fennec/include/fennec/threading/detail/_thread.h
2025-12-17 01:11:28 -05:00

59 lines
1.9 KiB
C++

// =====================================================================================================================
// fennec, a free and open source game engine
// Copyright © 2025 Medusa Slockbower
//
// 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/>.
// =====================================================================================================================
///
/// \file _thread.h
/// \brief
///
///
/// \details
/// \author Medusa Slockbower
///
/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html))
///
///
#ifndef FENNEC_THREADING_DETAIL_THREAD_H
#define FENNEC_THREADING_DETAIL_THREAD_H
#include <fennec/containers/tuple.h>
#include <fennec/lang/function.h>
#include <fennec/memory/pointers.h>
namespace fennec::detail
{
template<typename FuncT, typename...ArgsT> using thread_proxy_t = tuple<FuncT, ArgsT...>;
template<typename FuncT, typename...ArgsT, size_t...I>
void _execute_thread(thread_proxy_t<function<FuncT>, ArgsT...>& data, index_metasequence<I...>) {
auto func = data.template get<0>();
func(fennec::move(data.template get<I + 1>()) ...);
}
template<typename DataT>
void* _run_thread(void* data) {
unique_ptr<DataT> ptr(data);
detail::_execute_thread(*ptr, make_index_metasequence_t<DataT::size - 1>{});
return nullptr;
}
}
#endif // FENNEC_THREADING_DETAIL_THREAD_H