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.

Mutex Semaphore?

Other Parts Discussed in Thread: SYSBIOS

Processor: Gauss c6657

currently I am using SYSBIOS: 6.33.6.50

I am trying to insert a wrapper for some application code with VxWorks/Linux calls. 

For semaphore functions:

semCCreate( int options, int initialCount ) 
semBCreate( int options, int initialState ) 
semMCreate( int options ) 

1. semCcreate counting semaphore, but how do we define its options in semaphore_create function?

    (//These options are SEM_Q_PRIORITY (0x1) and SEM_Q_FIFO (0x0), respectively)

2. similarly semBcreate() how do we define options. 

3. semMCreate() which is a mutex semaphore. What is the equivalent semaphore API which creates a mutex semaphore. 

Regards,

Hari

  • Hari,

    Here's how you can create a counting semaphore or binary semaphore in SYS/BIOS:

    Semaphore_Handle sem;

    Semaphore_Params params;

    Semaphore_Params_init(&params);

    params.mode = Semaphore_Mode_COUNTING_PRIORITY; // or Semaphore_Mode_BINARY_PRIORITY (only with SYS/BIOS 6.34.00.10 or newer)

    params.mode = Semaphore_Mode_COUNTING; // or Semaphore_Mode_BINARY for FIFO based sem

    sem = Semaphore_create(count, &params, eb); // count =  1 for creating a binary semaphore. Any other count value will create a counting semaphore.

    Unfortunately the release that you are using only supports FIFO based semaphores. On newer versions of BIOS (6.34.00.10 or newer) it is possible to create a PRIORITY based semaphore in addition to the FIFO based semaphore.  You could move to a newer release to get this support.

    There are some additional parameters that you can specify. I have not used them in the above example. Please refer the SYS/BIOS User Guide as well the API reference for more info.

    Best,

    Ashish

  • Ashish

      Thanks. I shall update to latest SYSBIOS. 

    Can you suggest how to implement a Mutex Semaphore (semMCreate()?)

    I am not sure if SYSBIOS differentiates between binary semaphore and Mutex semaphore. 

    Regards,

    Hari

  • Hi Hari,

    SYS/BIOS does not provide an equivalent API for semMCreate(). If you would like to create a Mutex Semaphore, you could create a wrapper for the Binary Semaphore. You would basically need a wrapper for Semaphore_create(), Semaphore_pend() and Semaphore_post().

    - Semaphore_create() wrapper: Creates a semaphore and a object (structure instance) that stores the Task handle.

    - Semaphore_pend() wrapper: Stores the calling Task's handle in the object and then calls Semaphore_pend().

    - Semaphore_post() wrapper: Checks if the calling Task's handle matches the stored Task handle. If it matches then call Semaphore_post().

    Best,

    Ashish

  • Thanks Ashish,

       I got a following question on pthread function equivalents like pthread_mutex calls. A few of them. appreciate if you can offer a right direction in generating these APIs with SYSBIOS. 

    Regards,

    Hari

    pthread_mutex_unlock,   //Mutex lock

    pthread_mutex_lock   // Mutex_unlock

    pthread_key_create

    pthread_setspecific

    pthread_getspecific

  • Hi Hari,

    There is an open source project that has a pthread library compatible with DSP/BIOS - http://pthreads-emb.sourceforge.net/

    This project might be a good starting point.

    Best,

    Ashish