chibios_rt::Mutex no unlock methods

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

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
Thargon
Posts: 135
Joined: Wed Feb 04, 2015 5:03 pm
Has thanked: 15 times
Been thanked: 24 times

chibios_rt::Mutex no unlock methods

Post 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
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: chibios_rt::Mutex no unlock methods

Post 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
colin
Posts: 149
Joined: Thu Dec 22, 2011 7:44 pm

Re: chibios_rt::Mutex no unlock methods

Post 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.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: chibios_rt::Mutex no unlock methods

Post by Giovanni »

I must be forgetting things.... :(
Thargon
Posts: 135
Joined: Wed Feb 04, 2015 5:03 pm
Has thanked: 15 times
Been thanked: 24 times

Re: chibios_rt::Mutex no unlock methods

Post 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.
colin
Posts: 149
Joined: Thu Dec 22, 2011 7:44 pm

Re: chibios_rt::Mutex no unlock methods

Post 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.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: chibios_rt::Mutex no unlock methods

Post by Giovanni »

Fixed.

Giovanni
Post Reply