diff options
author | Rory Byrne <[email protected]> | 2015-05-14 20:07:39 +0100 |
---|---|---|
committer | Rory Byrne <[email protected]> | 2015-06-04 21:59:45 +0100 |
commit | 34b858c3e329918d530da882b594d2db727d3856 (patch) | |
tree | b75aadfd76c2fcfe80557dcbce4fc3f0f27e4ed6 /erts/emulator | |
parent | 81e21569a6cf9e5989348939b28ccedc1cc0dab1 (diff) | |
download | otp-34b858c3e329918d530da882b594d2db727d3856.tar.gz otp-34b858c3e329918d530da882b594d2db727d3856.tar.bz2 otp-34b858c3e329918d530da882b594d2db727d3856.zip |
Fix add_multi_timer() in inet_drv
Fix the sorting logic in add_multi_timer() and expand the test case
coverage around this area.
Diffstat (limited to 'erts/emulator')
-rw-r--r-- | erts/emulator/drivers/common/inet_drv.c | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/erts/emulator/drivers/common/inet_drv.c b/erts/emulator/drivers/common/inet_drv.c index e001f31932..10ef20fc82 100644 --- a/erts/emulator/drivers/common/inet_drv.c +++ b/erts/emulator/drivers/common/inet_drv.c @@ -12172,6 +12172,8 @@ static MultiTimerData *add_multi_timer(MultiTimerData **first, ErlDrvPort port, void (*timeout_fun)(ErlDrvData drv_data, ErlDrvTermData caller)) { +#define eq_mega(a, b) ((a)->when.megasecs == (b)->when.megasecs) +#define eq_sec(a, b) ((a)->when.secs == (b)->when.secs) MultiTimerData *mtd, *p, *s; mtd = ALLOC(sizeof(MultiTimerData)); absolute_timeout(timeout, &(mtd->when)); @@ -12183,23 +12185,17 @@ static MultiTimerData *add_multi_timer(MultiTimerData **first, ErlDrvPort port, break; } } - if (!p || p->when.megasecs > mtd->when.megasecs) { - goto found; - } - for (; p!= NULL; s = p, p = p->next) { + for (; p!= NULL && eq_mega(p, mtd); s = p, p = p->next) { if (p->when.secs >= mtd->when.secs) { break; } } - if (!p || p->when.secs > mtd->when.secs) { - goto found; - } - for (; p!= NULL; s = p, p = p->next) { + for (; p!= NULL && eq_mega(p, mtd) && eq_sec(p, mtd); s = p, p = p->next) { if (p->when.microsecs >= mtd->when.microsecs) { break; } } - found: + if (!p) { if (!s) { *first = mtd; @@ -12225,6 +12221,8 @@ static MultiTimerData *add_multi_timer(MultiTimerData **first, ErlDrvPort port, } return mtd; } +#undef eq_mega +#undef eq_sec |