This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

How to port LCK_pend( ) with timeout parameter to SYS/BIOS?

Hi,

Now I want to replace the following LCK_pend( ) in SYS/BIOS:

if( FALSE == LCK_pend( lock_hdl, 0xFFFFFFFF ) )

According to SPRAAS7, the "LCK" module is to replaced by the "GateMutex" module.  

But GateMutex doesn't take the timeout paremeter.

Should I use SYS/BIOS 6 legacy module?

since I have already created a .cfg file for new SYS/BIOS project,  What's the step to integrate the LCK module based on the cfg file?

Thanks in advance!

  • Gates are intended to be used for critical region management, not general resource management. We decided that having a timeout with gates was extra overhead so we do not include it in the API. With critical region management, you should enter the gate, do your business as quickly as possible and then leave the gate. Having a timeout complicates the code (e.g. you have to check the return to see if you got it or not...and then what do you do if you did not get it?).

    Note: LCK_pend(handle, 0xFFFFFFFF) is equivalent to GateMutex_enter(handle). Internally GateMutex uses (Uns)-1 as the timeout when it calls Semaphore_pend. So if you are only using 0xFFFFFFFF in your LCK_pend calls, just use GateMutex instead directly.

    Note: we use (Uns)-1 instead of 0xFFFFFFFF because an unsigned is not 32 bits on some devices.

    Todd


  • Hi Todd,

    Thank you for your reply.


    In our scenario, we need to do some error report when time is out.


    Just like below:

     if( FALSE == LCK_pend( lock_hdl, 0xFFFFFFFF ) ) // timeout = 0xFFFFFFFF system clock ticks;
     {
          SYS_Handle_Error(); // report errors
     }

    else

    {

         do some processing

         LCK_post( lock_hdl );

    }

    As you said, internally GateMutex uses (Uns)-1 as the timeout when it calls Semaphore_pend.

    If my understanding is correct, I can just replace the above code with the folowing:

    IArg gate_IArg;

    gate_IArg = GateMutex_enter( lock_hdl);

    if( ((unsigned int)-1) == gate_IArg )
     {
          SYS_Handle_Error(); // report errors
     }

    else

    {

          do some processing

         GateMutex_leave(lock_hdl,gate_IArg);

    }

    Is that true?

    If not, can you give me the correct code? Thank you!

  • That's not quite correct. Your code would be:

    IArg gate_IArg;

    gate_IArg = GateMutex_enter( lock_hdl);

    do some processing

    GateMutex_leave(lock_hdl,gate_IArg);

    Entering a Gate cannot fail. It never timeouts.

    Note: I made a small mistake. GateMutex_enter calls Semaphore_pend with BIOS_WAIT_FOREVER which is ~(0)...so basically the same.

    Todd

  • Hi Todd,

    If GateMutex is used,  I can't use SYS_Handle_Error(). Is that true?

     And If GateMutex waits forever, I think it's unacceptable for out system.

    Thank you!

  • When you used 0xffffffff (or basically ((Uns)-1)) in LCK_pend, this was SYS_FOREVER. So the functionality is the same.

    Todd

  • Hi Todd,

    OK, I see.

    Thank you!