Page 1 of 1

chibios_rt::Mutex no unlock methods

Posted: Tue Mar 24, 2015 4:32 pm
by Thargon
Hi,

I just tried to use the C++ wrapper for mutexes and was surprised when I didn't find any methods to unlock it.
It's no problem since the wrapper class just calls the chMtx... functions, but shouldn't a wrapper cover ALL the available functions?
Is there a reason why no unlock methods are provided?
If not, I will gladly create a patch ;)

Thargon

Re: chibios_rt::Mutex no unlock methods

Posted: Tue Mar 24, 2015 4:42 pm
by Giovanni
Hi,

If I remember well it is a method of the thread object because it intrinsically operates on the last mutex taken.

Propose your patch, it is not set in stone.

Giovanni

Re: chibios_rt::Mutex no unlock methods

Posted: Tue Mar 24, 2015 7:42 pm
by colin
Thargon, is this the code you are talking about?

Code: Select all

 void Mutex::unlock(void) {

    chMtxUnlock(&mutex);
  }

  void Mutex::unlockS(void) {

    chMtxLockS(&mutex);
  }


This code has been in ChibiOS ch.cpp/ch.hpp since Aug 2014.

Re: chibios_rt::Mutex no unlock methods

Posted: Tue Mar 24, 2015 8:52 pm
by Giovanni
I must be forgetting things.... :(

Re: chibios_rt::Mutex no unlock methods

Posted: Wed Mar 25, 2015 1:34 pm
by Thargon
Strange...
In the online documentation there are no such methods.
In my cloned version (2.6.7) these are missing as well.

Maybe the code is included in 3.0 but missing for 2.x.x?

However, the snippet provided by colin should do the job.

Re: chibios_rt::Mutex no unlock methods

Posted: Wed Mar 25, 2015 8:36 pm
by colin
colin wrote:Thargon, is this the code you are talking about?

Code: Select all

 void Mutex::unlock(void) {

    chMtxUnlock(&mutex);
  }

  void Mutex::unlockS(void) {

    chMtxLockS(&mutex);
  }


This code has been in ChibiOS ch.cpp/ch.hpp since Aug 2014.


Yikes, I think this is a bad bug: It seems that Mutex::unlockS() should call chMtxUnlockS() and not chMtxLockS() again.

Re: chibios_rt::Mutex no unlock methods

Posted: Wed Mar 25, 2015 8:40 pm
by Giovanni
Fixed.

Giovanni