strange chDbgAssert in chthreads.c

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
Michail
Posts: 28
Joined: Mon Aug 04, 2014 6:55 am

strange chDbgAssert in chthreads.c

Post by Michail »

Hello, Giovanni!

In function:

Code: Select all

msg_t chThdSuspendTimeoutS(thread_reference_t *trp, systime_t timeout) {
  thread_t *tp = chThdGetSelfX();

  chDbgAssert(*trp == NULL, "not NULL");

  if (TIME_IMMEDIATE == timeout)
    return MSG_TIMEOUT;

  *trp = tp;
  tp->p_u.wtobjp = &trp;
  return chSchGoSleepTimeoutS(CH_STATE_SUSPENDED, timeout);
}


Sorry, but I don't fully understand the purpose of "chDbgAssert(*trp == NULL, "not NULL");"
Later, we assign the value of "tp" to it, so why sould we check it?
Maybe there should be

Code: Select all

chDbgAssert(trp == NULL, "not NULL");

?
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: strange chDbgAssert in chthreads.c

Post by Giovanni »

Hi,

The thread reference pointer is also a flag, if NULL then it can be assigned and the current thread takes the "slot", if it is not NULL then there is already a suspended thread in that slot, we cannot assign it again.

Giovanni
Michail
Posts: 28
Joined: Mon Aug 04, 2014 6:55 am

Re: strange chDbgAssert in chthreads.c

Post by Michail »

Oh, I see.
Found "*trp = NULL;" in chThdResumeI :) Now it all gets clear. Thank you!
Post Reply