From bbc0a56d2b107b7fd2a753ec7882ada5bcd55ae2 Mon Sep 17 00:00:00 2001 From: Martin Konrad Date: Tue, 13 Oct 2020 18:22:08 -0400 Subject: [PATCH 1/2] Fix wrong PHAS order Records with lower PHAS value than any previously loaded records were inserted at the end of the list rather than at the beginning. This fixes lp: #1899697. Also fixes a proto-bug in that the second argument to the previously used ellAdd() call assumed that offsetof(scan_element, node)==0. Thanks to Bruno Martins for providing this patch. --- src/ioc/db/dbScan.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ioc/db/dbScan.c b/src/ioc/db/dbScan.c index dd283f7bf..c8a43519b 100644 --- a/src/ioc/db/dbScan.c +++ b/src/ioc/db/dbScan.c @@ -998,7 +998,7 @@ static void addToList(struct dbCommon *precord, scan_list *psl) } ptemp = (scan_element *)ellPrevious(&ptemp->node); } - if (ptemp == NULL) ellAdd(&psl->list, (void *)pse); + if (ptemp == NULL) ellInsert(&psl->list, NULL, &pse->node); psl->modified = TRUE; epicsMutexUnlock(psl->lock); } @@ -1024,7 +1024,7 @@ static void deleteFromList(struct dbCommon *precord, scan_list *psl) return; } pse->pscan_list = NULL; - ellDelete(&psl->list, (void *)pse); + ellDelete(&psl->list, &pse->node); psl->modified = TRUE; epicsMutexUnlock(psl->lock); } From 228ad79b7a33ec61cdfcebce9e357a019ead6bb7 Mon Sep 17 00:00:00 2001 From: Martin Konrad Date: Tue, 13 Oct 2020 18:38:17 -0400 Subject: [PATCH 2/2] Simplify addToList() function --- src/ioc/db/dbScan.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/ioc/db/dbScan.c b/src/ioc/db/dbScan.c index c8a43519b..5fc264d51 100644 --- a/src/ioc/db/dbScan.c +++ b/src/ioc/db/dbScan.c @@ -992,13 +992,10 @@ static void addToList(struct dbCommon *precord, scan_list *psl) pse->pscan_list = psl; ptemp = (scan_element *)ellLast(&psl->list); while (ptemp) { - if (ptemp->precord->phas <= precord->phas) { - ellInsert(&psl->list, &ptemp->node, &pse->node); - break; - } + if (ptemp->precord->phas <= precord->phas) break; ptemp = (scan_element *)ellPrevious(&ptemp->node); } - if (ptemp == NULL) ellInsert(&psl->list, NULL, &pse->node); + ellInsert(&psl->list, (ptemp ? &ptemp->node : NULL), &pse->node); psl->modified = TRUE; epicsMutexUnlock(psl->lock); }