Page 1 of 1

strange chDbgAssert in chthreads.c

Posted: Wed Aug 27, 2014 6:34 am
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");

?

Re: strange chDbgAssert in chthreads.c

Posted: Wed Aug 27, 2014 8:04 am
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

Re: strange chDbgAssert in chthreads.c

Posted: Wed Aug 27, 2014 8:22 am
by Michail
Oh, I see.
Found "*trp = NULL;" in chThdResumeI :) Now it all gets clear. Thank you!