feat add marl for fiber

This commit is contained in:
tqcq
2024-03-08 18:05:40 +08:00
parent b94e31983b
commit 1782dba5ba
105 changed files with 13215 additions and 2 deletions

View File

@@ -38,7 +38,9 @@ private:
template<typename T>
class ThreadLocal final {
public:
ThreadLocal() : key_(detail::ThreadLocalManager::NextKey()) {}
static_assert(std::is_pointer<T>::value, "T must be a pointer type");
inline ThreadLocal() : key_(detail::ThreadLocalManager::NextKey()) {}
~ThreadLocal()
{ /*detail::ThreadLocalManager::Instance().Delete(key_); */

View File

@@ -0,0 +1,45 @@
#pragma once
#ifndef SLED_SYSTEM_FIBER_FIBER_SCHEDULER_H
#define SLED_SYSTEM_FIBER_FIBER_SCHEDULER_H
#include <marl/defer.h>
#include <marl/scheduler.h>
#include <marl/task.h>
namespace sled {
using FiberScheduler = marl::Scheduler;
// schedule() schedules the task T to be asynchronously called using the
// currently bound scheduler.
inline void
Schedule(marl::Task &&t)
{
MARL_ASSERT_HAS_BOUND_SCHEDULER("marl::schedule");
auto scheduler = marl::Scheduler::get();
scheduler->enqueue(std::move(t));
}
// schedule() schedules the function f to be asynchronously called with the
// given arguments using the currently bound scheduler.
template<typename Function, typename... Args>
inline void
Schedule(Function &&f, Args &&...args)
{
MARL_ASSERT_HAS_BOUND_SCHEDULER("marl::schedule");
auto scheduler = marl::Scheduler::get();
scheduler->enqueue(marl::Task(
std::bind(std::forward<Function>(f), std::forward<Args>(args)...)));
}
// schedule() schedules the function f to be asynchronously called using the
// currently bound scheduler.
template<typename Function>
inline void
Schedule(Function &&f)
{
MARL_ASSERT_HAS_BOUND_SCHEDULER("marl::schedule");
auto scheduler = marl::Scheduler::get();
scheduler->enqueue(marl::Task(std::forward<Function>(f)));
}
}// namespace sled
#endif// SLED_SYSTEM_FIBER_FIBER_SCHEDULER_H

View File

@@ -0,0 +1,10 @@
#pragma once
#ifndef SLED_SYSTEM_FIBER_FIBER_WAIT_GROUP_H
#define SLED_SYSTEM_FIBER_FIBER_WAIT_GROUP_H
#include <marl/waitgroup.h>
namespace sled {
using FiberWaitGroup = marl::WaitGroup;
}
#endif// SLED_SYSTEM_FIBER_FIBER_WAIT_GROUP_H