22# if __cplusplus >= 201103L
23# include <initializer_list>
25# include <type_traits>
28# if __cplusplus < 201103L
29# undef ZTH_TYPEDFIBER98
31# define ZTH_TYPEDFIBER98 1
32# elif !defined(ZTH_TYPEDFIBER98)
35# define ZTH_TYPEDFIBER98 0
75# ifdef ZTH_FUTURE_EXCEPTION
120# ifdef ZTH_FUTURE_EXCEPTION
124# ifdef ZTH_FUTURE_EXCEPTION
133 template <
typename T>
146# ifdef ZTH_FUTURE_EXCEPTION
154 SharedPointer<Future_type> m_future;
185TypedFiber<R>& operator<<(TypedFiber<R>& fiber, setStackSize
const& m)
188 int res = fiber.setStackSize(m.stack);
203# if __cplusplus >= 201103L
215 explicit setName(
char const* n)
219 explicit setName(
string const& n)
224# if __cplusplus >= 201103L
238# if __cplusplus >= 201103L
240TypedFiber<R>& operator<<(TypedFiber<R>& fiber, setName&& m)
242 fiber.setName(std::move(m.name));
275 static_cast<Gate*
>(g)->pass();
283 fiber.atExit(&passOnExit::atExit,
static_cast<void*
>(&m.
gate));
288TypedFiber<R>& operator<<(TypedFiber<R>& fiber, passOnExit
const& m)
290 static_cast<Fiber&
>(fiber) << m;
317 return fiber.withFuture();
331class TypedFiber0 final :
public TypedFiber<R> {
334 typedef TypedFiber<R> base;
335 typedef R (*Function)();
337 explicit TypedFiber0(Function function)
338 : m_function(function)
344 virtual
void entry_() final
346 this->setFuture(m_function());
354class TypedFiber0<void> final :
public TypedFiber<void> {
357 typedef TypedFiber<void> base;
358 typedef void (*Function)();
360 explicit TypedFiber0(Function func)
364 virtual ~TypedFiber0() noexcept final
is_default
367 virtual
void entry_() final
377template <
typename R,
typename A1>
378class TypedFiber1 final :
public TypedFiber<R> {
381 typedef TypedFiber<R> base;
382 typedef R (*Function)(A1);
384 TypedFiber1(Function func, A1 a1)
389 virtual ~TypedFiber1() noexcept final
is_default
392 virtual
void entry_() final
394 this->setFuture(m_function(m_a1));
402template <
typename A1>
403class TypedFiber1<void, A1> final :
public TypedFiber<void> {
406 typedef TypedFiber<void> base;
407 typedef void (*Function)(A1);
410 TypedFiber1(Function func, A1 a1)
415 virtual ~TypedFiber1() noexcept final
is_default
418 virtual
void entry_() final
429template <
typename R,
typename A1,
typename A2>
430class TypedFiber2 final :
public TypedFiber<R> {
433 typedef TypedFiber<R> base;
434 typedef R (*Function)(A1, A2);
436 TypedFiber2(Function func, A1 a1, A2 a2)
442 virtual ~TypedFiber2() noexcept final
is_default
445 virtual
void entry_() final
447 this->setFuture(m_function(m_a1, m_a2));
456template <
typename A1,
typename A2>
457class TypedFiber2<void, A1, A2> final :
public TypedFiber<void> {
460 typedef TypedFiber<void> base;
461 typedef void (*Function)(A1, A2);
464 TypedFiber2(Function func, A1 a1, A2 a2)
470 virtual ~TypedFiber2() noexcept final
is_default
473 virtual
void entry_() final
475 m_function(m_a1, m_a2);
485template <
typename R,
typename A1,
typename A2,
typename A3>
486class TypedFiber3 final :
public TypedFiber<R> {
489 typedef TypedFiber<R> base;
490 typedef R (*Function)(A1, A2, A3);
492 TypedFiber3(Function func, A1 a1, A2 a2, A3 a3)
499 virtual ~TypedFiber3() noexcept final
is_default
502 virtual
void entry_() final
504 this->setFuture(m_function(m_a1, m_a2, m_a3));
514template <
typename A1,
typename A2,
typename A3>
515class TypedFiber3<void, A1, A2, A3> final :
public TypedFiber<void> {
518 typedef TypedFiber<void> base;
519 typedef void (*Function)(A1, A2, A3);
522 TypedFiber3(Function func, A1 a1, A2 a2, A3 a3)
529 virtual ~TypedFiber3() noexcept final
is_default
532 virtual
void entry_() final
534 m_function(m_a1, m_a2, m_a3);
546# if __cplusplus >= 201103L
548template <typename T, typename std::enable_if<!std::is_lvalue_reference<T>::value,
int>::type = 0>
549static constexpr T&& move_or_ref(T& t)
noexcept
554template <typename T, typename std::enable_if<std::is_lvalue_reference<T>::value,
int>::type = 0>
555static constexpr T move_or_ref(T t)
noexcept
566template <
typename F,
typename R,
typename Args>
573 template <
typename F_,
typename... Args_>
575 : m_function{
std::forward<F_>(func)}
576 , m_args{
std::forward<Args_>(args)...}
584 entry__(
typename SequenceGenerator<std::tuple_size<Args>::value>::type());
588 template <
size_t... S>
592 move_or_ref<
typename std::tuple_element<S, Args>::type>(
593 std::get<S>(m_args))...));
601template <
typename F,
typename Args>
608 template <
typename F_,
typename... Args_>
610 : m_function{
std::forward<F_>(func)}
611 , m_args{
std::forward<Args_>(args)...}
619 entry__(
typename SequenceGenerator<std::tuple_size<Args>::value>::type());
623 template <
size_t... S>
627 move_or_ref<
typename std::tuple_element<S, Args>::type>(
628 std::get<S>(m_args))...);
649# define REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_(P, PArgs, suffix, ...) \
650 template <typename R, ##__VA_ARGS__> \
651 struct remove_function_cvref<R P PArgs suffix> { \
652 typedef R(type) PArgs; \
656# define REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_A0(P, suffix) \
657 REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_(P, (), suffix)
658# define REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_A1(P, suffix) \
659 REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_(P, (A1), suffix, typename A1)
660# define REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_A2(P, suffix) \
661 REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_(P, (A1, A2), suffix, typename A1, typename A2)
662# define REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_A3(P, suffix) \
663 REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_( \
664 P, (A1, A2, A3), suffix, typename A1, typename A2, typename A3)
666# define REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_A(P, suffix) \
667 REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_A0(P, suffix) \
668 REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_A1(P, suffix) \
669 REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_A2(P, suffix) \
670 REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_A3(P, suffix)
672# define REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_A(P, suffix)
675# if __cplusplus >= 201103L
676# define REMOVE_FUNCTION_CVREF_SPECIALIZATIONS(P, suffix) \
677 REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_A(P, suffix) \
678 REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_(P, (Args...), suffix, typename... Args)
680# define REMOVE_FUNCTION_CVREF_SPECIALIZATIONS(P, suffix) \
681 REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_A(P, suffix)
689# if defined(__cpp_noexcept_function_type) && __cpp_noexcept_function_type >= 201510
696# undef REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_
697# undef REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_A0
698# undef REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_A1
699# undef REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_A2
700# undef REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_A3
701# undef REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_A
702# undef REMOVE_FUNCTION_CVREF_SPECIALIZATIONS
704# define REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_(PArgs, cvref, ...) \
705 template <typename R, typename C, ##__VA_ARGS__> \
706 struct remove_function_cvref<R(C::*) PArgs cvref> { \
707 typedef R(type) PArgs; \
711# define REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_A0(cvref) \
712 REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_((), cvref)
713# define REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_A1(cvref) \
714 REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_((A1), cvref, typename A1)
715# define REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_A2(cvref) \
716 REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_((A1, A2), cvref, typename A1, typename A2)
717# define REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_A3(cvref) \
718 REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_( \
719 (A1, A2, A3), cvref, typename A1, typename A2, typename A3)
720# define REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_A(cvref) \
721 REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_A0(cvref) \
722 REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_A1(cvref) \
723 REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_A2(cvref) \
724 REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_A3(cvref)
726# define REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_A(cvref)
729# if __cplusplus >= 201103L
730# define REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS(cvref) \
731 REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_A(cvref) \
732 REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_((Args...), cvref, typename... Args)
734# define REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS(cvref) \
735 REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_A(cvref)
738# define REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_CV(...) \
739 REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS(__VA_ARGS__) \
740 REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS(const __VA_ARGS__) \
741 REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS(volatile __VA_ARGS__) \
742 REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS(const volatile __VA_ARGS__)
745# if __cplusplus >= 201103L
749# if defined(__cpp_noexcept_function_type) && __cpp_noexcept_function_type >= 201510
756# undef REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_
757# undef REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_A0
758# undef REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_A1
759# undef REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_A2
760# undef REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_A3
761# undef REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_A
762# undef REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS
763# undef REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_CV
765# if __cplusplus >= 201103L
769template <
typename R,
typename... Args>
786 using args_type =
typename functor_operator_type_::args_type;
790template <
typename R,
typename... Args>
798template <
typename R,
typename... Args>
807template <
typename R,
typename... Args>
816template <
typename R,
typename... Args>
843# define ZTH_TYPEDFIBERTYPE_SPECIALIZATION(P) \
844 template <typename R> \
845 struct TypedFiberType<R P()> { \
847 typedef R returnType; \
848 typedef TypedFiber0<R> fiberType; \
849 typedef NoArg a1Type; \
850 typedef NoArg a2Type; \
851 typedef NoArg a3Type; \
854 template <typename R, typename A1> \
855 struct TypedFiberType<R P(A1)> { \
857 typedef R returnType; \
858 typedef TypedFiber1<R, A1> fiberType; \
860 typedef NoArg a2Type; \
861 typedef NoArg a3Type; \
864 template <typename R, typename A1, typename A2> \
865 struct TypedFiberType<R P(A1, A2)> { \
867 typedef R returnType; \
868 typedef TypedFiber2<R, A1, A2> fiberType; \
871 typedef NoArg a3Type; \
874 template <typename R, typename A1, typename A2, typename A3> \
875 struct TypedFiberType<R P(A1, A2, A3)> { \
877 typedef R returnType; \
878 typedef TypedFiber3<R, A1, A2, A3> fiberType; \
884ZTH_TYPEDFIBERTYPE_SPECIALIZATION()
885ZTH_TYPEDFIBERTYPE_SPECIALIZATION((*))
886ZTH_TYPEDFIBERTYPE_SPECIALIZATION((*&))
887ZTH_TYPEDFIBERTYPE_SPECIALIZATION((&))
889# undef ZTH_TYPEDFIBERTYPE_SPECIALIZATION
906# define FUNCTION_TYPE_HELPER_SPECIALIZATION(P) \
907 template <typename R> \
908 struct function_type_helper<R P()> { \
909 typedef R (*type)(); \
912 template <typename R, typename A1> \
913 struct function_type_helper<R P(A1)> { \
914 typedef R (*type)(A1); \
917 template <typename R, typename A1, typename A2> \
918 struct function_type_helper<R P(A1, A2)> { \
919 typedef R (*type)(A1, A2); \
922 template <typename R, typename A1, typename A2, typename A3> \
923 struct function_type_helper<R P(A1, A2, A3)> { \
924 typedef R (*type)(A1, A2, A3); \
927FUNCTION_TYPE_HELPER_SPECIALIZATION()
928FUNCTION_TYPE_HELPER_SPECIALIZATION((*))
929FUNCTION_TYPE_HELPER_SPECIALIZATION((*&))
930FUNCTION_TYPE_HELPER_SPECIALIZATION((&))
932# undef FUNCTION_TYPE_HELPER_SPECIALIZATION
935# if __cplusplus >= 201103L
936template <
typename R,
typename... Args>
941template <
typename R,
typename... Args>
946template <
typename R,
typename... Args>
951template <
typename R,
typename... Args>
969 : m_function(function)
973# if __cplusplus >= 201103L
974 template <
typename F_>
976 : m_function{std::forward<F_>(function)}
996 fiber_type<Function>
operator()(A1 a1, A2 a2)
const
1001 fiber_type<Function>
operator()(A1 a1, A2 a2, A3 a3)
const
1007# if __cplusplus >= 201103L
1008 template <
typename... Args>
1036template <
typename F>
1082 return _fiber->withFuture();
1105 template <
typename Manipulator>
1112 template <
typename Manipulator>
1119# if __cplusplus >= 201103L
1120 template <
typename Manipulator>
1124 return std::move(*
this);
1141static inline char const* fiber_name(
char const* name)
1150# if __cplusplus >= 201103L
1159template <
typename F>
1165template <
typename F>
1171template <
typename F>
1172typename fiber_type<F>::factory factory(F f,
char const* name =
nullptr)
1174 return typename fiber_type<F>::factory(f, impl::fiber_name(name));
1178# if ZTH_TYPEDFIBER98
1179template <
typename F>
1180typename fiber_type<F>::fiber
fiber(F f)
1182 return factory<F>(f)();
1185template <
typename F>
1186typename fiber_type<F>::fiber
fiber(F f,
typename fiber_type<F>::factory::A1 a1)
1188 return factory<F>(f)(a1);
1191template <
typename F>
1192typename fiber_type<F>::fiber
1193fiber(F f,
typename fiber_type<F>::factory::A1 a1,
typename fiber_type<F>::factory::A2 a2)
1195 return factory<F>(f)(a1, a2);
1198template <
typename F>
1199typename fiber_type<F>::fiber
1200fiber(F f,
typename fiber_type<F>::factory::A1 a1,
typename fiber_type<F>::factory::A2 a2,
1201 typename fiber_type<F>::factory::A3 a3)
1203 return factory<F>(f)(a1, a2, a3);
1207# if __cplusplus >= 201103L
1220template <
typename F,
typename... Args>
1223 return factory<F>(std::forward<F>(f))(std::forward<Args>(args)...);
1234template <
typename F>
1239# if ZTH_TYPEDFIBER98
1240template <
typename R>
1241struct is_function_<R()> {
1244template <
typename R,
typename A1>
1245struct is_function_<R(A1)> {
1248template <
typename R,
typename A1,
typename A2>
1249struct is_function_<R(A1, A2)> {
1252template <
typename R,
typename A1,
typename A2,
typename A3>
1253struct is_function_<R(A1, A2, A3)> {
1258# if __cplusplus >= 201103L
1259template <
typename T,
typename... Args>
1266template <
typename T>
1271template <
typename T>
1276 template <
typename C>
1282 enum {
value =
sizeof(test<T>(
nullptr)) ==
sizeof(
yes) };
1285template <
typename T>
1294# if __cplusplus >= 201103L
1304template <
typename T>
1320template <
typename T =
void>
1326 template <
typename F>
1332 template <
typename F>
1339# if __cplusplus >= 201703L
1341template <
typename F>
1344template <
typename F>
1360template <
typename F>
1362joinable(
typename fiber_type<F>::fiber
const& f, Gate& g, Hook<Gate&>&
UNUSED_PAR(join))
noexcept
1367template <
typename T>
1368static inline void joinable(Future<T>& f, Gate&
UNUSED_PAR(g), Hook<Gate&>& join)
noexcept
1371 static void cb(Gate& g_,
void* f_)
noexcept
1373 Future<T>* f =
static_cast<Future<T>*
>(f_);
1381 join.add(&impl::cb,
static_cast<void*
>(&f));
1384template <
typename T>
1386joinable(SharedReference<Future<T> >
const& f, Gate& g, Hook<Gate&>& join)
noexcept
1388 joinable(f.get(), g, join);
1412# if ZTH_TYPEDFIBER98
1413 template <
typename J0>
1417 joinable(j0, m_gate, m_join);
1420 template <
typename J0>
1421 explicit joiner(J0
const& j0)
1424 joinable(j0, m_gate, m_join);
1427 template <
typename J0,
typename J1>
1428 explicit joiner(J0& j0, J1& j1)
1431 joinable(j0, m_gate, m_join);
1432 joinable(j1, m_gate, m_join);
1435 template <
typename J0,
typename J1>
1436 explicit joiner(J0
const& j0, J1
const& j1)
1439 joinable(j0, m_gate, m_join);
1440 joinable(j1, m_gate, m_join);
1443 template <
typename J0,
typename J1,
typename J2>
1444 explicit joiner(J0& j0, J1& j1, J2& j2)
1447 joinable(j0, m_gate, m_join);
1448 joinable(j1, m_gate, m_join);
1449 joinable(j2, m_gate, m_join);
1452 template <
typename J0,
typename J1,
typename J2>
1453 explicit joiner(J0
const& j0, J1
const& j1, J2
const& j2)
1456 joinable(j0, m_gate, m_join);
1457 joinable(j1, m_gate, m_join);
1458 joinable(j2, m_gate, m_join);
1461 template <
typename J0,
typename J1,
typename J2,
typename J3>
1462 explicit joiner(J0& j0, J1& j1, J2& j2, J3& j3)
1465 joinable(j0, m_gate, m_join);
1466 joinable(j1, m_gate, m_join);
1467 joinable(j2, m_gate, m_join);
1468 joinable(j3, m_gate, m_join);
1471 template <
typename J0,
typename J1,
typename J2,
typename J3>
1472 explicit joiner(J0
const& j0, J1
const& j1, J2
const& j2, J3
const& j3)
1475 joinable(j0, m_gate, m_join);
1476 joinable(j1, m_gate, m_join);
1477 joinable(j2, m_gate, m_join);
1478 joinable(j3, m_gate, m_join);
1481 template <
typename J0,
typename J1,
typename J2,
typename J3,
typename J4>
1482 explicit joiner(J0& j0, J1& j1, J2& j2, J3& j3, J4& j4)
1485 joinable(j0, m_gate, m_join);
1486 joinable(j1, m_gate, m_join);
1487 joinable(j2, m_gate, m_join);
1488 joinable(j3, m_gate, m_join);
1489 joinable(j4, m_gate, m_join);
1492 template <
typename J0,
typename J1,
typename J2,
typename J3,
typename J4>
1493 explicit joiner(J0
const& j0, J1
const& j1, J2
const& j2, J3
const& j3, J4
const& j4)
1496 joinable(j0, m_gate, m_join);
1497 joinable(j1, m_gate, m_join);
1498 joinable(j2, m_gate, m_join);
1499 joinable(j3, m_gate, m_join);
1500 joinable(j4, m_gate, m_join);
1504# if __cplusplus >= 201103L
1505 template <
typename... J>
1507 : m_gate{sizeof...(j) + 1U}
1509 using dummy =
int[];
1510 (void)dummy{0, (joinable(std::forward<J>(j), m_gate, m_join), 0)...};
1516 m_join.once(m_gate);
1525# if ZTH_TYPEDFIBER98
1526template <
typename J0>
1527static inline void join(J0& j0)
1532template <
typename J0,
typename J1>
1533static inline void join(J0& j0, J1& j1)
1538template <
typename J0,
typename J1,
typename J2>
1539static inline void join(J0& j0, J1& j1, J2& j2)
1541 joiner jn(j0, j1, j2);
1544template <
typename J0,
typename J1,
typename J2,
typename J3>
1545static inline void join(J0& j0, J1& j1, J2& j2, J3& j3)
1547 joiner jn(j0, j1, j2, j3);
1550template <
typename J0,
typename J1,
typename J2,
typename J3,
typename J4>
1551static inline void join(J0& j0, J1& j1, J2& j2, J3& j3, J4& j4)
1553 joiner jn(j0, j1, j2, j3, j4);
1557# if __cplusplus >= 201103L
1562template <
typename... J>
1563static inline void join(J&&... j)
1565 joiner jn{std::forward<J>(j)...};
1579# define zth_fiber_declare_1(f) \
1581 namespace fibered { \
1582 extern ::zth::fiber_type<decltype(&::f)>::factory const f; \
1590# define zth_fiber_declare(...) FOREACH(zth_fiber_declare_1, ##__VA_ARGS__)
1592# define zth_fiber_define_1(storage, f) \
1594 namespace fibered { \
1595 ZTH_DEPRECATED("Use zth::fiber(f, args...) instead") \
1596 storage ::zth::fiber_type<decltype(&::f)>::factory const \
1597 f(&::f, ::zth::Config::SupportDebugPrint || ::zth::Config::EnablePerfEvent \
1598 ? ZTH_STRINGIFY(f) "()" \
1602 typedef ::zth::fiber_type<decltype(&::f)>::future f##_future;
1603# define zth_fiber_define_extern_1(f) zth_fiber_define_1(extern, f)
1604# define zth_fiber_define_static_1(f) zth_fiber_define_1(static constexpr, f)
1610# define zth_fiber_define(...) FOREACH(zth_fiber_define_extern_1, ##__VA_ARGS__)
1616# define zth_fiber(...) FOREACH(zth_fiber_define_static_1, ##__VA_ARGS__)
1637# define zth_async ::zth::fibered::
1650 zth_fiber_t* h,
void (*f)(
void*),
void* arg =
nullptr,
size_t stack = 0,
1651 char const* name =
nullptr) noexcept
1661 }
catch(std::bad_alloc
const&) {
1664# ifdef __cpp_exceptions
#define REMOVE_FUNCTION_CVREF_SPECIALIZATIONS(P, suffix)
#define REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_CV(...)
State state() const noexcept
zth_fiber_t handle() const noexcept
Fiber-aware barrier/gate.
virtual char const * id_str() const noexcept override
void setName(string const &name)
string const & name() const noexcept
SharedPointer_type::type type
constexpr T & get() const noexcept
TypedFiberType< Function >::fiberType TypedFiber_type
TypedFiberType< Function >::returnType Return
function_type_helper< F >::type Function
fiber_type< Function > operator()(Args &&... args) const
SharedReference< typename TypedFiber_type::Future_type > Future
constexpr TypedFiberFactory(F_ &&function, char const *name) noexcept
constexpr TypedFiberFactory(Function function, char const *name) noexcept
TypedFiber_type & polish(TypedFiber_type &fiber) const
virtual ~TypedFiber() noexcept override=default
SharedPointer< Future_type > const & withFuture()
Future_type * future() const
Future< Return > Future_type
void setFuture(T const &r)
void registerFuture(Future_type *future)
static void entry(void *that)
TypedFiberN(F_ &&func, Args_ &&... args)
virtual ~TypedFiberN() final=default
Actual fiber implementation for arbitrary function types and arguments.
virtual void entry_() final
virtual ~TypedFiberN() final=default
TypedFiberN(F_ &&func, Args_ &&... args)
void hatch(Fiber &fiber) noexcept
RAII class to join fibers and futures on destruction.
int zth_fiber_create(zth_fiber_t *h, void(*f)(void *), void *arg=nullptr, size_t stack=0, char const *name=nullptr) noexcept
Run a function as a new fiber.
#define zth_config(name)
Checks if the given zth::Config field is enabled.
Worker & currentWorker() noexcept
Return the (thread-local) singleton Worker instance.
fiber_type< F >::factory factory(F &&f, char const *name=nullptr)
Create a new fiber.
fiber_type< F >::fiber fiber(F &&f, Args &&... args)
Create and start a new fiber.
#define zth_dbg(group, fmt, a...)
Debug printf()-like function.
std::basic_string< char, std::char_traits< char >, Config::Allocator< char >::type > string
std::string type using Config::Allocator::type.
#define ZTH_CLASS_NEW_DELETE(T)
Define new/delete operators for a class, which are allocator-aware.
::std::future< zth::type< T > > future
string format(char const *fmt,...)
Format like sprintf(), but save the result in an zth::string.
TypedFiber< R > & operator<<(TypedFiber< R > &fiber, setStackSize const &m)
static bool const EnablePerfEvent
Enable (but not necessarily record) perf.
static bool const EnableStackWaterMark
When true, enable stack watermark to detect maximum stack usage.
static bool const NamedSynchronizer
Save names for all zth::Synchronizer instances.
typename traitsType::return_type returnType
Forces the fiber to have a future that outlives the fiber.
Base exception class for Zth exceptions.
Exception thrown when an operation cannot be performed, as the fiber is already dead.
The future returned by a fiber.
future_type::type return_type
fiber_future(F const &f) noexcept
impl::fiber_future_helper< T >::type future_type
fiber_future(F &f) noexcept
fiber_type< function > fiber
future getFuture() const noexcept
SharedPointer< TypedFiber_type > _fiber
TypedFiberFactory< typename function_type_helper< F >::type > factory
future operator<<(asFuture const &)
TypedFiber_type & getFiber() const noexcept
fiber_type(TypedFiber_type &f) noexcept
TypedFiber_type::Return operator->()
factory::Function function
fiber const & operator<<(Manipulator const &m) const
zth_fiber_t handle() const noexcept
fiber & operator<<(Manipulator const &m) &
factory::TypedFiber_type TypedFiber_type
fiber && operator<<(Manipulator const &m) &&
TypedFiber_type::Return operator*()
std::tuple< Args... > args_type
R(*)(Args...) functor_type
std::tuple< Args... > args_type
R(*)(Args...) functor_type
std::tuple< Args... > args_type
std::tuple< Args... > args_type
R(&)(Args...) functor_type
std::tuple< Args... > args_type
R(*)(Args...) functor_type
typename std::decay< F >::type functor_type
typename functor_operator_type_::args_type args_type
typename functor_operator_type_::return_type return_type
static yes test(decltype(&C::operator()) *)
SharedReference< Future< T > > type
fiber_type< T >::future type
Makes the fiber pass the given gate upon exit.
static void atExit(Fiber &f, void *g) noexcept
constexpr passOnExit(Gate &g) noexcept
Change the name of a fiber returned by zth_async.
Change the stack size of a fiber returned by zth_async.
constexpr setStackSize(size_t s) noexcept
Opaque fiber handle type.
#define ZTH_CLASS_NOCOPY(Class)
#define unlikely(expr)
Marks the given expression to likely be evaluated to true.