gi-glib-2.0.2: GLib bindings

CopyrightWill Thompson, Iñaki García Etxebarria and Jonas Platte
LicenseLGPL-2.1
MaintainerIñaki García Etxebarria (garetxe@gmail.com)
Safe HaskellNone
LanguageHaskell2010

GI.GLib.Structs.RWLock

Contents

Description

The GRWLock struct is an opaque data structure to represent a reader-writer lock. It is similar to a #GMutex in that it allows multiple threads to coordinate access to a shared resource.

The difference to a mutex is that a reader-writer lock discriminates between read-only (reader) and full (writer) access. While only one thread at a time is allowed write access (by holding the writer lock via g_rw_lock_writer_lock()), multiple threads can gain simultaneous read-only access (by holding the reader lock via g_rw_lock_reader_lock()).

Here is an example for an array with access functions: |[language="C" -- GRWLock lock; GPtrArray *array;

gpointer my_array_get (guint index) { gpointer retval = NULL;

if (!array) return NULL;

g_rw_lock_reader_lock (&lock); if (index array-len) retval = g_ptr_array_index (array, index); g_rw_lock_reader_unlock (&lock);

return retval; }

void my_array_set (guint index, gpointer data) { g_rw_lock_writer_lock (&lock);

if (!array) array = g_ptr_array_new ();

if (index >= array->len) g_ptr_array_set_size (array, index+1); g_ptr_array_index (array, index) = data;

g_rw_lock_writer_unlock (&lock); } ]| This example shows an array which can be accessed by many readers (the my_array_get() function) simultaneously, whereas the writers (the my_array_set() function) will only be allowed one at a time and only if no readers currently access the array. This is because of the potentially dangerous resizing of the array. Using these functions is fully multi-thread safe now.

If a #GRWLock is allocated in static storage then it can be used without initialisation. Otherwise, you should call g_rw_lock_init() on it and g_rw_lock_clear() when done.

A GRWLock should only be accessed with the g_rw_lock_ functions.

Synopsis

Exported types

newtype RWLock Source #

Constructors

RWLock (ForeignPtr RWLock) 

Instances

WrappedPtr RWLock Source # 

Methods

wrappedPtrCalloc :: IO (Ptr RWLock)

wrappedPtrCopy :: Ptr RWLock -> IO (Ptr RWLock)

wrappedPtrFree :: Maybe (FunPtr (Ptr RWLock -> IO ()))

(~) AttrOpTag tag AttrSet => Constructible RWLock tag Source # 

Methods

new :: MonadIO m => (ForeignPtr RWLock -> RWLock) -> [AttrOp RWLock tag] -> m RWLock

((~) * info (ResolveRWLockMethod t RWLock), MethodInfo * info RWLock p) => IsLabel t (RWLock -> p) Source # 

Methods

fromLabel :: Proxy# Symbol t -> RWLock -> p

((~) * info (ResolveRWLockMethod t RWLock), MethodInfo * info RWLock p) => IsLabelProxy t (RWLock -> p) Source # 

Methods

fromLabelProxy :: Proxy Symbol t -> RWLock -> p

((~) * signature (m ()), MonadIO m) => MethodInfo * RWLockWriterUnlockMethodInfo RWLock signature Source # 

Methods

overloadedMethod :: MethodProxy RWLockWriterUnlockMethodInfo RWLock -> signature -> s

((~) * signature (m Bool), MonadIO m) => MethodInfo * RWLockWriterTrylockMethodInfo RWLock signature Source # 

Methods

overloadedMethod :: MethodProxy RWLockWriterTrylockMethodInfo RWLock -> signature -> s

((~) * signature (m ()), MonadIO m) => MethodInfo * RWLockWriterLockMethodInfo RWLock signature Source # 

Methods

overloadedMethod :: MethodProxy RWLockWriterLockMethodInfo RWLock -> signature -> s

((~) * signature (m ()), MonadIO m) => MethodInfo * RWLockReaderUnlockMethodInfo RWLock signature Source # 

Methods

overloadedMethod :: MethodProxy RWLockReaderUnlockMethodInfo RWLock -> signature -> s

((~) * signature (m Bool), MonadIO m) => MethodInfo * RWLockReaderTrylockMethodInfo RWLock signature Source # 

Methods

