21# if __cplusplus >= 201103L
22# include <initializer_list>
24# include <type_traits>
27# if __cplusplus < 201103L
28# undef ZTH_TYPEDFIBER98
30# define ZTH_TYPEDFIBER98 1
31# elif !defined(ZTH_TYPEDFIBER98)
34# define ZTH_TYPEDFIBER98 0
74# ifdef ZTH_FUTURE_EXCEPTION
119# ifdef ZTH_FUTURE_EXCEPTION
123# ifdef ZTH_FUTURE_EXCEPTION
132 template <
typename T>
145# ifdef ZTH_FUTURE_EXCEPTION
153 SharedPointer<Future_type> m_future;
184TypedFiber<R>& operator<<(TypedFiber<R>& fiber, setStackSize
const& m)
187 int res = fiber.setStackSize(m.stack);
202# if __cplusplus >= 201103L
214 explicit setName(
char const* n)
218 explicit setName(
string const& n)
223# if __cplusplus >= 201103L
237# if __cplusplus >= 201103L
239TypedFiber<R>& operator<<(TypedFiber<R>& fiber, setName&& m)
241 fiber.setName(std::move(m.name));
274 static_cast<Gate*
>(g)->pass();
282 fiber.atExit(&passOnExit::atExit,
static_cast<void*
>(&m.
gate));
287TypedFiber<R>& operator<<(TypedFiber<R>& fiber, passOnExit
const& m)
289 static_cast<Fiber&
>(fiber) << m;
316 return fiber.withFuture();
330class TypedFiber0 final :
public TypedFiber<R> {
333 typedef TypedFiber<R> base;
334 typedef R (*Function)();
336 explicit TypedFiber0(Function function)
337 : m_function(function)
343 virtual
void entry_() final
345 this->setFuture(m_function());
353class TypedFiber0<void> final :
public TypedFiber<void> {
356 typedef TypedFiber<void> base;
357 typedef void (*Function)();
359 explicit TypedFiber0(Function func)
363 virtual ~TypedFiber0() noexcept final
is_default
366 virtual
void entry_() final
376template <
typename R,
typename A1>
377class TypedFiber1 final :
public TypedFiber<R> {
380 typedef TypedFiber<R> base;
381 typedef R (*Function)(A1);
383 TypedFiber1(Function func, A1 a1)
388 virtual ~TypedFiber1() noexcept final
is_default
391 virtual
void entry_() final
393 this->setFuture(m_function(m_a1));
401template <
typename A1>
402class TypedFiber1<void, A1> final :
public TypedFiber<void> {
405 typedef TypedFiber<void> base;
406 typedef void (*Function)(A1);
409 TypedFiber1(Function func, A1 a1)
414 virtual ~TypedFiber1() noexcept final
is_default
417 virtual
void entry_() final
428template <
typename R,
typename A1,
typename A2>
429class TypedFiber2 final :
public TypedFiber<R> {
432 typedef TypedFiber<R> base;
433 typedef R (*Function)(A1, A2);
435 TypedFiber2(Function func, A1 a1, A2 a2)
441 virtual ~TypedFiber2() noexcept final
is_default
444 virtual
void entry_() final
446 this->setFuture(m_function(m_a1, m_a2));
455template <
typename A1,
typename A2>
456class TypedFiber2<void, A1, A2> final :
public TypedFiber<void> {
459 typedef TypedFiber<void> base;
460 typedef void (*Function)(A1, A2);
463 TypedFiber2(Function func, A1 a1, A2 a2)
469 virtual ~TypedFiber2() noexcept final
is_default
472 virtual
void entry_() final
474 m_function(m_a1, m_a2);
484template <
typename R,
typename A1,
typename A2,
typename A3>
485class TypedFiber3 final :
public TypedFiber<R> {
488 typedef TypedFiber<R> base;
489 typedef R (*Function)(A1, A2, A3);
491 TypedFiber3(Function func, A1 a1, A2 a2, A3 a3)
498 virtual ~TypedFiber3() noexcept final
is_default
501 virtual
void entry_() final
503 this->setFuture(m_function(m_a1, m_a2, m_a3));
513template <
typename A1,
typename A2,
typename A3>
514class TypedFiber3<void, A1, A2, A3> final :
public TypedFiber<void> {
517 typedef TypedFiber<void> base;
518 typedef void (*Function)(A1, A2, A3);
521 TypedFiber3(Function func, A1 a1, A2 a2, A3 a3)
528 virtual ~TypedFiber3() noexcept final
is_default
531 virtual
void entry_() final
533 m_function(m_a1, m_a2, m_a3);
545# if __cplusplus >= 201103L
547template <typename T, typename std::enable_if<!std::is_lvalue_reference<T>::value,
int>::type = 0>
548static constexpr T&& move_or_ref(T& t)
noexcept
553template <typename T, typename std::enable_if<std::is_lvalue_reference<T>::value,
int>::type = 0>
554static constexpr T move_or_ref(T t)
noexcept
565template <
typename F,
typename R,
typename Args>
572 template <
typename F_,
typename... Args_>
574 : m_function{
std::forward<F_>(func)}
575 , m_args{
std::forward<Args_>(args)...}
583 entry__(
typename SequenceGenerator<std::tuple_size<Args>::value>::type());
587 template <
size_t... S>
590 this->
setFuture(m_function(move_or_ref<
typename std::tuple_element<S, Args>::type>(
591 std::get<S>(m_args))...));
599template <
typename F,
typename Args>
606 template <
typename F_,
typename... Args_>
608 : m_function{
std::forward<F_>(func)}
609 , m_args{
std::forward<Args_>(args)...}
617 entry__(
typename SequenceGenerator<std::tuple_size<Args>::value>::type());
621 template <
size_t... S>
624 m_function(move_or_ref<
typename std::tuple_element<S, Args>::type>(
625 std::get<S>(m_args))...);
646# define REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_(P, PArgs, suffix, ...) \
647 template <typename R, ##__VA_ARGS__> \
648 struct remove_function_cvref<R P PArgs suffix> { \
649 typedef R(type) PArgs; \
653# define REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_A0(P, suffix) \
654 REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_(P, (), suffix)
655# define REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_A1(P, suffix) \
656 REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_(P, (A1), suffix, typename A1)
657# define REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_A2(P, suffix) \
658 REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_(P, (A1, A2), suffix, typename A1, typename A2)
659# define REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_A3(P, suffix) \
660 REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_( \
661 P, (A1, A2, A3), suffix, typename A1, typename A2, typename A3)
663# define REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_A(P, suffix) \
664 REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_A0(P, suffix) \
665 REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_A1(P, suffix) \
666 REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_A2(P, suffix) \
667 REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_A3(P, suffix)
669# define REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_A(P, suffix)
672# if __cplusplus >= 201103L
673# define REMOVE_FUNCTION_CVREF_SPECIALIZATIONS(P, suffix) \
674 REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_A(P, suffix) \
675 REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_(P, (Args...), suffix, typename... Args)
677# define REMOVE_FUNCTION_CVREF_SPECIALIZATIONS(P, suffix) \
678 REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_A(P, suffix)
686# if defined(__cpp_noexcept_function_type) && __cpp_noexcept_function_type >= 201510
693# undef REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_
694# undef REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_A0
695# undef REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_A1
696# undef REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_A2
697# undef REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_A3
698# undef REMOVE_FUNCTION_CVREF_SPECIALIZATIONS_A
699# undef REMOVE_FUNCTION_CVREF_SPECIALIZATIONS
701# define REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_(PArgs, cvref, ...) \
702 template <typename R, typename C, ##__VA_ARGS__> \
703 struct remove_function_cvref<R(C::*) PArgs cvref> { \
704 typedef R(type) PArgs; \
708# define REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_A0(cvref) \
709 REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_((), cvref)
710# define REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_A1(cvref) \
711 REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_((A1), cvref, typename A1)
712# define REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_A2(cvref) \
713 REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_((A1, A2), cvref, typename A1, typename A2)
714# define REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_A3(cvref) \
715 REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_( \
716 (A1, A2, A3), cvref, typename A1, typename A2, typename A3)
717# define REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_A(cvref) \
718 REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_A0(cvref) \
719 REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_A1(cvref) \
720 REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_A2(cvref) \
721 REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_A3(cvref)
723# define REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_A(cvref)
726# if __cplusplus >= 201103L
727# define REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS(cvref) \
728 REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_A(cvref) \
729 REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_((Args...), cvref, typename... Args)
731# define REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS(cvref) \
732 REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_A(cvref)
735# define REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_CV(...) \
736 REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS(__VA_ARGS__) \
737 REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS(const __VA_ARGS__) \
738 REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS(volatile __VA_ARGS__) \
739 REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS(const volatile __VA_ARGS__)
742# if __cplusplus >= 201103L
746# if defined(__cpp_noexcept_function_type) && __cpp_noexcept_function_type >= 201510
753# undef REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_
754# undef REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_A0
755# undef REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_A1
756# undef REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_A2
757# undef REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_A3
758# undef REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_A
759# undef REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS
760# undef REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_CV
762# if __cplusplus >= 201103L
766template <
typename R,
typename... Args>
783 using args_type =
typename functor_operator_type_::args_type;
787template <
typename R,
typename... Args>
795template <
typename R,
typename... Args>
804template <
typename R,
typename... Args>
813template <
typename R,
typename... Args>
840# define ZTH_TYPEDFIBERTYPE_SPECIALIZATION(P) \
841 template <typename R> \
842 struct TypedFiberType<R P()> { \
844 typedef R returnType; \
845 typedef TypedFiber0<R> fiberType; \
846 typedef NoArg a1Type; \
847 typedef NoArg a2Type; \
848 typedef NoArg a3Type; \
851 template <typename R, typename A1> \
852 struct TypedFiberType<R P(A1)> { \
854 typedef R returnType; \
855 typedef TypedFiber1<R, A1> fiberType; \
857 typedef NoArg a2Type; \
858 typedef NoArg a3Type; \
861 template <typename R, typename A1, typename A2> \
862 struct TypedFiberType<R P(A1, A2)> { \
864 typedef R returnType; \
865 typedef TypedFiber2<R, A1, A2> fiberType; \
868 typedef NoArg a3Type; \
871 template <typename R, typename A1, typename A2, typename A3> \
872 struct TypedFiberType<R P(A1, A2, A3)> { \
874 typedef R returnType; \
875 typedef TypedFiber3<R, A1, A2, A3> fiberType; \
881ZTH_TYPEDFIBERTYPE_SPECIALIZATION()
882ZTH_TYPEDFIBERTYPE_SPECIALIZATION((*))
883ZTH_TYPEDFIBERTYPE_SPECIALIZATION((*&))
884ZTH_TYPEDFIBERTYPE_SPECIALIZATION((&))
886# undef ZTH_TYPEDFIBERTYPE_SPECIALIZATION
903# define FUNCTION_TYPE_HELPER_SPECIALIZATION(P) \
904 template <typename R> \
905 struct function_type_helper<R P()> { \
906 typedef R (*type)(); \
909 template <typename R, typename A1> \
910 struct function_type_helper<R P(A1)> { \
911 typedef R (*type)(A1); \
914 template <typename R, typename A1, typename A2> \
915 struct function_type_helper<R P(A1, A2)> { \
916 typedef R (*type)(A1, A2); \
919 template <typename R, typename A1, typename A2, typename A3> \
920 struct function_type_helper<R P(A1, A2, A3)> { \
921 typedef R (*type)(A1, A2, A3); \
924FUNCTION_TYPE_HELPER_SPECIALIZATION()
925FUNCTION_TYPE_HELPER_SPECIALIZATION((*))
926FUNCTION_TYPE_HELPER_SPECIALIZATION((*&))
927FUNCTION_TYPE_HELPER_SPECIALIZATION((&))
929# undef FUNCTION_TYPE_HELPER_SPECIALIZATION
932# if __cplusplus >= 201103L
933template <
typename R,
typename... Args>
938template <
typename R,
typename... Args>
943template <
typename R,
typename... Args>
948template <
typename R,
typename... Args>
966 : m_function(function)
970# if __cplusplus >= 201103L
971 template <
typename F_>
973 : m_function{std::forward<F_>(function)}
993 fiber_type<Function>
operator()(A1 a1, A2 a2)
const
998 fiber_type<Function>
operator()(A1 a1, A2 a2, A3 a3)
const
1004# if __cplusplus >= 201103L
1005 template <
typename... Args>
1033template <
typename F>
1074 return _fiber->withFuture();
1077 template <
typename Manipulator>
1084 template <
typename Manipulator>
1091# if __cplusplus >= 201103L
1092 template <
typename Manipulator>
1096 return std::move(*
this);
1113static inline char const* fiber_name(
char const* name)
1121# if __cplusplus >= 201103L
1130template <
typename F>
1136template <
typename F>
1142template <
typename F>
1143typename fiber_type<F>::factory factory(F f,
char const* name =
nullptr)
1145 return typename fiber_type<F>::factory(f, impl::fiber_name(name));
1149# if ZTH_TYPEDFIBER98
1150template <
typename F>
1151typename fiber_type<F>::fiber
fiber(F f)
1153 return factory<F>(f)();
1156template <
typename F>
1157typename fiber_type<F>::fiber
fiber(F f,
typename fiber_type<F>::factory::A1 a1)
1159 return factory<F>(f)(a1);
1162template <
typename F>
1163typename fiber_type<F>::fiber
1164fiber(F f,
typename fiber_type<F>::factory::A1 a1,
typename fiber_type<F>::factory::A2 a2)
1166 return factory<F>(f)(a1, a2);
1169template <
typename F>
1170typename fiber_type<F>::fiber
1171fiber(F f,
typename fiber_type<F>::factory::A1 a1,
typename fiber_type<F>::factory::A2 a2,
1172 typename fiber_type<F>::factory::A3 a3)
1174 return factory<F>(f)(a1, a2, a3);
1178# if __cplusplus >= 201103L
1191template <
typename F,
typename... Args>
1194 return factory<F>(std::forward<F>(f))(std::forward<Args>(args)...);
1205template <
typename F>
1210# if ZTH_TYPEDFIBER98
1211template <
typename R>
1212struct is_function_<R()> {
1215template <
typename R,
typename A1>
1216struct is_function_<R(A1)> {
1219template <
typename R,
typename A1,
typename A2>
1220struct is_function_<R(A1, A2)> {
1223template <
typename R,
typename A1,
typename A2,
typename A3>
1224struct is_function_<R(A1, A2, A3)> {
1229# if __cplusplus >= 201103L
1230template <
typename T,
typename... Args>
1237template <
typename T>
1242template <
typename T>
1247 template <
typename C>
1253 enum {
value =
sizeof(test<T>(
nullptr)) ==
sizeof(
yes) };
1256template <
typename T>
1265# if __cplusplus >= 201103L
1275template <
typename T>
1291template <
typename T =
void>
1297 template <
typename F>
1303 template <
typename F>
1310# if __cplusplus >= 201703L
1312template <
typename F>
1315template <
typename F>
1330template <
typename F>
1332joinable(
typename fiber_type<F>::fiber
const& f, Gate& g, Hook<Gate&>&
UNUSED_PAR(join))
noexcept
1337template <
typename T>
1338static inline void joinable(Future<T>& f, Gate&
UNUSED_PAR(g), Hook<Gate&>& join)
noexcept
1341 static void cb(Gate& g_,
void* f_)
noexcept
1343 Future<T>* f =
static_cast<Future<T>*
>(f_);
1351 join.add(&impl::cb,
static_cast<void*
>(&f));
1354template <
typename T>
1356joinable(SharedReference<Future<T> >
const& f, Gate& g, Hook<Gate&>& join)
noexcept
1358 joinable(f.get(), g, join);
1382# if ZTH_TYPEDFIBER98
1383 template <
typename J0>
1387 joinable(j0, m_gate, m_join);
1390 template <
typename J0>
1391 explicit joiner(J0
const& j0)
1394 joinable(j0, m_gate, m_join);
1397 template <
typename J0,
typename J1>
1398 explicit joiner(J0& j0, J1& j1)
1401 joinable(j0, m_gate, m_join);
1402 joinable(j1, m_gate, m_join);
1405 template <
typename J0,
typename J1>
1406 explicit joiner(J0
const& j0, J1
const& j1)
1409 joinable(j0, m_gate, m_join);
1410 joinable(j1, m_gate, m_join);
1413 template <
typename J0,
typename J1,
typename J2>
1414 explicit joiner(J0& j0, J1& j1, J2& j2)
1417 joinable(j0, m_gate, m_join);
1418 joinable(j1, m_gate, m_join);
1419 joinable(j2, m_gate, m_join);
1422 template <
typename J0,
typename J1,
typename J2>
1423 explicit joiner(J0
const& j0, J1
const& j1, J2
const& j2)
1426 joinable(j0, m_gate, m_join);
1427 joinable(j1, m_gate, m_join);
1428 joinable(j2, m_gate, m_join);
1431 template <
typename J0,
typename J1,
typename J2,
typename J3>
1432 explicit joiner(J0& j0, J1& j1, J2& j2, J3& j3)
1435 joinable(j0, m_gate, m_join);
1436 joinable(j1, m_gate, m_join);
1437 joinable(j2, m_gate, m_join);
1438 joinable(j3, m_gate, m_join);
1441 template <
typename J0,
typename J1,
typename J2,
typename J3>
1442 explicit joiner(J0
const& j0, J1
const& j1, J2
const& j2, J3
const& j3)
1445 joinable(j0, m_gate, m_join);
1446 joinable(j1, m_gate, m_join);
1447 joinable(j2, m_gate, m_join);
1448 joinable(j3, m_gate, m_join);
1451 template <
typename J0,
typename J1,
typename J2,
typename J3,
typename J4>
1452 explicit joiner(J0& j0, J1& j1, J2& j2, J3& j3, J4& j4)
1455 joinable(j0, m_gate, m_join);
1456 joinable(j1, m_gate, m_join);
1457 joinable(j2, m_gate, m_join);
1458 joinable(j3, m_gate, m_join);
1459 joinable(j4, m_gate, m_join);
1462 template <
typename J0,
typename J1,
typename J2,
typename J3,
typename J4>
1463 explicit joiner(J0
const& j0, J1
const& j1, J2
const& j2, J3
const& j3, J4
const& j4)
1466 joinable(j0, m_gate, m_join);
1467 joinable(j1, m_gate, m_join);
1468 joinable(j2, m_gate, m_join);
1469 joinable(j3, m_gate, m_join);
1470 joinable(j4, m_gate, m_join);
1474# if __cplusplus >= 201103L
1475 template <
typename... J>
1477 : m_gate{sizeof...(j) + 1U}
1479 using dummy =
int[];
1480 (void)dummy{0, (joinable(std::forward<J>(j), m_gate, m_join), 0)...};
1486 m_join.once(m_gate);
1495# if ZTH_TYPEDFIBER98
1496template <
typename J0>
1497static inline void join(J0& j0)
1502template <
typename J0,
typename J1>
1503static inline void join(J0& j0, J1& j1)
1508template <
typename J0,
typename J1,
typename J2>
1509static inline void join(J0& j0, J1& j1, J2& j2)
1511 joiner jn(j0, j1, j2);
1514template <
typename J0,
typename J1,
typename J2,
typename J3>
1515static inline void join(J0& j0, J1& j1, J2& j2, J3& j3)
1517 joiner jn(j0, j1, j2, j3);
1520template <
typename J0,
typename J1,
typename J2,
typename J3,
typename J4>
1521static inline void join(J0& j0, J1& j1, J2& j2, J3& j3, J4& j4)
1523 joiner jn(j0, j1, j2, j3, j4);
1527# if __cplusplus >= 201103L
1532template <
typename... J>
1533static inline void join(J&&... j)
1535 joiner jn{std::forward<J>(j)...};
1549# define zth_fiber_declare_1(f) \
1551 namespace fibered { \
1552 extern ::zth::fiber_type<decltype(&::f)>::factory const f; \
1560# define zth_fiber_declare(...) FOREACH(zth_fiber_declare_1, ##__VA_ARGS__)
1562# define zth_fiber_define_1(storage, f) \
1564 namespace fibered { \
1565 ZTH_DEPRECATED("Use zth::fiber(f, args...) instead") \
1566 storage ::zth::fiber_type<decltype(&::f)>::factory const \
1567 f(&::f, ::zth::Config::EnableDebugPrint || ::zth::Config::EnablePerfEvent \
1568 ? ZTH_STRINGIFY(f) "()" \
1572 typedef ::zth::fiber_type<decltype(&::f)>::future f##_future;
1573# define zth_fiber_define_extern_1(f) zth_fiber_define_1(extern, f)
1574# define zth_fiber_define_static_1(f) zth_fiber_define_1(static constexpr, f)
1580# define zth_fiber_define(...) FOREACH(zth_fiber_define_extern_1, ##__VA_ARGS__)
1586# define zth_fiber(...) FOREACH(zth_fiber_define_static_1, ##__VA_ARGS__)
1607# define zth_async ::zth::fibered::
1620 void (*f)(
void*),
void* arg =
nullptr,
size_t stack = 0,
1621 char const* name =
nullptr) noexcept
1625 }
catch(std::bad_alloc
const&) {
1628# ifdef __cpp_exceptions
1641ZTH_EXPORT
int zth_fiber_create(
void (*f)(
void*),
void* arg,
size_t stack,
char const* name);
#define REMOVE_FUNCTION_CVREF_SPECIALIZATIONS(P, suffix)
#define REMOVE_FUNCTION_CVREF_MEMBER_SPECIALIZATIONS_CV(...)
State state() 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(void(*f)(void *), void *arg=nullptr, size_t stack=0, char const *name=nullptr) noexcept
Run a function as a new fiber.
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 EnableDebugPrint
Actually do print the debug output.
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
SharedPointer< TypedFiber_type > _fiber
TypedFiberFactory< typename function_type_helper< F >::type > factory
future operator<<(asFuture const &)
fiber_type(TypedFiber_type &f) noexcept
TypedFiber_type::Return operator->()
factory::Function function
fiber const & operator<<(Manipulator const &m) const
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
#define ZTH_CLASS_NOCOPY(Class)
#define unlikely(expr)
Marks the given expression to likely be evaluated to true.