34 static ENV_LOCAL unsigned int _egrp_tbl_iter_idx;
39 em_event_group_t egrp;
42 egrp = event_group_alloc();
45 "Event group alloc failed!");
49 egrp_elem = event_group_elem_get(egrp);
52 egrp_elem->
ready =
true;
61 event_group_elem_get(event_group);
67 "Invalid event group: %" PRI_EGRP "", event_group);
69 egrp_count.all = EM_ATOMIC_GET(&egrp_elem->post.atomic);
72 count = egrp_count.
count;
74 count = egrp_count.all;
77 EM_ESCOPE_EVENT_GROUP_DELETE,
78 "Event group:%" PRI_EGRP " count not zero!",
84 status = event_group_free(event_group);
86 status, EM_ESCOPE_EVENT_GROUP_DELETE,
87 "Event Group delete failed!");
100 event_group_elem_get(event_group);
105 "Invalid args: event group:%" PRI_EGRP ", count:%d",
110 "Event group:%" PRI_EGRP " not created!", event_group);
114 "Invalid notif cfg given!");
117 egrp_count = egrp_elem->post.count;
119 egrp_count = egrp_elem->post.
all;
123 "Event group %" PRI_EGRP " currently in use! count: %i",
124 event_group, egrp_count);
127 egrp_elem->post.count = count;
129 egrp_elem->post.gen++;
130 egrp_elem->pre.
all = egrp_elem->post.
all;
132 egrp_elem->post.
all = count;
135 egrp_elem->
ready =
false;
138 for (
int i = 0; i < num_notif; i++) {
139 egrp_elem->notif_tbl[i].event = notif_tbl[i].
event;
140 egrp_elem->notif_tbl[i].queue = notif_tbl[i].
queue;
141 egrp_elem->notif_tbl[i].egroup = notif_tbl[i].
egroup;
162 "No current event group (%" PRI_EGRP ") or not applied",
168 "Current event group in a bad state (%" PRI_EGRP ")",
172 EM_ATOMIC_ADD(&egrp_elem->post.atomic, count);
180 current_count.all = EM_ATOMIC_GET(&egrp_elem->post.atomic);
185 EM_ESCOPE_EVENT_GROUP_INCREMENT,
186 "Expired event group (%" PRI_EGRP ")",
189 new_count = current_count;
190 new_count.
count += count;
191 }
while (!EM_ATOMIC_CMPSET(&egrp_elem->post.atomic,
192 current_count.all, new_count.all));
196 current_count.all = EM_ATOMIC_GET(&egrp_elem->pre.atomic);
200 EM_ESCOPE_EVENT_GROUP_INCREMENT,
201 "Expired event group (%" PRI_EGRP ")",
204 new_count = current_count;
205 new_count.
count += count;
206 }
while (!EM_ATOMIC_CMPSET(&egrp_elem->pre.atomic,
207 current_count.all, new_count.all));
215 event_group_elem_get(event_group);
219 "Invalid event group: %" PRI_EGRP "",
224 if (unlikely(
EM_CHECK_LEVEL >= 2 && !event_group_allocated(egrp_elem))) {
226 "Event group: %" PRI_EGRP " not created",
234 count = egrp_elem->post.count;
236 count = egrp_elem->post.
all;
238 if (count == 0 && egrp_elem->
ready)
258 if (egrp_elem == NULL)
261 current.all = EM_ATOMIC_GET(&egrp_elem->post.atomic);
275 send_external_egrp(em_event_t event,
event_hdr_t *
const ev_hdr,
276 em_queue_t queue, em_event_group_t event_group,
280 call_api_hooks_send(&event, 1, queue, event_group);
282 em_status_t stat = send_chaining_egrp(event, ev_hdr, queue, egrp_elem);
288 "send_chaining_egrp: Q:%" PRI_QUEUE "", queue);
298 send_external_egrp_multi(
const em_event_t events[],
event_hdr_t *ev_hdrs[],
int num,
299 em_queue_t queue, em_event_group_t event_group,
303 call_api_hooks_send(events, num, queue, event_group);
305 int num_sent = send_chaining_egrp_multi(events, ev_hdrs, num,
309 "send_chaining_egrp_multi: req:%d, sent:%d",
321 send_internal_egrp(em_event_t event,
event_hdr_t *ev_hdr, em_queue_t queue,
322 em_event_group_t event_group)
346 if (unlikely(num_sent != 1)) {
355 call_api_hooks_send(&event, 1, queue, event_group);
363 switch (q_elem->
type) {
367 stat = send_event(event, q_elem);
370 stat = queue_unsched_enqueue(event, q_elem);
373 stat = send_local(event, q_elem);
380 if (likely(stat ==
EM_OK))
390 "send egrp: Q:%" PRI_QUEUE " type:%" PRI_QTYPE
"",
391 queue, q_elem->
type);
400 send_internal_egrp_multi(
const em_event_t events[],
event_hdr_t *ev_hdrs[],
401 int num, em_queue_t queue, em_event_group_t event_group)
426 EVSTATE__SEND_EGRP_MULTI);
429 if (unlikely(num_sent != num))
436 call_api_hooks_send(events, num, queue, event_group);
444 switch (q_elem->
type) {
448 num_sent = send_event_multi(events, num, q_elem);
451 num_sent = send_local_multi(events, num, q_elem);
458 if (likely(num_sent == num))
466 EVSTATE__SEND_EGRP_MULTI__FAIL);
469 "send-egrp-multi failed: req:%d, sent:%d",
475 em_event_group_t event_group)
478 const bool is_external = queue_external(queue);
485 "Invalid event group:%" PRI_EGRP "", event_group);
487 !event_group_allocated(egrp_elem),
489 "Event group:%" PRI_EGRP " not created", event_group);
498 "Event has references: can't use references with event groups");
503 EM_ERR_BAD_ARG, EM_ESCOPE_SEND_GROUP,
"Timer-ring event can't be sent");
509 ev_hdr->
egrp_gen = event_group_gen_get(egrp_elem);
518 return send_external_egrp(event, ev_hdr, queue,
519 event_group, egrp_elem);
523 return send_internal_egrp(event, ev_hdr, queue, event_group);
530 send_grpmulti_check(
const em_event_t events[],
int num,
531 em_event_group_t event_group,
535 unlikely(!events || num <= 0 ||
541 !event_group_allocated(egrp_elem)))
549 if (unlikely(i != num))
557 em_event_group_t event_group)
560 const bool is_external = queue_external(queue);
564 event_group, egrp_elem);
565 if (unlikely(err !=
EM_OK)) {
567 "Invalid args: events:%p num:%d event_group:%" PRI_EGRP "",
568 events, num, queue, event_group);
578 for (
int i = 0; i < num; i++) {
579 if (likely(!event_has_ref(events[i])))
583 "event[%d] has references: can't use with event groups", i);
588 event_to_hdr_multi(events, ev_hdrs, num);
592 for (
int i = 0; i < num; i++) {
595 "Timer-ring event[%d] can't be sent", i);
602 for (
int i = 0; i < num; i++)
603 ev_hdrs[i]->egrp = event_group;
606 uint64_t egrp_gen = event_group_gen_get(egrp_elem);
608 for (
int i = 0; i < num; i++)
609 ev_hdrs[i]->egrp_gen = egrp_gen;
616 return send_external_egrp_multi(events, ev_hdrs, num, queue,
617 event_group, egrp_elem);
621 return send_internal_egrp_multi(events, ev_hdrs, num, queue, event_group);
630 if (unlikely(invalid_egrp(event_group)))
648 event_group_elem_get(event_group);
653 "Invalid event group: %" PRI_EGRP "", event_group);
658 "Invalid event group: %" PRI_EGRP "", event_group);
662 "Cannot assign event group %" PRI_EGRP ",\n"
663 "event already belongs to event group %" PRI_EGRP "",
668 "Cannot assign event group %" PRI_EGRP ".\n"
669 "Event group has not been applied", event_group);
688 event_group_elem_get(event_group);
693 "Invalid event group: %" PRI_EGRP "", event_group);
698 "Event group: %" PRI_EGRP " not created", event_group);
703 "Event group abort too late, notifs already sent");
704 egrp_elem->post.
all = 0;
706 egrp_elem->
ready =
true;
715 current_count.all = EM_ATOMIC_GET(&egrp_elem->post.atomic);
719 "Event group abort late, notifs already sent");
720 new_count = current_count;
722 }
while (!EM_ATOMIC_CMPSET(&egrp_elem->post.atomic,
723 current_count.all, new_count.all));
728 EM_ATOMIC_SET(&egrp_elem->pre.atomic, new_count.all);
730 egrp_elem->
ready =
true;
739 event_group_elem_get(event_group);
743 unlikely(egrp_elem == NULL || max_notif < 0)) {
745 "Invalid args: evgrp:%" PRI_EGRP ", notifs:%d",
746 event_group, max_notif);
750 if (unlikely(
EM_CHECK_LEVEL >= 2 && !event_group_allocated(egrp_elem))) {
752 "Event group:%" PRI_EGRP " not created",
753 event_group, max_notif);
757 if (unlikely(max_notif == 0))
760 if (unlikely(notif_tbl == NULL)) {
762 EM_ESCOPE_EVENT_GROUP_GET_NOTIF,
763 "Invalid notif_tbl[] given");
767 if (!egrp_elem->
ready) {
768 num_notif = max_notif < egrp_elem->
num_notif ?
771 for (
int i = 0; i < num_notif; i++) {
772 notif_tbl[i].
event = egrp_elem->notif_tbl[i].event;
773 notif_tbl[i].
queue = egrp_elem->notif_tbl[i].queue;
774 notif_tbl[i].
egroup = egrp_elem->notif_tbl[i].egroup;
785 em_shm->event_group_tbl.egrp_elem;
787 const unsigned int egrp_count = event_group_count();
789 _egrp_tbl_iter_idx = 0;
794 if (egrp_count == 0) {
800 while (!event_group_allocated(egrp_elem)) {
801 _egrp_tbl_iter_idx++;
804 egrp_elem = &egrp_elem_tbl[_egrp_tbl_iter_idx];
807 return egrp_idx2hdl(_egrp_tbl_iter_idx);
816 _egrp_tbl_iter_idx++;
819 em_shm->event_group_tbl.egrp_elem;
821 &egrp_elem_tbl[_egrp_tbl_iter_idx];
824 while (!event_group_allocated(egrp_elem)) {
825 _egrp_tbl_iter_idx++;
828 egrp_elem = &egrp_elem_tbl[_egrp_tbl_iter_idx];
831 return egrp_idx2hdl(_egrp_tbl_iter_idx);
836 return (uint64_t)event_group;