- Timer mutex bugs fixed (again...)

- IPRA bugs fixed
This commit is contained in:
Wiesner András 2023-11-04 21:52:38 +01:00
parent ae2c228bda
commit 5fa42c0326
3 changed files with 12 additions and 11 deletions

View File

@ -55,7 +55,7 @@ static void ipra_remove_chain(IPv4Assembler * ipra, uint16_t id) {
return;
}
timer_unsched(E.tmr, chainDesc->id); // remove timeout schedule
timer_unsched(E.tmr, chainDesc->alarmID); // remove timeout schedule
IPv4Fragment * iter = chainDesc->fragChain; // unlink and release fragment chain
while (iter != NULL) {
IPv4Fragment * oldIter = iter;
@ -66,7 +66,7 @@ static void ipra_remove_chain(IPv4Assembler * ipra, uint16_t id) {
FragChainDesc * chainIter = ipra->chains;
while (chainIter != NULL) { // unlink chain from chain list
if (chainIter->next == chainDesc) { // if element is found
chainIter->next = chainDesc->next; // skip by looked up element by setting next properly
chainIter->next = chainDesc->next; // skip looked up element by setting next properly
break; // break the loop
}
chainIter = chainIter->next;
@ -104,7 +104,7 @@ static void ipra_insert_into_chain(FragChainDesc *chainDesc, const IPv4Props *ip
((iter->next == NULL) || (iter->next->offset >= (frag->offset + frag->size)))) {
frag->next = iter->next;
iter->next = frag;
} else if ((iter == chainDesc->fragChain) && (frag->offset < iter->offset)) { // insert before the firstly received segment
} else if ((iter == chainDesc->fragChain) && (frag->offset < iter->offset)) { // insert before the first received segment
frag->next = iter;
chainDesc->fragChain = frag;
}
@ -141,8 +141,7 @@ void ipra_input(IPv4Assembler *ipra, const IPv4Props *ipProps, const uint8_t *pa
AlarmUserData aud;
aud.ptr = ipra;
aud.u = chainDesc->id;
timer_sched_rel(E.tmr, IP_REASSEMBLY_TIMEOUT_US, ipra_timeout, aud);
timer_report(E.tmr);
chainDesc->alarmID = timer_sched_rel(E.tmr, IP_REASSEMBLY_TIMEOUT_US, ipra_timeout, aud);
}
bool ipra_try_reassemble(IPv4Assembler *ipra, uint16_t id, uint8_t **payload, uint16_t *size, PcktHeaderElement *pcktHdrLe) {

10
timer.c
View File

@ -106,7 +106,6 @@ uint32_t timer_sched(Timer *tmr, const TimePoint *t, TimerAlarmCb cb, AlarmUserD
// increase allocation count
tmr->nSched++;
MSG("%d %s\n", tmr->nSched, __FUNCTION__);
// replace nearest if needed
if (tmr->nSched > 1) {
@ -129,6 +128,10 @@ uint32_t timer_sched_rel(Timer *tmr, int64_t us, TimerAlarmCb cb, AlarmUserData
}
void timer_unsched(Timer *tmr, uint32_t id) {
if (id == 0) { // no unscheduling on receiving unknown id
return;
}
ETHLIB_OS_MTX_LOCK(&(tmr->tabMtx));
if (tmr->nSched > 0) {
@ -136,7 +139,6 @@ void timer_unsched(Timer *tmr, uint32_t id) {
if (alarm != NULL) {
memset(alarm, 0, sizeof(AlarmAssignment));
tmr->nSched--;
MSG("%d %s\n", tmr->nSched, __FUNCTION__);
timer_update_nearest_alarm(tmr);
}
}
@ -181,11 +183,12 @@ void timer_tick(Timer *tmr, int64_t us) {
// decrease scheduled alarm count
tmr->nSched--;
MSG("%d %s\n", tmr->nSched, __FUNCTION__);
// update nearest alarm
timer_update_nearest_alarm(tmr);
ETHLIB_OS_MTX_UNLOCK(&(tmr->tabMtx));
// invoke callback
if (alarm.cb != NULL) {
alarm.cb(tmr, alarm.params);
@ -195,7 +198,6 @@ void timer_tick(Timer *tmr, int64_t us) {
t_alarm = time_to_us(&(tmr->nextAlarm->time));
}
ETHLIB_OS_MTX_UNLOCK(&(tmr->tabMtx));
}
}
}

View File

@ -10,8 +10,8 @@
* A single point in time
*/
typedef struct {
int64_t s; ///< Seconds
int64_t us; ///< Microseconds
uint32_t s; ///< Seconds
uint32_t us; ///< Microseconds
} TimePoint;
/**