287 #ifdef CGU_USE_SCHED_YIELD
294 #include <unordered_set>
296 #include <functional>
339 std::unordered_set<Callback::SafeFunctor> disconnect_set;
459 template <
class... FreeArgs>
462 #ifndef DOXYGEN_PARSING
467 Callback::FunctorArg<FreeArgs...> f1;
471 f1(f1_), f2(f2_), blocked(false) {}
475 std::list<ListItem> emission_list;
478 void tracking_disconnect(
const Callback::FunctorArg<FreeArgs...>&);
608 template <
class... FreeArgs>
621 struct DisconnectReleaserItem {
622 static void exec(
const ListItem& l) {(l.f2)();}
624 std::for_each(emission_list.begin(), emission_list.end(),
628 template <
class... FreeArgs>
660 std::list<ListItem> local_list = emission_list;
667 typename std::list<ListItem>::const_iterator iter;
668 for (iter = local_list.begin(); iter != local_list.end(); ++iter) {
669 if (!iter->blocked) iter->f1(args...);
673 template <
class... FreeArgs>
675 if (emission_list.empty())
return false;
680 template <
class... FreeArgs>
686 template <
class... FreeArgs>
699 emission_list.emplace_back(f1, f2);
708 template <
class... FreeArgs>
712 auto iter = emission_list.begin();
725 iter = std::find_if(iter, emission_list.end(),
726 std::bind(Pred::pred, std::placeholders::_1, std::ref(arg)));
727 if (iter != emission_list.end()) {
732 iter = emission_list.erase(iter);
741 template <
class... FreeArgs>
743 auto iter = emission_list.begin();
756 iter = std::find_if(iter, emission_list.end(),
757 std::bind(Pred::pred, std::placeholders::_1, std::ref(arg)));
758 if (iter != emission_list.end()) {
760 iter = emission_list.erase(iter);
766 template <
class... FreeArgs>
770 auto iter = emission_list.begin();
783 iter = std::find_if(iter, emission_list.end(),
784 std::bind(Pred::pred, std::placeholders::_1, std::ref(arg)));
785 if (iter != emission_list.end()) {
786 iter->blocked =
true;
793 template <
class... FreeArgs>
797 auto iter = emission_list.begin();
810 iter = std::find_if(iter, emission_list.end(),
811 std::bind(Pred::pred, std::placeholders::_1, std::ref(arg)));
812 if (iter != emission_list.end()) {
813 iter->blocked =
false;
870 template <
class... FreeArgs>
873 #ifndef DOXYGEN_PARSING
882 f1(f1_), f2(f2_), blocked(false) {}
886 std::list<ListItem> emission_list;
887 mutable Thread::Mutex mutex;
890 void tracking_disconnect(
const Callback::SafeFunctorArg<FreeArgs...>&);
1035 template <
class... FreeArgs>
1042 while (!emission_list.empty()) {
1043 auto iter = emission_list.begin();
1046 (iter->f2)(&result);
1049 emission_list.erase(iter);
1054 #ifdef CGU_USE_SCHED_YIELD
1064 template <
class... FreeArgs>
1126 std::list<ListItem> local_list;
1129 local_list = emission_list;
1137 typename std::list<ListItem>::const_iterator iter;
1138 for (iter = local_list.begin(); iter != local_list.end(); ++iter) {
1139 if (!iter->blocked) iter->f1(args...);
1143 template <
class... FreeArgs>
1146 std::list<ListItem> local_list;
1149 if (emission_list.empty())
return false;
1150 local_list = emission_list;
1158 typename std::list<ListItem>::const_iterator iter;
1159 for (iter = local_list.begin(); iter != local_list.end(); ++iter) {
1160 if (!iter->blocked) iter->f1(args...);
1165 template <
class... FreeArgs>
1170 Thread::Mutex::Lock lock{mutex};
1171 emission_list.splice(emission_list.end(), std::move(tmp));
1175 template <
class... FreeArgs>
1193 std::list<ListItem> tmp{ListItem{f1, f2}};
1194 Thread::Mutex::Lock lock{mutex};
1195 emission_list.splice(emission_list.end(), std::move(tmp));
1204 template <
class... FreeArgs>
1209 auto iter = emission_list.begin();
1222 iter = std::find_if(iter, emission_list.end(),
1223 std::bind(Pred::pred, std::placeholders::_1, std::ref(arg)));
1224 if (iter != emission_list.end()) {
1227 (iter->f2)(&result);
1230 iter = emission_list.erase(iter);
1235 #ifdef CGU_USE_SCHED_YIELD
1243 iter = emission_list.begin();
1253 template <
class... FreeArgs>
1256 auto iter = emission_list.begin();
1265 static bool pred(
const ListItem& p,
const Callback::SafeFunctorArg<FreeArgs...>& f) {
1269 iter = std::find_if(iter, emission_list.end(),
1270 std::bind(Pred::pred, std::placeholders::_1, std::ref(arg)));
1271 if (iter != emission_list.end()) {
1273 iter = emission_list.erase(iter);
1279 template <
class... FreeArgs>
1284 auto iter = emission_list.begin();
1297 iter = std::find_if(iter, emission_list.end(),
1298 std::bind(Pred::pred, std::placeholders::_1, std::ref(arg)));
1299 if (iter != emission_list.end()) {
1300 iter->blocked =
true;
1307 template <
class... FreeArgs>
1312 auto iter = emission_list.begin();
1325 iter = std::find_if(iter, emission_list.end(),
1326 std::bind(Pred::pred, std::placeholders::_1, std::ref(arg)));
1327 if (iter != emission_list.end()) {
1328 iter->blocked =
false;