OSFastCond_Wait

Syntax

#include <cafe/os.h>

void OSFastCond_Wait (OSFastCond* fastCond, OSFastMutex* fastMutex);

Parameters

fastCond Pointer to fast condition variable.
fastMutex Pointer to fast mutex.

Return Values

None.

Description

Blocks the calling thread on the fast condition variable and unlocks the fast mutex. Must be called by the thread that owns the fast mutex.

The calling thread is made runnable again by calling the OSFastCond_Signal function. When this function returns, the calling thread will become the owner of the fast mutex.

Note that the fast mutex is temporarily unlocked regardless of the number of times this thread may have locked the mutex with the OSFastMutex_Lock function. When this thread reacquires the fast mutex and notification is given of the condition variable (via the OSFastCond_Signal function), the mutex lock count is restored; each call to the OSFastMutex_Lock function must have a corresponding call to the OSFastMutex_Unlock function.

An example of condition variable use is the following bounded buffer program.

u32 Append (u32 item, buffer * buf)
{
      OSFastMutex_Lock(&buf->mutex);
      while (buf->itemCount == MAX_BUF_SIZE)
      {
            OSFastCond_Wait(buf->bufferNotFullCV, &buf->mutex);
      }
      // know that the buffer is not full and that I own the mutex
      InsertData(item, buf);
      OSFastMutex_Unlock(&buf->mutex);
       // let any consumers know that the buffer is not empty anymore.
      OSFastCond_Signal(&buf->bufferNotEmptyCV);
}
u32 Take (u32 * item, buffer * buf)
{
      OSFastMutex_Lock(&buf->mutex);
      while (buf->itemCount == 0)
      {
            OSFastCond_Wait(buf->bufferNotEmptyCV, &buf->mutex);
      }
      // know that the buffer is not empty and that I own the mutex
      ExtractData(item, buf);
      OSFastMutex_Unlock(&buf->mutex);
      // let any appenders know that the buffer is not full anymore.
      OSFastCond_Signal(&buf->bufferNotFullCV);
}

Do Not Call From

Callbacks Do not call this function from any callback function.

See Also

OSFastCond_Init
OSFastCond_Signal
OSFastMutex_Init
OSFastMutex_Lock
OSFastMutex_Unlock
OSFastMutex_TryLock

Revision History

2013/04/24 Initial Version.


CONFIDENTIAL