My Project
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Functions
sw_semaphores.c File Reference
#include <sw_semaphores.h>
#include <sw_debug.h>
#include <unused.h>
#include <cpu.h>

Functions

s32int sw_mutex_init (sw_mutex_t *mutex, const sw_mutexattr_t *attribute)
 Initializes mutex parameters. More...
 
s32int sw_mutex_destroy (sw_mutex_t *mutex)
 This function is called to destroy the mutex once it is used If it is under lock it returns an error code init param is reinitialized to zero. More...
 
s32int sw_mutex_lock (sw_mutex_t *mutex)
 This function is called to lock the specified mutex. More...
 
s32int sw_mutex_unlock (sw_mutex_t *mutex)
 This function is called to unlock a mutex. More...
 
s32int sw_mutex_trylock (sw_mutex_t *mutex)
 Same as sw_mutex_lock but it does not block the calling function It returns an error code if the mutex is already locked. More...
 
s32int sw_sem_init (sw_sem_t *sem, s32int shared, u32 value)
 Semaphore initialization Following successful call, other semaphore operations can be performed until semaphore is destroyed. More...
 
s32int sw_sem_wait (sw_sem_t *sem)
 Locks the semaphore referenced by sem It will return to the calling thread only after locking the semaphore or if the call is interrupted by a signal. More...
 
s32int sw_sem_post (sw_sem_t *sem)
 unlocks the semaphore referenced by sem by performing a unlock operation on that semaphore More...
 
s32int sw_sem_destroy (sw_sem_t *sem)
 Destroys the semaphore indicated by sem. More...
 
s32int sw_sem_getvalue (sw_sem_t *sem, s32int *value)
 This function is called to get the semaphore value. More...
 

Function Documentation

s32int sw_mutex_destroy ( sw_mutex_t mutex)

This function is called to destroy the mutex once it is used If it is under lock it returns an error code init param is reinitialized to zero.

this function destroys the mutex object. Attempting to destroy a mutex that has already been destroyed has no effect. Attempting to destroy a locked mutex fails.

Parameters
mutex
Returns
s32int sw_mutex_init ( sw_mutex_t mutex,
const sw_mutexattr_t attribute 
)

Initializes mutex parameters.

dymanic initialization of the mutex. The attribute parameter is kept for consistency and is not used. Attempting to re-initialize a mutex will reset it.

Parameters
mutex
attribute
Returns
s32int sw_mutex_lock ( sw_mutex_t mutex)

This function is called to lock the specified mutex.

this function locks the mutex object referenced. If the mutex is already locked, it blocks till it becomes available. Once it is available, it is locked. No deadlock detection is provided.

Parameters
mutex
Returns
s32int sw_mutex_trylock ( sw_mutex_t mutex)

Same as sw_mutex_lock but it does not block the calling function It returns an error code if the mutex is already locked.

Try to lock the mutex. This function is same as the lock function, except that it returns if the mutex cannot be locked.

Parameters
mutex
Returns
s32int sw_mutex_unlock ( sw_mutex_t mutex)

This function is called to unlock a mutex.

this function unlocks the mutex object referenced. Attempts to unlock a mutex that is already locked has no effect.

Parameters
mutex
Returns
s32int sw_sem_destroy ( sw_sem_t sem)

Destroys the semaphore indicated by sem.

Delete the semaphore pointed to by sem variable The semaphore cannot be used after deletion.

Parameters
sem
Returns
s32int sw_sem_getvalue ( sw_sem_t sem,
s32int *  value 
)

This function is called to get the semaphore value.

Get the current value of the semaphore. It is copied into the argument supplied by the caller.

Parameters
sem
value
Returns
s32int sw_sem_init ( sw_sem_t sem,
s32int  shared,
u32  value 
)

Semaphore initialization Following successful call, other semaphore operations can be performed until semaphore is destroyed.

This function initializes the semaphore, and sets is counters to the value passed to it.

Parameters
sem
shared
value
Returns
s32int sw_sem_post ( sw_sem_t sem)

unlocks the semaphore referenced by sem by performing a unlock operation on that semaphore

This function unlocks the semaphore referenced by sem. The value is incremented atomically. If there are any threads waiting on this semaphore, only one of them would be released from sem_wait.

Parameters
sem
Returns
s32int sw_sem_wait ( sw_sem_t sem)

Locks the semaphore referenced by sem It will return to the calling thread only after locking the semaphore or if the call is interrupted by a signal.

This function locks the semaphore referenced by the sem value. An atomic decrement is performed. If the counters become negative, sem_init is blocked, till another thread invokes sw_sem_post.

Parameters
sem
Returns