mirror of
https://github.com/EnderIce2/Fennix.git
synced 2025-05-25 22:14:34 +00:00
refactor(kernel): improve future implementation
Signed-off-by: EnderIce2 <enderice2@protonmail.com>
This commit is contained in:
parent
8d71ed0ad5
commit
ffd992cd74
@ -67,7 +67,7 @@ ifeq ($(DEBUG), 1)
|
||||
# CFLAGS += --coverage
|
||||
# CFLAGS += -pg
|
||||
# CFLAGS += -finstrument-functions
|
||||
CFLAGS += -DDEBUG -ggdb3 -O0 -fdiagnostics-color=always -fstack-usage -fsanitize=undefined
|
||||
CFLAGS += -DDEBUG -ggdb3 -O0 -fdiagnostics-color=always -fstack-usage -fsanitize=undefined -fdiagnostics-all-candidates
|
||||
ifeq ($(OSARCH), amd64)
|
||||
CFLAGS += -fverbose-asm
|
||||
endif # amd64
|
||||
|
@ -57,11 +57,7 @@ namespace std
|
||||
};
|
||||
error_condition make_error_condition(future_errc e) noexcept;
|
||||
|
||||
const error_category &future_category() noexcept
|
||||
{
|
||||
static const error_category cat;
|
||||
return cat;
|
||||
}
|
||||
const error_category &future_category() noexcept;
|
||||
|
||||
inline std::error_code make_error_code(future_errc e) noexcept
|
||||
{
|
||||
@ -155,13 +151,16 @@ namespace std
|
||||
template <class R>
|
||||
class promise
|
||||
{
|
||||
private:
|
||||
public:
|
||||
promise();
|
||||
promise() = default;
|
||||
|
||||
template <class Allocator>
|
||||
promise(allocator_arg_t, const Allocator &a);
|
||||
promise(promise &&rhs) noexcept;
|
||||
|
||||
promise(promise &&rhs) noexcept = default;
|
||||
promise(const promise &) = delete;
|
||||
~promise();
|
||||
~promise() = default;
|
||||
|
||||
promise &operator=(promise &&rhs) noexcept;
|
||||
promise &operator=(const promise &) = delete;
|
||||
@ -176,7 +175,11 @@ namespace std
|
||||
|
||||
void set_exception(exception_ptr p);
|
||||
|
||||
void set_value_at_thread_exit(/* see description */);
|
||||
void set_value_at_thread_exit(const R &value);
|
||||
void set_value_at_thread_exit(R &&value);
|
||||
void set_value_at_thread_exit(R &value);
|
||||
void set_value_at_thread_exit();
|
||||
|
||||
void set_exception_at_thread_exit(exception_ptr p);
|
||||
};
|
||||
|
||||
|
@ -691,6 +691,6 @@ namespace std
|
||||
template <class T>
|
||||
using result_of_t = typename result_of<T>::type;
|
||||
|
||||
// template <class F, class... ArgTypes>
|
||||
// using invoke_result_t = typename invoke_result<F, ArgTypes...>::type;
|
||||
template <class F, class... ArgTypes>
|
||||
using invoke_result_t = typename invoke_result<F, ArgTypes...>::type;
|
||||
}
|
||||
|
@ -15,9 +15,13 @@
|
||||
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// #include <future>
|
||||
#include <future>
|
||||
|
||||
namespace std
|
||||
{
|
||||
|
||||
const error_category &future_category() noexcept
|
||||
{
|
||||
static const error_category cat;
|
||||
return cat;
|
||||
}
|
||||
}
|
||||
|
@ -15,22 +15,45 @@
|
||||
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// #include <future>
|
||||
// #include <thread>
|
||||
// #include <assert.h>
|
||||
#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; });
|
||||
// {
|
||||
// std::packaged_task<int()> task([]
|
||||
// { return 7; });
|
||||
// std::future<int> f1 = task.get_future();
|
||||
// std::thread t(std::move(task));
|
||||
|
||||
// debug("waiting for future");
|
||||
// int result = f.get();
|
||||
// debug("future result is %d", result);
|
||||
// }
|
||||
// std::future<int> f2 = std::async(std::launch::async, []
|
||||
// { return 8; });
|
||||
|
||||
// std::promise<int> p;
|
||||
// std::future<int> f3 = p.get_future();
|
||||
// std::thread([&p]
|
||||
// { p.set_value_at_thread_exit(9); })
|
||||
// .detach();
|
||||
|
||||
// debug("Waiting for futures...");
|
||||
// f1.wait();
|
||||
// f2.wait();
|
||||
// f3.wait();
|
||||
// debug("results: %d %d %d", f1.get(), f2.get(), f3.get());
|
||||
// t.join();
|
||||
// }
|
||||
|
||||
// {
|
||||
// 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;
|
||||
@ -57,16 +80,16 @@ void test_stl_future()
|
||||
// assert(future.get() == 42);
|
||||
// }
|
||||
|
||||
// {
|
||||
// std::promise<int> p;
|
||||
// std::future<int> f = p.get_future();
|
||||
// std::shared_future<int> sf = f.share();
|
||||
// {
|
||||
// std::promise<int> p;
|
||||
// std::future<int> f = p.get_future();
|
||||
// std::shared_future<int> sf = f.share();
|
||||
|
||||
// p.set_value(42);
|
||||
// p.set_value(42);
|
||||
|
||||
// assert(sf.get() == 42);
|
||||
// assert(sf.get() == 42);
|
||||
// }
|
||||
// assert(sf.get() == 42);
|
||||
// assert(sf.get() == 42);
|
||||
// }
|
||||
|
||||
// {
|
||||
// std::promise<int> p;
|
||||
|
Loading…
x
Reference in New Issue
Block a user