Class RecMutex

All Implemented Interfaces:
Proxy

@Generated("org.javagi.JavaGI") public class RecMutex extends ProxyInstance

The GRecMutex struct is an opaque data structure to represent a recursive mutex. It is similar to a GMutex with the difference that it is possible to lock a GRecMutex multiple times in the same thread without deadlock. When doing so, care has to be taken to unlock the recursive mutex as often as it has been locked.

If a GRecMutex is allocated in static storage then it can be used without initialisation. Otherwise, you should call g_rec_mutex_init() on it and g_rec_mutex_clear() when done.

A GRecMutex should only be accessed with the g_rec_mutex_ functions.

Since:
2.32
  • Constructor Summary

    Constructors
    Constructor
    Description
    Allocate a new RecMutex.
    RecMutex(Arena arena)
    Allocate a new RecMutex.
    Create a RecMutex proxy instance for the provided memory address.
    RecMutex(MemorySegment p, int[] i)
    Allocate a new RecMutex with the fields set to the provided values.
    RecMutex(MemorySegment p, int[] i, Arena arena)
    Allocate a new RecMutex with the fields set to the provided values.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Frees the resources allocated to a recursive mutex with g_rec_mutex_init().
    The memory layout of the native struct.
    void
    Initializes a GRecMutex so that it can be used.
    void
    Locks recMutex. If this RecMutex is already locked by another thread, the current thread will block until this RecMutex is unlocked by the other thread.
    @Nullable int @Nullable []
    Read the value of the field i.
    Read the value of the field p.
    boolean
    Tries to lock recMutex. If this RecMutex is already locked by another thread, it immediately returns false.
    void
    Unlocks recMutex. If another thread is blocked in a g_rec_mutex_lock() call for recMutex, it will become unblocked and can lock this RecMutex itself.
    void
    writeI(@Nullable int @Nullable [] i, Arena _arena)
    Write a value in the field i.
    void
    Write a value in the field p.

    Methods inherited from class ProxyInstance

    equals, handle, hashCode

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • RecMutex

      public RecMutex(MemorySegment address)
      Create a RecMutex proxy instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • RecMutex

      public RecMutex(Arena arena)
      Allocate a new RecMutex.
      Parameters:
      arena - to control the memory allocation scope
    • RecMutex

      public RecMutex()
      Allocate a new RecMutex. The memory is allocated with Arena.ofAuto().
    • RecMutex

      public RecMutex(MemorySegment p, int[] i, Arena arena)
      Allocate a new RecMutex with the fields set to the provided values.
      Parameters:
      p - value for the field p
      i - value for the field i
      arena - to control the memory allocation scope
    • RecMutex

      public RecMutex(MemorySegment p, int[] i)
      Allocate a new RecMutex with the fields set to the provided values. The memory is allocated with Arena.ofAuto().
      Parameters:
      p - value for the field p
      i - value for the field i
  • Method Details

    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • readP

      public MemorySegment readP()
      Read the value of the field p.
      Returns:
      The value of the field p
    • writeP

      public void writeP(MemorySegment p)
      Write a value in the field p.
      Parameters:
      p - The new value for the field p
    • readI

      public @Nullable int @Nullable [] readI()
      Read the value of the field i.
      Returns:
      The value of the field i
    • writeI

      public void writeI(@Nullable int @Nullable [] i, Arena _arena)
      Write a value in the field i.
      Parameters:
      i - The new value for the field i
    • clear

      public void clear()

      Frees the resources allocated to a recursive mutex with g_rec_mutex_init().

      This function should not be used with a GRecMutex that has been statically allocated.

      Calling g_rec_mutex_clear() on a locked recursive mutex leads to undefined behaviour.

      Since:
      2.32
    • init

      public void init()

      Initializes a GRecMutex so that it can be used.

      This function is useful to initialize a recursive mutex that has been allocated on the stack, or as part of a larger structure.

      It is not necessary to initialise a recursive mutex that has been statically allocated.

        typedef struct {
          GRecMutex m;
          ...
        } Blob;
      
      Blob *b;
      
      b = g_new (Blob, 1);
      g_rec_mutex_init (&b->m);
      

      Calling g_rec_mutex_init() on an already initialized GRecMutex leads to undefined behaviour.

      To undo the effect of g_rec_mutex_init() when a recursive mutex is no longer needed, use g_rec_mutex_clear().

      Since:
      2.32
    • lock

      public void lock()
      Locks recMutex. If this RecMutex is already locked by another thread, the current thread will block until this RecMutex is unlocked by the other thread. If this RecMutex is already locked by the current thread, the 'lock count' of this RecMutex is increased. The mutex will only become available again when it is unlocked as many times as it has been locked.
      Since:
      2.32
    • trylock

      public boolean trylock()
      Tries to lock recMutex. If this RecMutex is already locked by another thread, it immediately returns false. Otherwise it locks this RecMutex and returns true.
      Returns:
      true if this RecMutex could be locked
      Since:
      2.32
    • unlock

      public void unlock()

      Unlocks recMutex. If another thread is blocked in a g_rec_mutex_lock() call for recMutex, it will become unblocked and can lock this RecMutex itself.

      Calling g_rec_mutex_unlock() on a recursive mutex that is not locked by the current thread leads to undefined behaviour.

      Since:
      2.32