overloadedMethod :: MethodProxy RWLockReaderTrylockMethodInfo RWLock -> signature -> s

((~) * signature (m ()), MonadIO m) => MethodInfo * RWLockReaderLockMethodInfo RWLock signature Source # 

Methods

overloadedMethod :: MethodProxy RWLockReaderLockMethodInfo RWLock -> signature -> s

((~) * signature (m ()), MonadIO m) => MethodInfo * RWLockInitMethodInfo RWLock signature Source # 

Methods

overloadedMethod :: MethodProxy RWLockInitMethodInfo RWLock -> signature -> s

((~) * signature (m ()), MonadIO m) => MethodInfo * RWLockClearMethodInfo RWLock signature Source # 

Methods

overloadedMethod :: MethodProxy RWLockClearMethodInfo RWLock -> signature -> s

type AttributeList RWLock Source # 
type AttributeList RWLock

newZeroRWLock :: MonadIO m => m RWLock Source #

Construct a RWLock struct initialized to zero.

Methods

rWLockClear

data RWLockClearMethodInfo Source #

Instances

((~) * signature (m ()), MonadIO m) => MethodInfo * RWLockClearMethodInfo RWLock signature Source # 

Methods

overloadedMethod :: MethodProxy RWLockClearMethodInfo RWLock -> signature -> s

rWLockClear :: MonadIO m => RWLock -> m () Source #

rWLockInit

data RWLockInitMethodInfo Source #

Instances

((~) * signature (m ()), MonadIO m) => MethodInfo * RWLockInitMethodInfo RWLock signature Source # 

Methods

overloadedMethod :: MethodProxy RWLockInitMethodInfo RWLock -> signature -> s

rWLockInit :: MonadIO m => RWLock -> m () Source #

rWLockReaderLock

data RWLockReaderLockMethodInfo Source #

Instances

((~) * signature (m ()), MonadIO m) => MethodInfo * RWLockReaderLockMethodInfo RWLock signature Source # 

Methods

overloadedMethod :: MethodProxy RWLockReaderLockMethodInfo RWLock -> signature -> s

rWLockReaderLock :: MonadIO m => RWLock -> m () Source #

rWLockReaderTrylock

data RWLockReaderTrylockMethodInfo Source #

Instances

((~) * signature (m Bool), MonadIO m) => MethodInfo * RWLockReaderTrylockMethodInfo RWLock signature Source # 

Methods

overloadedMethod :: MethodProxy RWLockReaderTrylockMethodInfo RWLock -> signature -> s

rWLockReaderTrylock :: MonadIO m => RWLock -> m Bool Source #

rWLockReaderUnlock

data RWLockReaderUnlockMethodInfo Source #

Instances

((~) * signature (m ()), MonadIO m) => MethodInfo * RWLockReaderUnlockMethodInfo RWLock signature Source # 

Methods

overloadedMethod :: MethodProxy RWLockReaderUnlockMethodInfo RWLock -> signature -> s

rWLockReaderUnlock :: MonadIO m => RWLock -> m () Source #

rWLockWriterLock

data RWLockWriterLockMethodInfo Source #

Instances

((~) * signature (m ()), MonadIO m) => MethodInfo * RWLockWriterLockMethodInfo RWLock signature Source # 

Methods

overloadedMethod :: MethodProxy RWLockWriterLockMethodInfo RWLock -> signature -> s

rWLockWriterLock :: MonadIO m => RWLock -> m () Source #

rWLockWriterTrylock

data RWLockWriterTrylockMethodInfo Source #

Instances

((~) * signature (m Bool), MonadIO m) => MethodInfo * RWLockWriterTrylockMethodInfo RWLock signature Source # 

Methods

overloadedMethod :: MethodProxy RWLockWriterTrylockMethodInfo RWLock -> signature -> s

rWLockWriterTrylock :: MonadIO m => RWLock -> m Bool Source #

rWLockWriterUnlock

data RWLockWriterUnlockMethodInfo Source #

Instances

((~) * signature (m ()), MonadIO m) => MethodInfo * RWLockWriterUnlockMethodInfo RWLock signature Source # 

Methods

overloadedMethod :: MethodProxy RWLockWriterUnlockMethodInfo RWLock -> signature -> s

rWLockWriterUnlock :: MonadIO m => RWLock -> m () Source #