:right-sidebar: True RWLock =================================================================== .. currentmodule:: gi.repository.GLib .. versionadded:: 2.32 .. class:: RWLock(*args, **kwargs) :no-contents-entry: :Constructors: :: RWLock() Methods ------- .. rst-class:: interim-class .. class:: RWLock :no-index: .. method:: clear() -> None Frees the resources allocated to a lock with :func:`~gi.repository.GLib.RWLock.init`. This function should not be used with a :obj:`~gi.repository.GLib.RWLock` that has been statically allocated. Calling :func:`~gi.repository.GLib.RWLock.clear` when any thread holds the lock leads to undefined behaviour. .. versionadded:: 2.32 .. method:: init() -> None Initializes a :obj:`~gi.repository.GLib.RWLock` so that it can be used. This function is useful to initialize a lock that has been allocated on the stack, or as part of a larger structure. It is not necessary to initialise a reader-writer lock that has been statically allocated. .. code-block:: C :dedent: typedef struct { GRWLock l; ... } Blob; Blob *b; b = g_new (Blob, 1); g_rw_lock_init (&b->l); To undo the effect of :func:`~gi.repository.GLib.RWLock.init` when a lock is no longer needed, use :func:`~gi.repository.GLib.RWLock.clear`. Calling :func:`~gi.repository.GLib.RWLock.init` on an already initialized :obj:`~gi.repository.GLib.RWLock` leads to undefined behaviour. .. versionadded:: 2.32 .. method:: reader_lock() -> None Obtain a read lock on ``rw_lock``. If another thread currently holds the write lock on ``rw_lock``, the current thread will block until the write lock was (held and) released. If another thread does not hold the write lock, but is waiting for it, it is implementation defined whether the reader or writer will block. Read locks can be taken recursively. Calling :func:`~gi.repository.GLib.RWLock.reader_lock` while the current thread already owns a write lock leads to undefined behaviour. Read locks however can be taken recursively, in which case you need to make sure to call :func:`~gi.repository.GLib.RWLock.reader_unlock` the same amount of times. It is implementation-defined how many read locks are allowed to be held on the same lock simultaneously. If the limit is hit, or if a deadlock is detected, a critical warning will be emitted. .. versionadded:: 2.32 .. method:: reader_trylock() -> bool Tries to obtain a read lock on ``rw_lock`` and returns :const:`True` if the read lock was successfully obtained. Otherwise it returns :const:`False`. .. versionadded:: 2.32 .. method:: reader_unlock() -> None Release a read lock on ``rw_lock``. Calling :func:`~gi.repository.GLib.RWLock.reader_unlock` on a lock that is not held by the current thread leads to undefined behaviour. .. versionadded:: 2.32 .. method:: writer_lock() -> None Obtain a write lock on ``rw_lock``. If another thread currently holds a read or write lock on ``rw_lock``, the current thread will block until all other threads have dropped their locks on ``rw_lock``. Calling :func:`~gi.repository.GLib.RWLock.writer_lock` while the current thread already owns a read or write lock on ``rw_lock`` leads to undefined behaviour. .. versionadded:: 2.32 .. method:: writer_trylock() -> bool Tries to obtain a write lock on ``rw_lock``. If another thread currently holds a read or write lock on ``rw_lock``, it immediately returns :const:`False`. Otherwise it locks ``rw_lock`` and returns :const:`True`. .. versionadded:: 2.32 .. method:: writer_unlock() -> None Release a write lock on ``rw_lock``. Calling :func:`~gi.repository.GLib.RWLock.writer_unlock` on a lock that is not held by the current thread leads to undefined behaviour. .. versionadded:: 2.32 Fields ------ .. rst-class:: interim-class .. class:: RWLock :no-index: .. attribute:: i .. attribute:: p