msp_rwlocks.h File Reference

Userspace read write locking functions for the MultiServices PIC SDK. More...


Data Structures

struct  msp_rwlock_s
 Read write lock data structure. More...

Typedefs

typedef msp_rwlock_s msp_rwlock_t
 Read write lock data structure.

Functions

int msp_rwlock_init (msp_rwlock_t *lock)
 Initializes the read write lock.
int msp_rwlock_destroy (msp_rwlock_t *lock)
 Destroys the read write lock.
int msp_rwlock_rlock (msp_rwlock_t *lock)
 Acquire a read lock.
int msp_rwlock_wlock (msp_rwlock_t *lock)
 Acquire a write lock.
int msp_rwlock_try_rlock (msp_rwlock_t *lock)
 Acquire a read lock without blocking.
int msp_rwlock_try_wlock (msp_rwlock_t *lock)
 Acquire a write lock without blocking.
int msp_rwlock_runlock (msp_rwlock_t *lock)
 Unlock a previously acquired read lock.
int msp_rwlock_wunlock (msp_rwlock_t *lock)
 Unlock a previously acquired write lock.


Detailed Description

Userspace read write locking functions for the MultiServices PIC SDK.

This implementation, ensures the writer priority, but does not address reader starvation. For the applications it is assumed that, the write requests are few and in between, to avoid performance penalty. The read write lock is also referred as rwlock.

The following assumptions are made about the usage:

These locks are more efficient if the memory for the lock is from OBJCACHE or SHM.

Function Documentation

int msp_rwlock_destroy msp_rwlock_t lock  ) 
 

Destroys the read write lock.

This function call is optional and this call renders the read write lock unuseable. This function should be called only when the read write lock is in unlocked state. Caller should take care that nobody uses the lock while this function is being called.

Parameters:
[in] *lock Pointer to read write lock instance.
Returns:
MSP_OK on success; otherwise, returns an error code:
  • MSP_INVALID_ARG - lock is passed as NULL.

int msp_rwlock_init msp_rwlock_t lock  ) 
 

Initializes the read write lock.

Parameters:
[in] *lock Pointer to read write lock instance.
This function has to be called before using a read write lock.
Returns:
MSP_OK on success; otherwise, returns an error code:
  • MSP_INVALID_ARG - lock is passed as NULL.

int msp_rwlock_rlock msp_rwlock_t lock  ) 
 

Acquire a read lock.

Blocks till the read lock is acquired.

Parameters:
[in] *lock Pointer to read write lock instance.
Returns:
MSP_OK on success; otherwise, returns an error code:
  • MSP_INVALID_ARG - lock is passed as NULL.

int msp_rwlock_runlock msp_rwlock_t lock  ) 
 

Unlock a previously acquired read lock.

Parameters:
[in] *lock Pointer to read write lock instance.
Returns:
MSP_OK on success; otherwise, returns an error code:
  • MSP_INVALID_ARG - lock is passed as NULL.
  • MSP_ERROR - Read lock was not acquired.

int msp_rwlock_try_rlock msp_rwlock_t lock  ) 
 

Acquire a read lock without blocking.

Parameters:
[in] *lock Pointer to read write lock instance.
Returns:
MSP_OK on success; otherwise, returns an error code:
  • MSP_EAGAIN - Failed to acquire the lock. Application can retry to acquire the lock.
  • MSP_INVALID_ARG - lock is passed as NULL.

int msp_rwlock_try_wlock msp_rwlock_t lock  ) 
 

Acquire a write lock without blocking.

Parameters:
[in] *lock Pointer to read write lock instance.
Returns:
MSP_OK on success; otherwise, returns an error code:
  • MSP_EAGAIN - Failed to acquire the lock. Application can retry to acquire the lock.
  • MSP_INVALID_ARG - lock is passed as NULL.

int msp_rwlock_wlock msp_rwlock_t lock  ) 
 

Acquire a write lock.

Blocks till the write lock is acquired.

Parameters:
[in] *lock Pointer to read write lock instance.
Returns:
MSP_OK on success; otherwise, returns an error code:
  • MSP_INVALID_ARG - lock is passed as NULL.

int msp_rwlock_wunlock msp_rwlock_t lock  ) 
 

Unlock a previously acquired write lock.

Parameters:
[in] *lock Pointer to read write lock instance.
Returns:
MSP_OK on success; otherwise, returns an error code:
  • MSP_INVALID_ARG - lock is passed as NULL.
  • MSP_ERROR - Write lock was not acquired.


2007-2009 Juniper Networks, Inc. All rights reserved. The information contained herein is confidential information of Juniper Networks, Inc., and may not be used, disclosed, distributed, modified, or copied without the prior written consent of Juniper Networks, Inc. in an express license. This information is subject to change by Juniper Networks, Inc. Juniper Networks, the Juniper Networks logo, and JUNOS are registered trademarks of Juniper Networks, Inc. in the United States and other countries. All other trademarks, service marks, registered trademarks, or registered service marks are the property of their respective owners.
Generated on Sun May 30 20:24:47 2010 for libmp-sdk by Doxygen 1.4.5