lib/rwlock.h File Reference


Detailed Description

Read/write locks, header.

Definition in file rwlock.h.

#include "lib/sectionlock.h"
#include "lib/lockerror.h"
#include <pthread.h>
#include <time.h>
#include <nobug.h>

Include dependency graph for rwlock.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  lumiera_rwlock_struct
 RWLock. More...

Defines

#define LUMIERA_RDLOCK_SECTION(nobugflag, rwlck)
 Read locked section.
#define LUMIERA_RDLOCK_SECTION_CHAIN(nobugflag, rwlck)
#define LUMIERA_RWLOCK_SECTION_UNLOCK   LUMIERA_SECTION_UNLOCK_(&lumiera_lock_section_)
#define LUMIERA_WRLOCK_SECTION(nobugflag, rwlck)
 Write locked section.
#define LUMIERA_WRLOCK_SECTION_CHAIN(nobugflag, rwlck)

Typedefs

typedef struct
lumiera_rwlock_struct 
lumiera_rwlock
typedef lumiera_rwlockLumieraRWLock

Functions

LumieraRWLock lumiera_rwlock_destroy (LumieraRWLock self, struct nobug_flag *flag, const struct nobug_context ctx)
 destroy a rwlock
LumieraRWLock lumiera_rwlock_init (LumieraRWLock self, const char *purpose, struct nobug_flag *flag, const struct nobug_context ctx)
 Initialize a rwlock.
static LumieraRWLock lumiera_rwlock_rdlock (LumieraRWLock self, struct nobug_flag *flag, struct nobug_resource_user **handle, const struct nobug_context ctx)
static LumieraRWLock lumiera_rwlock_timedrdlock (LumieraRWLock self, const struct timespec *timeout, struct nobug_flag *flag, struct nobug_resource_user **handle, const struct nobug_context ctx)
static LumieraRWLock lumiera_rwlock_timedwrlock (LumieraRWLock self, const struct timespec *timeout, struct nobug_flag *flag, struct nobug_resource_user **handle, const struct nobug_context ctx)
static LumieraRWLock lumiera_rwlock_tryrdlock (LumieraRWLock self, struct nobug_flag *flag, struct nobug_resource_user **handle, const struct nobug_context ctx)
static LumieraRWLock lumiera_rwlock_trywrlock (LumieraRWLock self, struct nobug_flag *flag, struct nobug_resource_user **handle, const struct nobug_context ctx)
static void lumiera_rwlock_unlock (LumieraRWLock self, struct nobug_flag *flag, struct nobug_resource_user **handle, const struct nobug_context ctx)
static LumieraRWLock lumiera_rwlock_wrlock (LumieraRWLock self, struct nobug_flag *flag, struct nobug_resource_user **handle, const struct nobug_context ctx)


Define Documentation

#define LUMIERA_RDLOCK_SECTION ( nobugflag,
rwlck   ) 

Value:

for (lumiera_sectionlock NOBUG_CLEANUP(lumiera_sectionlock_ensureunlocked)    \
         lumiera_lock_section_ = {                                              \
         rwlck, (lumiera_sectionlock_unlock_fn) lumiera_rwlock_unlock           \
           NOBUG_ALPHA_COMMA(&NOBUG_FLAG(nobugflag)) NOBUG_ALPHA_COMMA_NULL};   \
       ({                                                                       \
         if (lumiera_lock_section_.lock)                                        \
           lumiera_lock_section_.lock =                                         \
             lumiera_rwlock_rdlock (rwlck, &NOBUG_FLAG(nobugflag),              \
                                    &lumiera_lock_section_.rh, NOBUG_CONTEXT);  \
         lumiera_lock_section_.lock;                                            \
       });                                                                      \
       ({                                                                       \
         LUMIERA_RWLOCK_SECTION_UNLOCK;                                         \
       }))
Read locked section.

readlocks may fail when there are too much readers, one has to check the error afterwards!

Definition at line 47 of file rwlock.h.

#define LUMIERA_RDLOCK_SECTION_CHAIN ( nobugflag,
rwlck   ) 

Value:

