feat(kernel): update stl headers

Signed-off-by: EnderIce2 <enderice2@protonmail.com>
This commit is contained in:
2025-03-29 18:27:57 +00:00
parent 31181d5b5d
commit 93d897e95c
16 changed files with 1042 additions and 29 deletions

View File

@ -25,18 +25,18 @@ __constructor void TestRandom()
{
#if defined(__amd64__) || defined(__i386__)
int RDRANDFlag = 0;
if (strcmp(CPU::Vendor(), x86_CPUID_VENDOR_AMD) == 0)
if (std::strcmp(CPU::Vendor(), x86_CPUID_VENDOR_AMD) == 0)
{
CPU::x86::AMD::CPUID0x00000001 cpuid;
RDRANDFlag = cpuid.ECX.RDRAND;
}
else if (strcmp(CPU::Vendor(), x86_CPUID_VENDOR_INTEL) == 0)
else if (std::strcmp(CPU::Vendor(), x86_CPUID_VENDOR_INTEL) == 0)
{
CPU::x86::Intel::CPUID0x00000001 cpuid;
RDRANDFlag = cpuid.ECX.RDRAND;
}
if (strcmp(CPU::Hypervisor(), x86_CPUID_VENDOR_TCG) == 0)
if (std::strcmp(CPU::Hypervisor(), x86_CPUID_VENDOR_TCG) == 0)
RDRANDFlag = 0;
if (RDRANDFlag)

View File

@ -0,0 +1,136 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel 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.
Fennix Kernel 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 Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
// #include <future>
// #include <thread>
// #include <assert.h>
void test_stl_future()
{
// {
// std::future<int> f = std::async(std::launch::async, []
// {
// for (uint64_t i = 0; i < 100000; ++i);
// return 1; });
// debug("waiting for future");
// int result = f.get();
// debug("future result is %d", result);
// }
// {
// std::promise<int> p;
// std::future<int> f = p.get_future();
// assert(f.valid());
// p.set_value(42);
// assert(f.get() == 42);
// try
// {
// f.get();
// assert(false);
// }
// catch (const std::future_error &e)
// {
// // assert(e.code() == std::future_errc::future_already_retrieved);
// }
// }
// {
// auto future = std::async([]()
// { return 42; });
// assert(future.get() == 42);
// }
// {
// std::promise<int> p;
// std::future<int> f = p.get_future();
// std::shared_future<int> sf = f.share();
// p.set_value(42);
// assert(sf.get() == 42);
// assert(sf.get() == 42);
// }
// {
// std::promise<int> p;
// std::future<int> f = p.get_future();
// auto status = f.wait_for(std::chrono::milliseconds(100));
// assert(status == std::future_status::timeout);
// p.set_value(42);
// status = f.wait_for(std::chrono::milliseconds(100));
// assert(status == std::future_status::ready);
// }
// {
// auto future = std::async(std::launch::async, []()
// { return 42; });
// assert(future.get() == 42);
// auto deferred = std::async(std::launch::deferred, []()
// { return 42; });
// assert(deferred.get() == 42);
// }
// {
// std::promise<int> p1, p2;
// std::future<int> f1 = p1.get_future();
// std::future<int> f2 = p2.get_future();
// p1.set_value(42);
// p2.set_value(24);
// assert(f1.get() == 42);
// assert(f2.get() == 24);
// }
// {
// std::promise<int> p;
// std::future<int> f1 = p.get_future();
// std::future<int> f2 = std::move(f1);
// p.set_value(42);
// assert(f2.get() == 42);
// }
// {
// std::promise<int> p;
// std::shared_future<int> sf = p.get_future().share();
// std::atomic<int> sum{0};
// std::vector<std::thread> threads;
// for (int i = 0; i < 10; ++i)
// {
// threads.emplace_back([&sf, &sum]()
// { sum += sf.get(); });
// }
// p.set_value(42);
// for (auto &t : threads)
// {
// t.join();
// }
// assert(sum == 420);
// }
}

View File

@ -25,6 +25,7 @@ void test_stl_vector();
void test_stl_bitset();
void test_stl_string();
void test_stl_unordered_map() {}
void test_stl_future();
void Test_stl()
{
@ -36,6 +37,7 @@ void Test_stl()
test_stl_bitset();
test_stl_string();
test_stl_unordered_map();
test_stl_future();
}
#endif // DEBUG
#endif // DEBUG