Producer from ISRs Example / S-Locked Query Topic is solved

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

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
alan5
Posts: 24
Joined: Mon Nov 11, 2013 5:06 pm
Has thanked: 1 time
Been thanked: 1 time

Producer from ISRs Example / S-Locked Query

Post by alan5 »

Hello,

I'd like to implement some form of producer ISR, consumer thread queue and found the following page:
http://www.chibios.org/dokuwiki/doku.ph ... el_mutexes

I'm trying to make sense of the "Producer from ISRs" example.

I was hoping someone would be able to help explain the behaviour of qConsume():

  1. chSysLock() disables interrupts
  2. The mutex is locked
  3. The queue is empty
  4. chCondWaitS() is used to:
    1. free the mutex
    2. wait on the queue to fill

Will the chSysLock() call still be active and blocking interrupts during this wait?
I think my understanding of the "S" system state is lacking - it's possible to sleep in an S state?

Some relevant documentation:

chCondWaitS - http://chibios.sourceforge.net/docs3/rt ... 2ab2c2996c
System States - http://chibios.sourceforge.net/html/con ... tem_states
chSchGoSleepS - http://chibios.sourceforge.net/html/gro ... 19c1ccf986
awygle
Posts: 32
Joined: Sun Apr 03, 2016 8:39 pm
Has thanked: 6 times
Been thanked: 4 times

Re: Producer from ISRs Example / S-Locked Query

Post by awygle »

When sleeping in a locked state (using S-class functions), interrupts are re-enabled when the thread is switched out, and disabled again when the thread is switched back in. (More properly, the system lock is released - this may or may not be the same as "interrupts" on all platforms, hence chSysLockFromISR())

If you look at the implementations of most of the non S-class Sleep- and Wait-type functions, internally they are just locking and calling the corresponding S-class version of themselves.
alan5
Posts: 24
Joined: Mon Nov 11, 2013 5:06 pm
Has thanked: 1 time
Been thanked: 1 time

Re: Producer from ISRs Example / S-Locked Query

Post by alan5 »

Thanks for your reply. I had my suspicions about this but was hoping someone could confirm the behaviour.
Presumably then threads which were suspended as a result of normal scheduling, as opposed to the user making a blocking API call are not relocked? Since the chSysLock() call was not made by the user.
Presumably detection for this is if the thread state was "sleeping" or "ready"?
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Producer from ISRs Example / S-Locked Query

Post by Giovanni »

Hi,

The switch protocol in ChibiOS is:

lock
switch
unlock

The unlock operation is done "on the other side" after the thread switched. It never happens that the system stays with interrupts disabled waiting for something.

Giovanni
Post Reply