for (lumiera_sectionlock *lumiera_lock_section_old_ = &lumiera_lock_section_,         \
         NOBUG_CLEANUP(lumiera_sectionlock_ensureunlocked) lumiera_lock_section_ = {    \
         rwlck, (lumiera_sectionlock_unlock_fn) lumiera_rwlock_unlock                   \
           NOBUG_ALPHA_COMMA(&NOBUG_FLAG(nobugflag)) NOBUG_ALPHA_COMMA_NULL};           \
       ({                                                                               \
         if (lumiera_lock_section_.lock)                                                \
           {                                                                            \
             REQUIRE (lumiera_lock_section_old_->lock, "section prematurely unlocked"); \
             lumiera_lock_section_.lock =                                               \
               lumiera_rwlock_rdlock (rwlck, &NOBUG_FLAG(nobugflag),                    \
                                      lumiera_lock_section_.rh, NOBUG_CONTEXT);         \
             LUMIERA_SECTION_UNLOCK_(lumiera_lock_section_old_);                        \
           }                                                                            \
         lumiera_lock_section_.lock;                                                    \
       });                                                                              \
       ({                                                                               \
         LUMIERA_RWLOCK_SECTION_UNLOCK;                                                 \
       }))

Definition at line 64 of file rwlock.h.

#define LUMIERA_WRLOCK_SECTION ( nobugflag,
rwlck   ) 

Value:

for (lumiera_sectionlock NOBUG_CLEANUP(lumiera_sectionlock_ensureunlocked)    \
         lumiera_lock_section_ = {                                              \
         rwlck, (lumiera_sectionlock_unlock_fn) lumiera_rwlock_unlock           \
           NOBUG_ALPHA_COMMA(&NOBUG_FLAG(nobugflag)) NOBUG_ALPHA_COMMA_NULL};   \
       ({                                                                       \
         if (lumiera_lock_section_.lock)                                        \
           lumiera_lock_section_.lock =                                         \
             lumiera_rwlock_wrlock (rwlck, &NOBUG_FLAG(nobugflag),              \
                                    &lumiera_lock_section_.rh, NOBUG_CONTEXT);  \
         lumiera_lock_section_.lock;                                            \
       });                                                                      \
       ({                                                                       \
         LUMIERA_RWLOCK_SECTION_UNLOCK;                                         \
       }))
Write locked section.

Definition at line 89 of file rwlock.h.

#define LUMIERA_WRLOCK_SECTION_CHAIN ( nobugflag,
rwlck   ) 

Value:

for (lumiera_sectionlock *lumiera_lock_section_old_ = &lumiera_lock_section_,         \
         NOBUG_CLEANUP(lumiera_sectionlock_ensureunlocked) lumiera_lock_section_ = {    \
         rwlck, (lumiera_sectionlock_unlock_fn) lumiera_rwlock_unlock                   \
           NOBUG_ALPHA_COMMA(&NOBUG_FLAG(nobugflag)) NOBUG_ALPHA_COMMA_NULL};           \
       ({                                                                               \
         if (lumiera_lock_section_.lock)                                                \
           {                                                                            \
             REQUIRE (lumiera_lock_section_old_->lock, "section prematurely unlocked"); \
             lumiera_lock_section_.lock =                                               \
               lumiera_rwlock_wrlock (rwlck, &NOBUG_FLAG(nobugflag),                    \
                                      lumiera_lock_section_.rh, NOBUG_CONTEXT);         \
             LUMIERA_SECTION_UNLOCK_(lumiera_lock_section_old_);                        \
           }                                                                            \
         lumiera_lock_section_.lock;                                                    \
       });                                                                              \
       ({                                                                               \
         LUMIERA_RWLOCK_SECTION_UNLOCK;                                                 \
       }))

Definition at line 106 of file rwlock.h.


Function Documentation

LumieraRWLock lumiera_rwlock_init ( LumieraRWLock  self,
const char *  purpose,
struct nobug_flag *  flag,
const struct nobug_context  ctx 
)

Initialize a rwlock.

Parameters:
self is a pointer to the rwlock to be initialized
Returns:
self as given

Definition at line 32 of file rwlock.c.

Referenced by lumiera_filedescriptor_new().

Here is the caller graph for this function:

LumieraRWLock lumiera_rwlock_destroy ( LumieraRWLock  self,
struct nobug_flag *  flag,
const struct nobug_context  ctx 
)

destroy a rwlock

Parameters:
self is a pointer to the rwlock to be initialized
Returns:
self on success or NULL at error

Definition at line 50 of file rwlock.c.

References LUMIERA_DIE.

Referenced by lumiera_filedescriptor_delete().

Here is the caller graph for this function:


Generated on Sun Aug 1 21:31:31 2010 for Lumiera by  doxygen 1.5.6