Skip to content

Commit a9e8b92

Browse files
committed
event_routing: Clean up convoluted looping logic
1 parent 6ef166a commit a9e8b92

File tree

1 file changed

+7
-22
lines changed

1 file changed

+7
-22
lines changed

modules/event_routing/ebr_data.c

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -475,9 +475,8 @@ int notify_ebr_subscriptions( ebr_event *ev, evi_params_t *params)
475475

476476
/* check the EBR subscription on this event and apply the filters */
477477
sub_prev = NULL;
478-
sub_next = NULL;
479-
for ( sub=ev->subs ; sub ; sub_prev=sub,
480-
sub=sub_next?sub_next:(sub?sub->next:NULL) ) {
478+
for ( sub=ev->subs ; sub ; sub_prev=sub, sub=sub_next) {
479+
sub_next = sub->next;
481480

482481
/* discard expired subscriptions */
483482
if (sub->expire<my_time) {
@@ -492,7 +491,6 @@ int notify_ebr_subscriptions( ebr_event *ev, evi_params_t *params)
492491
job =(ebr_ipc_job*)shm_malloc( sizeof(ebr_ipc_job) );
493492
if (job==NULL) {
494493
LM_ERR("failed to allocated new IPC job, skipping..\n");
495-
sub_next = sub->next;
496494
continue; /* with the next subscription */
497495
}
498496
job->ev = ev;
@@ -505,12 +503,10 @@ int notify_ebr_subscriptions( ebr_event *ev, evi_params_t *params)
505503
if (ipc_send_job( sub->proc_no, ebr_ipc_type , (void*)job)<0) {
506504
LM_ERR("failed to send job via IPC, skipping...\n");
507505
shm_free(job);
508-
sub_next = sub->next;
509506
continue; /* keep it and try next time */
510507
}
511508
}
512-
/* remove the subscription */
513-
sub_next = sub->next;
509+
514510
/* unlink it */
515511
if (sub_prev) sub_prev->next = sub_next;
516512
else ev->subs = sub_next;
@@ -523,7 +519,6 @@ int notify_ebr_subscriptions( ebr_event *ev, evi_params_t *params)
523519

524520
/* run the filters */
525521
matches = 1;
526-
sub_next = NULL;
527522
for ( filter=sub->filters ; matches && filter ; filter=filter->next ) {
528523

529524
/* look for the evi param with the same name */
@@ -558,7 +553,6 @@ int notify_ebr_subscriptions( ebr_event *ev, evi_params_t *params)
558553
job =(ebr_ipc_job*)shm_malloc( sizeof(ebr_ipc_job) );
559554
if (job==NULL) {
560555
LM_ERR("failed to allocated new IPC job, skipping..\n");
561-
sub_next = sub->next;
562556
continue; /* with the next subscription */
563557
}
564558

@@ -595,9 +589,7 @@ int notify_ebr_subscriptions( ebr_event *ev, evi_params_t *params)
595589
LM_ERR("failed to send job via IPC, skipping...\n");
596590
shm_free(job);
597591
}
598-
/* remove the subscription, as it can be triggered only
599-
* one time */
600-
sub_next = sub->next;
592+
601593
/* unlink it */
602594
if (sub_prev) sub_prev->next = sub_next;
603595
else ev->subs = sub_next;
@@ -651,15 +643,12 @@ void ebr_timeout(unsigned int ticks, void* param)
651643

652644
/* check the EBR subscriptions on this event */
653645
sub_prev = NULL;
654-
sub_next = NULL;
655-
for ( sub=ev->subs ; sub ; sub_prev=sub,
656-
sub=sub_next?sub_next:(sub?sub->next:NULL) ) {
646+
for ( sub=ev->subs ; sub ; sub_prev=sub, sub=sub_next ) {
647+
sub_next = sub->next;
657648

658649
/* skip valid and non WAIT subscriptions */
659-
if ( (sub->flags&EBR_SUBS_TYPE_WAIT)==0 || sub->expire>my_time ) {
660-
sub_next = sub->next;
650+
if ( (sub->flags&EBR_SUBS_TYPE_WAIT)==0 || sub->expire>my_time )
661651
continue;
662-
}
663652

664653
LM_DBG("subscription type [%s] from process %d(pid %d) on "
665654
"event <%.*s> expired at %d, now %d\n",
@@ -672,7 +661,6 @@ void ebr_timeout(unsigned int ticks, void* param)
672661
job =(ebr_ipc_job*)shm_malloc( sizeof(ebr_ipc_job) );
673662
if (job==NULL) {
674663
LM_ERR("failed to allocated new IPC job, skipping..\n");
675-
sub_next = sub->next;
676664
continue; /* with the next subscription */
677665
}
678666
job->ev = ev;
@@ -685,12 +673,9 @@ void ebr_timeout(unsigned int ticks, void* param)
685673
if (ipc_send_job( sub->proc_no, ebr_ipc_type , (void*)job)<0) {
686674
LM_ERR("failed to send job via IPC, skipping...\n");
687675
shm_free(job);
688-
sub_next = sub->next;
689676
continue; /* with the next subscription */
690677
}
691678

692-
/* remove the subscription */
693-
sub_next = sub->next;
694679
/* unlink it */
695680
if (sub_prev) sub_prev->next = sub_next;
696681
else ev->subs = sub_next;

0 commit comments

Comments
 (0)