Class StaticRecMutex

java.lang.Object
org.javagi.base.ProxyInstance
org.gnome.glib.StaticRecMutex
All Implemented Interfaces:
Proxy

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

A GStaticRecMutex works like a GStaticMutex, but it can be locked multiple times by one thread. If you enter it n times, you have to unlock it n times again to let other threads lock it. An exception is the function g_static_rec_mutex_unlock_full(): that allows you to unlock a GStaticRecMutex completely returning the depth, (i.e. the number of times this mutex was locked). The depth can later be used to restore the state of the GStaticRecMutex by calling g_static_rec_mutex_lock_full(). In GLib 2.32, GStaticRecMutex has been deprecated in favor of GRecMutex.

Even though GStaticRecMutex is not opaque, it should only be used with the following functions.

All of the g_static_rec_mutex_* functions can be used even if g_thread_init() has not been called. Then they do nothing, apart from g_static_rec_mutex_trylock(), which does nothing but returning true.

  • Constructor Details

    • StaticRecMutex

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

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

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

      public StaticRecMutex(StaticMutex mutex, int depth, Arena arena)
      Allocate a new StaticRecMutex with the fields set to the provided values.
      Parameters:
      mutex - value for the field mutex
      depth - value for the field depth
      arena - to control the memory allocation scope
    • StaticRecMutex

      public StaticRecMutex(StaticMutex mutex, int depth)
      Allocate a new StaticRecMutex with the fields set to the provided values. The memory is allocated with Arena.ofAuto().
      Parameters:
      mutex - value for the field mutex
      depth - value for the field depth
  • Method Details

    • getMemoryLayout

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

      public @Nullable StaticMutex readMutex()
      Read the value of the field mutex.
      Returns:
      The value of the field mutex
    • writeMutex

      public void writeMutex(@Nullable StaticMutex mutex)
      Write a value in the field mutex.
      Parameters:
      mutex - The new value for the field mutex
    • readDepth

      public int readDepth()
      Read the value of the field depth.
      Returns:
      The value of the field depth
    • writeDepth

      public void writeDepth(int depth)
      Write a value in the field depth.
      Parameters:
      depth - The new value for the field depth
    • free

      @Deprecated public void free()
      Deprecated.
      Use g_rec_mutex_clear()

      Releases all resources allocated to a GStaticRecMutex.

      You don't have to call this functions for a GStaticRecMutex with an unbounded lifetime, i.e. objects declared 'static', but if you have a GStaticRecMutex as a member of a structure and the structure is freed, you should also free the GStaticRecMutex.

    • init

      @Deprecated public void init()
      Deprecated.
      Use g_rec_mutex_init()
      A GStaticRecMutex must be initialized with this function before it can be used. Alternatively you can initialize it with G_STATIC_REC_MUTEX_INIT.
    • lock

      @Deprecated public void lock()
      Deprecated.
      Use g_rec_mutex_lock()
      Locks mutex. If this StaticRecMutex is already locked by another thread, the current thread will block until this StaticRecMutex is unlocked by the other thread. If this StaticRecMutex is already locked by the calling thread, this functions increases the depth of this StaticRecMutex and returns immediately.
    • lockFull

      @Deprecated public void lockFull(int depth)
      Deprecated.
      Use g_rec_mutex_lock()
      Works like calling g_static_rec_mutex_lock() for this StaticRecMutex depth times.
      Parameters:
      depth - number of times this mutex has to be unlocked to be completely unlocked.
    • trylock

      @Deprecated public boolean trylock()
      Deprecated.
      Use g_rec_mutex_trylock()
      Tries to lock mutex. If this StaticRecMutex is already locked by another thread, it immediately returns false. Otherwise it locks this StaticRecMutex and returns true. If this StaticRecMutex is already locked by the calling thread, this functions increases the depth of this StaticRecMutex and immediately returns true.
      Returns:
      true, if this StaticRecMutex could be locked.
    • unlock

      @Deprecated public void unlock()
      Deprecated.
      Use g_rec_mutex_unlock()
      Unlocks mutex. Another thread will be allowed to lock this StaticRecMutex only when it has been unlocked as many times as it had been locked before. If this StaticRecMutex is completely unlocked and another thread is blocked in a g_static_rec_mutex_lock() call for mutex, it will be woken and can lock this StaticRecMutex itself.
    • unlockFull

      @Deprecated public int unlockFull()
      Deprecated.
      Use g_rec_mutex_unlock()
      Completely unlocks mutex. If another thread is blocked in a g_static_rec_mutex_lock() call for mutex, it will be woken and can lock this StaticRecMutex itself. This function returns the number of times that this StaticRecMutex has been locked by the current thread. To restore the state before the call to g_static_rec_mutex_unlock_full() you can call g_static_rec_mutex_lock_full() with the depth returned by this function.
      Returns:
      number of times this StaticRecMutex has been locked by the current thread.