rwlock.c File Reference

Functions for using synchronization primitive called R/W lock. More...

#include "rwlock.h"
#include "malloc.h"
#include "int.h"
#include "debug.h"
#include "timers.h"
#include "thread.h"
#include "errnums.h"

Functions

void rwlock_init (rwlock_t *rwl)
void rwlock_destroy (rwlock_t *rwl)
 Destroy r/w lock.
void rwlock_read_lock (rwlock_t *rwl)
 Lock the r/w lock for reading.
void rwlock_write_lock (rwlock_t *rwl)
 Lock the r/w lock for writing.
int rwlock_read_lock_try (rwlock_t *rwl)
 Non block read lock.
int rwlock_write_lock_try (rwlock_t *rwl)
 Non block write lock.
int rwlock_read_timeout (rwlock_t *rwl, const unsigned int usec)
 Read lock with timeout.
int rwlock_write_timeout (rwlock_t *rwl, const unsigned int usec)
 Write lock with timeout.
void rwlock_read_unlock (rwlock_t *rwl)
 Release r/w lock locked for reading.
void rwlock_write_unlock (rwlock_t *rwl)
 Release r/w lock locked for writing.


Detailed Description

Functions for using synchronization primitive called R/W lock.

Functions for initialize, destroy, lock for writing or reading and timeout lock. R/w lock can be locked by multiple readers at a time and only one writer at a time. Writers has higher priority, it means that if there are waiting readers and waiting writers the first waiting writer will be woken up and readers will stay suspended. Writing thread can locked the lock recursively and the lock will be free after the count of callings unlock will be same as count of callings lock or lock timeout. This implementation does not test wheter the unlocking thread has the r/w lock locked!


Function Documentation

void rwlock_destroy ( rwlock_t *  rwl  ) 

Destroy r/w lock.

Parameters:
rwl - r/w lock structure
This only check if there are any waiting threads in both queues, and if it is call panic.

void rwlock_init ( rwlock_t *  rwl  ) 

Parameters:
rwl - r/w lock structure
Function initialize r/w lock structure to state open. Set pointers to waiting threads to NULL and count of writing and reading threads to 0

void rwlock_read_lock ( rwlock_t *  rwl  ) 

Lock the r/w lock for reading.

Parameters:
rwl - r/w lock structure
Function try to lock r/w lock for reading, if there is writing thread, current thread is suspended on this lock.

int rwlock_read_lock_try ( rwlock_t *  rwl  ) 

Non block read lock.

Parameters:
rwl - r/w lock structure
Returns:
EOK if success and ETIMEDOUT otherwise
Function try to lock the r/w lock for reading, but not suspend on this lock. Return EOK if the lock was succesfully locked for reading and ETIMEDOUT if there is writing thread on the lock

int rwlock_read_timeout ( rwlock_t *  rwl,
const unsigned int  usec 
)

Read lock with timeout.

Parameters:
rwl - r/w lock structure
usec - count of microseconds
Returns:
EOK if success and ETIMEDOUT otherwise
Trying to lock r/w lock for reading only for usec microseconds. Return EOK if the lock was succesfully locked for reading and return ETIMEDOUT if usec microseconds run out.

void rwlock_read_unlock ( rwlock_t *  rwl  ) 

Release r/w lock locked for reading.

Parameters:
rwl - r/w lock structure
Less the count of reading threads and if the count is 0, release the lock and wake up threads suspended on this lock

void rwlock_write_lock ( rwlock_t *  rwl  ) 

Lock the r/w lock for writing.

Parameters:
rwl - r/w lock structure
Function try to lock r/w lock for writing, if there is writing or reading thread, current thread is suspended on this lock. If the current thread is same as actual thread it is recursion call of lock function and only count of writing threads is raised.

int rwlock_write_lock_try ( rwlock_t *  rwl  ) 

Non block write lock.

Parameters:
rwl - r/w lock structure
Returns:
EOK if success and ETIMEDOUT otherwise
Function try to lock the r/w lock for writing, but not suspend on this lock. Return EOK if the lock was succesfully locked for writing and ETIMEDOUT if there is writing or reading thread on the lock

int rwlock_write_timeout ( rwlock_t *  rwl,
const unsigned int  usec 
)

Write lock with timeout.

Parameters:
rwl - r/w lock structure
usec - count of microseconds
Returns:
EOK if success and ETIMEDOUT otherwise
Trying to lock r/w lock for writing only for usec microseconds. Return EOK if the lock was succesfully locked for writing and return ETIMEDOUT if usec microseconds run out.

void rwlock_write_unlock ( rwlock_t *  rwl  ) 

Release r/w lock locked for writing.

Parameters:
rwl - r/w lock structure
Less the count of writing recursion and if the count is 0, release the lock and wake up threads suspended on this lock


Generated on Wed Nov 15 17:25:44 2006 for Kalisto by  doxygen 1.4.7