Commit d997bff4 authored by Xavier Thompson's avatar Xavier Thompson

Rename parent.hpp into span.hpp

parent a06701ba
......@@ -5,9 +5,9 @@
#include <cstdint>
#include <typon/forked.hpp>
#include <typon/parent.hpp>
#include <typon/result.hpp>
#include <typon/scheduler.hpp>
#include <typon/span.hpp>
namespace typon
......@@ -17,7 +17,7 @@ namespace typon
struct [[nodiscard]] Fork
{
struct promise_type;
using u64 = Parent::u64;
using u64 = Span::u64;
std::coroutine_handle<promise_type> _coroutine;
......@@ -33,7 +33,7 @@ namespace typon
struct promise_type : Result<T>
{
Parent * _parent;
Span * _span;
ForkList::Node _node;
Fork get_return_object() noexcept
......@@ -52,15 +52,15 @@ namespace typon
{
std::coroutine_handle<> await_suspend(std::coroutine_handle<promise_type> coroutine) noexcept
{
auto parent = coroutine.promise()._parent;
auto span = coroutine.promise()._span;
if (Scheduler::pop())
{
return parent->_coroutine;
return span->_coroutine;
}
u64 n = parent->_n.fetch_sub(1, std::memory_order_acq_rel);
u64 n = span->_n.fetch_sub(1, std::memory_order_acq_rel);
if (n == 1)
{
return parent->continuation();
return span->continuation();
}
return std::noop_coroutine();
}
......@@ -87,22 +87,22 @@ namespace typon
template <typename Promise>
auto await_suspend(std::coroutine_handle<Promise> continuation) noexcept
{
Parent * parent = &(continuation.promise()._data);
_coroutine.promise()._parent = parent;
_thefts = parent->_thefts;
Span * span = &(continuation.promise()._span);
_coroutine.promise()._span = span;
_thefts = span->_thefts;
std::coroutine_handle<> on_stack_handle = _coroutine;
Scheduler::push(parent);
Scheduler::push(span);
return on_stack_handle;
}
auto await_resume()
{
auto parent = _coroutine.promise()._parent;
bool stolen = parent->_thefts > _thefts;
auto span = _coroutine.promise()._span;
bool stolen = span->_thefts > _thefts;
if (stolen)
{
parent->_children.insert(_coroutine);
span->_children.insert(_coroutine);
}
return Forked<T>(_coroutine, !stolen);
}
......
......@@ -4,8 +4,8 @@
#include <coroutine>
#include <utility>
#include <typon/parent.hpp>
#include <typon/result.hpp>
#include <typon/span.hpp>
namespace typon
......@@ -40,20 +40,20 @@ namespace typon
{
if (_coroutine)
{
_coroutine.promise()._data._children.clear();
_coroutine.promise()._span._children.clear();
_coroutine.destroy();
}
}
struct promise_type : Result<T>
{
using u64 = Parent::u64;
static constexpr u64 UMAX = Parent::UMAX;
using u64 = Span::u64;
static constexpr u64 UMAX = Span::UMAX;
Parent _data;
Span _span;
promise_type() noexcept
: _data(std::coroutine_handle<promise_type>::from_promise(*this))
: _span(std::coroutine_handle<promise_type>::from_promise(*this))
{}
Join get_return_object() noexcept
......@@ -76,13 +76,13 @@ namespace typon
{
struct awaitable
{
Parent & _data;
Span & _span;
bool await_ready() noexcept
{
if (u64 thefts = _data._thefts)
if (u64 thefts = _span._thefts)
{
u64 n = _data._n.load(std::memory_order_acquire);
u64 n = _span._n.load(std::memory_order_acquire);
if (n - (UMAX - thefts) == 0)
{
return true;
......@@ -94,8 +94,8 @@ namespace typon
std::coroutine_handle<> await_suspend(std::coroutine_handle<promise_type> coroutine) noexcept
{
u64 thefts = _data._thefts;
u64 n = _data._n.fetch_sub(UMAX - thefts, std::memory_order_acq_rel);
u64 thefts = _span._thefts;
u64 n = _span._n.fetch_sub(UMAX - thefts, std::memory_order_acq_rel);
if (n - (UMAX - thefts) == 0)
{
return coroutine;
......@@ -105,13 +105,13 @@ namespace typon
void await_resume()
{
_data._thefts = 0;
_data._n.store(UMAX, std::memory_order_release);
_data._children.check_exceptions();
_span._thefts = 0;
_span._n.store(UMAX, std::memory_order_release);
_span._children.check_exceptions();
}
};
return awaitable { _data };
return awaitable { _span };
}
auto final_suspend() noexcept
......@@ -120,16 +120,16 @@ namespace typon
{
std::coroutine_handle<> await_suspend(std::coroutine_handle<promise_type> coroutine) noexcept
{
Parent & data = coroutine.promise()._data;
u64 thefts = data._thefts;
Span & span = coroutine.promise()._span;
u64 thefts = span._thefts;
if (thefts == 0)
{
return data._continuation;
return span._continuation;
}
u64 n = data._n.fetch_sub(UMAX - thefts, std::memory_order_acq_rel);
u64 n = span._n.fetch_sub(UMAX - thefts, std::memory_order_acq_rel);
if (n - (UMAX - thefts) == 0)
{
return data._continuation;
return span._continuation;
}
return std::noop_coroutine();
}
......@@ -152,13 +152,13 @@ namespace typon
std::coroutine_handle<> await_suspend(std::coroutine_handle<> continuation) noexcept
{
_coroutine.promise()._data._continuation = continuation;
_coroutine.promise()._span._continuation = continuation;
return _coroutine;
}
decltype(auto) await_resume()
{
_coroutine.promise()._data._children.check_exceptions();
_coroutine.promise()._span._children.check_exceptions();
return _coroutine.promise().get();
}
};
......
#ifndef TYPON_PARENT_HPP_INCLUDED
#define TYPON_PARENT_HPP_INCLUDED
#ifndef TYPON_SPAN_HPP_INCLUDED
#define TYPON_SPAN_HPP_INCLUDED
#include <atomic>
#include <concepts>
......@@ -65,7 +65,7 @@ namespace typon
};
struct Parent : Continuation
struct Span : Continuation
{
using u64 = Continuation::u64;
......@@ -77,7 +77,7 @@ namespace typon
std::atomic<u64> _n = UMAX;
Parent(std::coroutine_handle<> coroutine) noexcept
Span(std::coroutine_handle<> coroutine) noexcept
: Continuation(coroutine)
{}
......@@ -104,4 +104,4 @@ namespace typon
}
#endif // TYPON_PARENT_HPP_INCLUDED
#endif // TYPON_SPAN_HPP_INCLUDED
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment