My Project
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Classes | Macros | Functions
sw_semaphores.h File Reference
#include <sw_types.h>
#include <sw_cpu_helper.h>

Go to the source code of this file.

Classes

struct  sw_mutex_t
 
struct  sw_sem_t
 
struct  spinlock
 

Macros

#define OTZ_LOCKED   1
 
#define OTZ_FREE   0
 
#define TRUE   1
 
#define FALSE   0
 
#define OTZ_OK   0
 
#define OTZ_INVALID   1
 
#define OTZ_BUSY   2
 
#define OTZ_AGAIN   3
 
#define INIT_SPIN_LOCK(s)   ((s)->lock = 0)
 
#define OTZ_MUTEX_INIT   {TRUE, OTZ_FREE}
 
#define sw_mutexattr_t   void
 

Functions

void sw_spinlock_s (void *data)
 
void sw_spinunlock_s (void *data)
 
void sw_sem_post_s (volatile s32int *data)
 
void sw_sem_wait_s (volatile s32int *data)
 
u32 sw_trylock_s (void *data)
 
s32int sw_mutex_init (sw_mutex_t *mutex, const sw_mutexattr_t *attribute)
 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. More...
 
s32int sw_mutex_destroy (sw_mutex_t *mutex)
 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. More...
 
s32int sw_mutex_lock (sw_mutex_t *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. More...
 
s32int sw_mutex_unlock (sw_mutex_t *mutex)
 this function unlocks the mutex object referenced. Attempts to unlock a mutex that is already locked has no effect. More...
 
s32int sw_mutex_trylock (sw_mutex_t *mutex)
 Try to lock the mutex. This function is same as the lock function, except that it returns if the mutex cannot be locked. More...
 
s32int sw_sem_init (sw_sem_t *sem, s32int shared, u32 value)
 This function initializes the semaphore, and sets is counters to the value passed to it. More...
 
s32int sw_sem_wait (sw_sem_t *sem)
 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. More...
 
s32int sw_sem_post (sw_sem_t *sem)
 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. More...
 
s32int sw_sem_destroy (sw_sem_t *sem)
 Delete the semaphore pointed to by sem variable The semaphore cannot be used after deletion. More...
 
s32int sw_sem_getvalue (sw_sem_t *sem, s32int *value)
 Get the current value of the semaphore. It is copied into the argument supplied by the caller. More...
 

Macro Definition Documentation

#define FALSE   0
#define INIT_SPIN_LOCK (   s)    ((s)->lock = 0)
#define OTZ_AGAIN   3
#define OTZ_BUSY   2
#define OTZ_FREE   0
#define OTZ_INVALID   1
#define OTZ_LOCKED   1
#define OTZ_MUTEX_INIT   {TRUE, OTZ_FREE}
#define OTZ_OK   0
#define sw_mutexattr_t   void
#define TRUE   1

Function Documentation

s32int sw_mutex_destroy ( sw_mutex_t mutex)

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- A pointer to the mutex that needs to be destroyed.
Returns
OTZ_OK if the deletion was successful.
OTZ_INVALID if the value specified by the mutex was invalid.
OTZ_BUSY if the mutex is locked and cannot be destroyed.

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 
)

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.

This function must be invoked before a mutex can be used.

Parameters
mutex- A pointer to the mutex that needs to be initialized
attribute- A pointer to the attributes of the mutex
Returns
OTZ_OK if the initialization was successful
OTZ_INVALID if the value specified by mutex was invalid

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 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- A pointer to the mutex that has to be locked.
Returns
OTZ_OK If the attempt to lock was successful.
OTZ_INVALID If the mutex was un-initialized, of the value is invalid.

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)

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- A pointer to the mutex that needs to be locked.
Returns
OTZ_OK If the lock was successful.
OTZ_INVALID If the value specified by mutex is invalid or mutex was not initalized.
OTZ_BUSY 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 unlocks the mutex object referenced. Attempts to unlock a mutex that is already locked has no effect.

Parameters
mutex- A pointer to the mutex that has to be unlocked.
Returns
OTZ_OK If the attempt to unlock was successful.
OTZ_EINVAL If the value specified in the mutex is invalid or un-initialized.

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)

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

Parameters
sem- The semaphore to be destroyed.
Return values
OTZ_OKIf the semaphore has been deleted successfully.
OTZ_INVALIDIf the semaphore parameter is invalid.
OTZ_BUSYIf the semaphore is currently busy and hence cannot be destroyed.

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 
)

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

Parameters
sem- The semaphore whose value has to be obtained.
value- The location where the value of the semaphore needs to be copied.
Returns
OTZ_OK The value has been succesfully copied.
OTZ_INVALID Invalid value for semaphore or the location where the value needs to be copied into.

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 
)

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

Parameters
sem- A pointer to the semaphore that needs to be initialized
shared- Not supported and any value that is passed is ignored.
value- The value that needs to be assigned to the semaphore.
Returns
OTZ_OK If the initialization suceeded.
OTZ_INVALID If the semaphore that was passed is invalid.

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)

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- A pointer to the semaphore that needs to be incremented.
Returns
OTZ_OK If the operation is successful.
OTZ_INVALID If the semaphore is invalid.

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
void sw_sem_post_s ( volatile s32int *  data)
Parameters
data
s32int sw_sem_wait ( sw_sem_t sem)

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- A pointer to the semaphore to be waited upon on.
Returns
OTZ_OK If the operation was successful.
OTZ_INVALID If the semaphore that was passed to it is invalid.

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
void sw_sem_wait_s ( volatile s32int *  data)
Parameters
data
void sw_spinlock_s ( void *  data)
Parameters
data
void sw_spinunlock_s ( void *  data)
Parameters
data
u32 sw_trylock_s ( void *  data)
Parameters
data
Returns