mirror of
https://github.com/EnderIce2/Fennix.git
synced 2025-05-28 15:34:31 +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 += --coverage
|
||||||
# CFLAGS += -pg
|
# CFLAGS += -pg
|
||||||
# CFLAGS += -finstrument-functions
|
# 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)
|
ifeq ($(OSARCH), amd64)
|
||||||
CFLAGS += -fverbose-asm
|
CFLAGS += -fverbose-asm
|
||||||
endif # amd64
|
endif # amd64
|
||||||
|
@ -57,11 +57,7 @@ namespace std
|
|||||||
};
|
};
|
||||||
error_condition make_error_condition(future_errc e) noexcept;
|
error_condition make_error_condition(future_errc e) noexcept;
|
||||||
|
|
||||||
const error_category &future_category() noexcept
|
const error_category &future_category() noexcept;
|
||||||
{
|
|
||||||
static const error_category cat;
|
|
||||||
return cat;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline std::error_code make_error_code(future_errc e) noexcept
|
inline std::error_code make_error_code(future_errc e) noexcept
|
||||||
{
|
{
|
||||||
@ -155,13 +151,16 @@ namespace std
|
|||||||
template <class R>
|
template <class R>
|
||||||
class promise
|
class promise
|
||||||
{
|
{
|
||||||
|
private:
|
||||||
public:
|
public:
|
||||||
promise();
|
promise() = default;
|
||||||
|
|
||||||
template <class Allocator>
|
template <class Allocator>
|
||||||
promise(allocator_arg_t, const Allocator &a);
|
promise(allocator_arg_t, const Allocator &a);
|
||||||
promise(promise &&rhs) noexcept;
|
|
||||||
|
promise(promise &&rhs) noexcept = default;
|
||||||
promise(const promise &) = delete;
|
promise(const promise &) = delete;
|
||||||
~promise();
|
~promise() = default;
|
||||||
|
|
||||||
promise &operator=(promise &&rhs) noexcept;
|
promise &operator=(promise &&rhs) noexcept;
|
||||||
promise &operator=(const promise &) = delete;
|
promise &operator=(const promise &) = delete;
|
||||||
@ -176,7 +175,11 @@ namespace std
|
|||||||
|
|
||||||
void set_exception(exception_ptr p);
|
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);
|
void set_exception_at_thread_exit(exception_ptr p);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -691,6 +691,6 @@ namespace std
|
|||||||
template <class T>
|
template <class T>
|
||||||
using result_of_t = typename result_of<T>::type;
|
using result_of_t = typename result_of<T>::type;
|
||||||
|
|
||||||
// template <class F, class... ArgTypes>
|
template <class F, class... ArgTypes>
|
||||||
// using invoke_result_t = typename invoke_result<F, ArgTypes...>::type;
|
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/>.
|
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// #include <future>
|
#include <future>
|
||||||
|
|
||||||
namespace std
|
namespace std
|
||||||
{
|
{
|
||||||
|
const error_category &future_category() noexcept
|
||||||
|
{
|
||||||
|
static const error_category cat;
|
||||||
|
return cat;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,12 +15,35 @@
|
|||||||
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// #include <future>
|
#include <future>
|
||||||
// #include <thread>
|
#include <thread>
|
||||||
// #include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
void test_stl_future()
|
void test_stl_future()
|
||||||
{
|
{
|
||||||
|
// {
|
||||||
|
// std::packaged_task<int()> task([]
|
||||||
|
// { return 7; });
|
||||||
|
// std::future<int> f1 = task.get_future();
|
||||||
|
// std::thread t(std::move(task));
|
||||||
|
|
||||||
|
// 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, []
|
// std::future<int> f = std::async(std::launch::async, []
|
||||||
// {
|
// {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user