Commit d39b3d5a authored by Xavier Thompson's avatar Xavier Thompson

Reroganise source tree into unified include/typon

parent 0988d534
#ifndef TYPON_CORE_CONTINUATION_HPP_INCLUDED
#define TYPON_CORE_CONTINUATION_HPP_INCLUDED
#ifndef TYPON_CONTINUATION_HPP_INCLUDED
#define TYPON_CONTINUATION_HPP_INCLUDED
#include <coroutine>
#include <cstdint>
......
#ifndef TYPON_FUNDAMENTAL_SCOPE_HPP_INCLUDED
#define TYPON_FUNDAMENTAL_SCOPE_HPP_INCLUDED
#ifndef TYPON_SCOPE_HPP_INCLUDED
#define TYPON_SCOPE_HPP_INCLUDED
#include <concepts>
namespace typon::fdt
namespace typon
{
template <std::invocable<> F>
struct defer
struct Defer
{
F _f;
~defer()
~Defer()
{
_f();
}
};
template <std::invocable<> F>
defer(F) -> defer<F>;
Defer(F) -> Defer<F>;
}
#endif // TYPON_FUNDAMENTAL_SCOPE_HPP_INCLUDED
#endif // TYPON_SCOPE_HPP_INCLUDED
#ifndef TYPON_EVENTCOUNT_HPP_INCLUDED
#define TYPON_EVENTCOUNT_HPP_INCLUDED
#ifndef TYPON_EVENT_COUNT_HPP_INCLUDED
#define TYPON_EVENT_COUNT_HPP_INCLUDED
#include <atomic>
#include <cstdint>
namespace typon::fdt::lock_free
namespace typon
{
template <unsigned int N = 10>
struct event_count
struct EventCount
{
using u64 = std::uint_fast64_t;
......@@ -63,4 +63,4 @@ namespace typon::fdt::lock_free
}
#endif // TYPON_EVENTCOUNT_HPP_INCLUDED
#endif // TYPON_EVENT_COUNT_HPP_INCLUDED
#ifndef TYPON_CORE_FORK_HPP_INCLUDED
#define TYPON_CORE_FORK_HPP_INCLUDED
#ifndef TYPON_FORK_HPP_INCLUDED
#define TYPON_FORK_HPP_INCLUDED
#include <coroutine>
#include <cstdint>
#include <typon/core/forked.hpp>
#include <typon/core/parent.hpp>
#include <typon/core/result.hpp>
#include <typon/core/scheduler.hpp>
#include <typon/forked.hpp>
#include <typon/parent.hpp>
#include <typon/result.hpp>
#include <typon/scheduler.hpp>
namespace typon
......
#ifndef TYPON_CORE_FORKED_HPP_INCLUDED
#define TYPON_CORE_FORKED_HPP_INCLUDED
#ifndef TYPON_FORKED_HPP_INCLUDED
#define TYPON_FORKED_HPP_INCLUDED
#include <coroutine>
#include <memory>
#include <type_traits>
#include <utility>
#include <typon/fundamental/scope.hpp>
#include <typon/core/result.hpp>
#include <typon/defer.hpp>
#include <typon/result.hpp>
namespace typon
......@@ -30,7 +29,7 @@ namespace typon
{
if (ready)
{
fdt::defer defer { [&coroutine]() { coroutine.destroy(); } };
Defer defer { [&coroutine]() { coroutine.destroy(); } };
std::construct_at(std::addressof(_value), coroutine.promise().get());
}
else
......@@ -152,7 +151,7 @@ namespace typon
{
if (ready)
{
fdt::defer defer { [&coroutine]() { coroutine.destroy(); } };
Defer defer { [&coroutine]() { coroutine.destroy(); } };
std::construct_at(std::addressof(_value), coroutine.promise().get());
}
else
......@@ -196,7 +195,7 @@ namespace typon
{
if (ready)
{
fdt::defer defer { [&coroutine]() { coroutine.destroy(); } };
Defer defer { [&coroutine]() { coroutine.destroy(); } };
_value = std::addressof(coroutine.promise().get());
}
else
......@@ -228,7 +227,7 @@ namespace typon
{
if (ready)
{
fdt::defer defer { [&coroutine]() { coroutine.destroy(); } };
Defer defer { [&coroutine]() { coroutine.destroy(); } };
coroutine.promise().get();
}
else
......
#ifndef TYPON_META_HPP_INCLUDED
#define TYPON_META_HPP_INCLUDED
namespace typon::fdt::meta
{
template <template <typename ...> typename T>
struct lazy
{
template <typename... Args>
using type = T<Args...>;
};
template <typename... T>
static constexpr bool always_false_v { false };
}
#endif // TYPON_META_HPP_INCLUDED
#ifndef TYPON_CORE_FUTURE_HPP_INCLUDED
#define TYPON_CORE_FUTURE_HPP_INCLUDED
#ifndef TYPON_FUTURE_HPP_INCLUDED
#define TYPON_FUTURE_HPP_INCLUDED
#include <atomic>
#include <coroutine>
#include <cstdint>
#include <typon/core/continuation.hpp>
#include <typon/core/result.hpp>
#include <typon/core/scheduler.hpp>
#include <typon/core/stack.hpp>
#include <typon/continuation.hpp>
#include <typon/result.hpp>
#include <typon/scheduler.hpp>
#include <typon/stack.hpp>
namespace typon
......@@ -183,4 +183,4 @@ namespace typon
}
#endif // TYPON_CORE_FUTURE_HPP_INCLUDED
#endif // TYPON_FUTURE_HPP_INCLUDED
#ifndef TYPON_FUNDAMENTAL_GARBAGE_COLLECTOR_HPP_INCLUDED
#define TYPON_FUNDAMENTAL_GARBAGE_COLLECTOR_HPP_INCLUDED
#ifndef TYPON_GARBAGE_COLLECTOR_HPP_INCLUDED
#define TYPON_GARBAGE_COLLECTOR_HPP_INCLUDED
#include <atomic>
#include <bit>
......@@ -7,10 +7,10 @@
#include <type_traits>
namespace typon::fdt::lock_free
namespace typon
{
struct garbage_collector
struct GarbageCollector
{
using u64 = std::uint_fast64_t;
using uint = unsigned int;
......@@ -50,7 +50,7 @@ namespace typon::fdt::lock_free
std::atomic<node *> _head;
std::atomic<node *> _tail;
garbage_collector(uint concurrency) noexcept
GarbageCollector(uint concurrency) noexcept
: _concurrency(concurrency)
, _bits(std::bit_width(concurrency))
, _stamps(new std::atomic<u64>[concurrency])
......@@ -66,19 +66,19 @@ namespace typon::fdt::lock_free
auto epoch(uint id) noexcept
{
struct epoch
struct Epoch
{
garbage_collector & _gc;
GarbageCollector & _gc;
uint _id;
~epoch()
~Epoch()
{
_gc.leave(_id);
}
};
enter(id);
return epoch { *this, id };
return Epoch { *this, id };
}
void enter(uint id) noexcept
......@@ -149,7 +149,7 @@ namespace typon::fdt::lock_free
}
}
~garbage_collector()
~GarbageCollector()
{
delete[] _stamps;
auto tail = _tail.load();
......@@ -164,4 +164,4 @@ namespace typon::fdt::lock_free
}
#endif // TYPON_FUNDAMENTAL_GARBAGE_COLLECTOR_HPP_INCLUDED
#endif // TYPON_GARBAGE_COLLECTOR_HPP_INCLUDED
#ifndef TYPON_CORE_JOIN_HPP_INCLUDED
#define TYPON_CORE_JOIN_HPP_INCLUDED
#ifndef TYPON_JOIN_HPP_INCLUDED
#define TYPON_JOIN_HPP_INCLUDED
#include <coroutine>
#include <utility>
#include <typon/core/parent.hpp>
#include <typon/core/result.hpp>
#include <typon/parent.hpp>
#include <typon/result.hpp>
namespace typon
......
#ifndef TYPON_CORE_PARENT_HPP_INCLUDED
#define TYPON_CORE_PARENT_HPP_INCLUDED
#ifndef TYPON_PARENT_HPP_INCLUDED
#define TYPON_PARENT_HPP_INCLUDED
#include <atomic>
#include <concepts>
......@@ -9,7 +9,7 @@
#include <limits>
#include <vector>
#include <typon/core/continuation.hpp>
#include <typon/continuation.hpp>
namespace typon
......@@ -104,4 +104,4 @@ namespace typon
}
#endif // TYPON_CORE_PARENT_HPP_INCLUDED
#endif // TYPON_PARENT_HPP_INCLUDED
#ifndef TYPON_CORE_POOL_HPP_INCLUDED
#define TYPON_CORE_POOL_HPP_INCLUDED
#ifndef TYPON_POOL_HPP_INCLUDED
#define TYPON_POOL_HPP_INCLUDED
#include <mutex>
#include <vector>
#include <typon/core/stack.hpp>
#include <typon/stack.hpp>
namespace typon
......@@ -66,4 +66,4 @@ namespace typon
}
#endif // TYPON_CORE_POOL_HPP_INCLUDED
#endif // TYPON_POOL_HPP_INCLUDED
#ifndef TYPON_CORE_PROMISE_HPP_INCLUDED
#define TYPON_CORE_PROMISE_HPP_INCLUDED
#ifndef TYPON_PROMISE_HPP_INCLUDED
#define TYPON_PROMISE_HPP_INCLUDED
#include <atomic>
#include <cstdint>
#include <memory>
#include <type_traits>
#include <typon/fundamental/scope.hpp>
#include <typon/core/stack.hpp>
#include <typon/core/scheduler.hpp>
#include <typon/defer.hpp>
#include <typon/stack.hpp>
#include <typon/scheduler.hpp>
namespace typon
......@@ -66,7 +65,7 @@ namespace typon
T await_resume() noexcept
{
fdt::defer defer( [this]() { std::destroy_at(std::addressof(_value)); });
Defer defer( [this]() { std::destroy_at(std::addressof(_value)); });
_consumed = true;
return std::move(_value);
}
......@@ -197,4 +196,4 @@ namespace typon
}
#endif // TYPON_CORE_PROMISE_HPP_INCLUDED
#endif // TYPON_PROMISE_HPP_INCLUDED
#ifndef TYPON_FUNDAMENTAL_RANDOM_HPP_INCLUDED
#define TYPON_FUNDAMENTAL_RANDOM_HPP_INCLUDED
#ifndef TYPON_RANDOM_HPP_INCLUDED
#define TYPON_RANDOM_HPP_INCLUDED
#include <random>
namespace typon::fdt::random
namespace typon::random
{
static thread_local std::mt19937 random { std::random_device{}() };
......@@ -14,4 +14,4 @@ namespace typon::fdt::random
}
#endif // TYPON_FUNDAMENTAL_RANDOM_HPP_INCLUDED
#endif // TYPON_RANDOM_HPP_INCLUDED
#ifndef TYPON_CORE_RESULT_HPP_INCLUDED
#define TYPON_CORE_RESULT_HPP_INCLUDED
#ifndef TYPON_RESULT_HPP_INCLUDED
#define TYPON_RESULT_HPP_INCLUDED
#include <exception>
......
#ifndef TYPON_FUNDAMENTAL_BINARY_RING_HPP_INCLUDED
#define TYPON_FUNDAMENTAL_BINARY_RING_HPP_INCLUDED
#ifndef TYPON_RING_HPP_INCLUDED
#define TYPON_RING_HPP_INCLUDED
#include <atomic>
#include <cstdint>
#include <type_traits>
namespace typon::fdt
namespace typon
{
template <typename I>
requires std::is_unsigned_v<I>
struct binary_ring
struct Ring
{
const I _mask;
binary_ring(std::uint_least8_t bits) noexcept
Ring(std::uint_least8_t bits) noexcept
: _mask((I(1) << bits) - 1)
{}
......@@ -24,7 +24,7 @@ namespace typon::fdt
return _mask + 1;
}
friend I operator % (I x, binary_ring ring) noexcept
friend I operator % (I x, Ring ring) noexcept
{
return x & ring._mask;
}
......@@ -33,4 +33,4 @@ namespace typon::fdt
}
#endif // TYPON_FUNDAMENTAL_BINARY_RING_HPP_INCLUDED
#endif // TYPON_RING_HPP_INCLUDED
#ifndef TYPON_FUNDAMENTAL_RINGBUFFER_HPP_INCLUDED
#define TYPON_FUNDAMENTAL_RINGBUFFER_HPP_INCLUDED
#ifndef TYPON_RING_BUFFER_HPP_INCLUDED
#define TYPON_RING_BUFFER_HPP_INCLUDED
#include <atomic>
#include <bit>
#include <cstdint>
#include <type_traits>
#include <typon/fundamental/binary_ring.hpp>
#include <typon/ring.hpp>
namespace typon::fdt::lock_free
namespace typon
{
template <typename T>
requires std::is_trivially_copyable_v<T>
&& std::is_trivially_destructible_v<T>
struct ring_buffer
struct RingBuffer
{
using u8 = std::uint_least8_t;
using u64 = std::uint_fast64_t;
using enum std::memory_order;
binary_ring<u64> _ring;
ring_buffer * _next;
Ring<u64> _ring;
RingBuffer * _next;
std::atomic<T> * const _array;
ring_buffer(u8 bits, ring_buffer * next = nullptr) noexcept
RingBuffer(u8 bits, RingBuffer * next = nullptr) noexcept
: _ring(bits)
, _next(next)
, _array(new std::atomic<T>[this->capacity()])
{}
~ring_buffer()
~RingBuffer()
{
delete [] _array;
if (_next)
......@@ -56,7 +56,7 @@ namespace typon::fdt::lock_free
return _array[index % _ring].load(relaxed);
}
ring_buffer * fill(ring_buffer * sink, u64 start, u64 end) noexcept
RingBuffer * fill(RingBuffer * sink, u64 start, u64 end) noexcept
{
for (u64 i = start; i < end; i++)
{
......@@ -65,15 +65,15 @@ namespace typon::fdt::lock_free
return sink;
}
ring_buffer * grow(u64 start, u64 end) noexcept
RingBuffer * grow(u64 start, u64 end) noexcept
{
auto buffer = new ring_buffer(std::countr_zero(_ring.size()) + 1, this);
auto buffer = new RingBuffer(std::countr_zero(_ring.size()) + 1, this);
return fill(buffer, start, end);
}
ring_buffer * shrink(u64 start, u64 end) noexcept
RingBuffer * shrink(u64 start, u64 end) noexcept
{
ring_buffer * last = nullptr;
RingBuffer * last = nullptr;
auto next = this;
auto size = (end - start);
auto threshold = size * 2;
......@@ -94,4 +94,4 @@ namespace typon::fdt::lock_free
}
#endif // TYPON_FUNDAMENTAL_RINGBUFFER_HPP_INCLUDED
#endif // TYPON_RING_BUFFER_HPP_INCLUDED
#ifndef TYPON_CORE_ROOT_HPP_INCLUDED
#define TYPON_CORE_ROOT_HPP_INCLUDED
#ifndef TYPON_ROOT_HPP_INCLUDED
#define TYPON_ROOT_HPP_INCLUDED
#include <atomic>
#include <coroutine>
#include <cstdint>
#include <typon/core/result.hpp>
#include <typon/core/scheduler.hpp>
#include <typon/result.hpp>
#include <typon/scheduler.hpp>
namespace typon
......
#ifndef TYPON_CORE_SCHEDULER_HPP_INCLUDED
#define TYPON_CORE_SCHEDULER_HPP_INCLUDED
#ifndef TYPON_SCHEDULER_HPP_INCLUDED
#define TYPON_SCHEDULER_HPP_INCLUDED
#include <atomic>
#include <bit>
......@@ -10,13 +10,12 @@
#include <utility>
#include <vector>
#include <typon/fundamental/event_count.hpp>
#include <typon/fundamental/garbage_collector.hpp>
#include <typon/fundamental/random.hpp>
#include <typon/core/continuation.hpp>
#include <typon/core/pool.hpp>
#include <typon/core/stack.hpp>
#include <typon/continuation.hpp>
#include <typon/event_count.hpp>
#include <typon/garbage_collector.hpp>
#include <typon/pool.hpp>
#include <typon/random.hpp>
#include <typon/stack.hpp>
namespace typon
......@@ -32,11 +31,11 @@ namespace typon
const uint _mask;
std::atomic<uint> _thieves = 0;
std::atomic<u64> _potential = 0;
fdt::lock_free::event_count<> _notifyer;
EventCount<> _notifyer;
std::vector<Pool> _pool;
std::vector<Stack *> _stack;
std::vector<std::thread> _thread;
fdt::lock_free::garbage_collector _gc;
GarbageCollector _gc;
static inline thread_local uint thread_id;
......@@ -177,7 +176,7 @@ namespace typon
{
continue;
}
auto index = size > 1 ? fdt::random::random() % size : 0;
auto index = size > 1 ? random::random() % size : 0;
auto stack = pool.get(index);
auto state = stack->_state.load();
if (state == Stack::ACTIVE)
......@@ -249,7 +248,7 @@ namespace typon
Pool & random() noexcept
{
return _pool[fdt::random::random() & _mask];
return _pool[random::random() & _mask];
}
~Scheduler() noexcept
......
......@@ -7,9 +7,8 @@
#include <type_traits>
#include <utility>
#include <typon/fundamental/ring_buffer.hpp>
#include <typon/core/continuation.hpp>
#include <typon/continuation.hpp>
#include <typon/ring_buffer.hpp>
namespace typon
......@@ -17,8 +16,8 @@ namespace typon
struct Stack
{
using ring_buffer = fdt::lock_free::ring_buffer<Continuation *>;
using u64 = ring_buffer::u64;
using RingBuffer = typon::RingBuffer<Continuation *>;
using u64 = RingBuffer::u64;
using enum std::memory_order;
......@@ -26,12 +25,12 @@ namespace typon
std::atomic<u64> _top {1};
std::atomic<u64> _bottom {1};
std::atomic<ring_buffer *> _buffer;
std::atomic<RingBuffer *> _buffer;
std::atomic<State> _state;
std::coroutine_handle<> _coroutine;
Stack(State state) noexcept
: _buffer(new ring_buffer(3))
: _buffer(new RingBuffer(3))
, _state(state)
{}
......@@ -44,7 +43,7 @@ namespace typon
{
u64 bottom = _bottom.load(relaxed);
u64 top = _top.load(acquire);
ring_buffer * buffer = _buffer.load(relaxed);
RingBuffer * buffer = _buffer.load(relaxed);
if (bottom - top > buffer->capacity() - 1)
{
buffer = buffer->grow(top, bottom);
......@@ -78,7 +77,7 @@ namespace typon
Continuation * peek() noexcept
{
u64 bottom = _bottom.load(relaxed) - 1;
ring_buffer * buffer = _buffer.load(relaxed);
RingBuffer * buffer = _buffer.load(relaxed);
return buffer->get(bottom);
}
......@@ -87,7 +86,7 @@ namespace typon
u64 top = _top.load(acquire);
std::atomic_thread_fence(seq_cst);
u64 bottom = _bottom.load(acquire);
ring_buffer * buffer = _buffer.load(consume);
RingBuffer * buffer = _buffer.load(consume);
if (top < bottom)
{
Continuation * x = buffer->get(top);
......@@ -118,7 +117,7 @@ namespace typon
return x;
}
ring_buffer * reclaim() noexcept
RingBuffer * reclaim() noexcept
{
u64 bottom = _bottom.load(relaxed);
u64 top = _top.load(relaxed);
......
#ifndef TYPON_CORE_TASK_HPP_INCLUDED
#define TYPON_CORE_TASK_HPP_INCLUDED
#ifndef TYPON_TASK_HPP_INCLUDED
#define TYPON_TASK_HPP_INCLUDED
#include <coroutine>
#include <utility>
#include <typon/core/result.hpp>
#include <typon/result.hpp>
namespace typon
......
......@@ -3,13 +3,13 @@
#include <utility>
#include <typon/core/fork.hpp>
#include <typon/core/forked.hpp>
#include <typon/core/future.hpp>
#include <typon/core/join.hpp>
#include <typon/core/promise.hpp>
#include <typon/core/root.hpp>
#include <typon/core/task.hpp>
#include <typon/fork.hpp>
#include <typon/forked.hpp>
#include <typon/future.hpp>
#include <typon/join.hpp>
#include <typon/promise.hpp>
#include <typon/root.hpp>
#include <typon/task.hpp>
namespace typon
......
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