Class Private

All Implemented Interfaces:
Proxy

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

The GPrivate struct is an opaque data structure to represent a thread-local data key. It is approximately equivalent to the pthread_setspecific()/pthread_getspecific() APIs on POSIX and to TlsSetValue()/TlsGetValue() on Windows.

If you don't already know why you might want this functionality, then you probably don't need it.

GPrivate is a very limited resource (as far as 128 per program, shared between all libraries). It is also not possible to destroy a GPrivate after it has been used. As such, it is only ever acceptable to use GPrivate in static scope, and even then sparingly so.

See G_PRIVATE_INIT() for a couple of examples.

The GPrivate structure should be considered opaque. It should only be accessed via the g_private_ functions.

  • Constructor Details

    • Private

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

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

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

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

      public Private(MemorySegment p, DestroyNotify notify, MemorySegment[] future)
      Allocate a new Private with the fields set to the provided values. The memory is allocated with Arena.ofAuto().
      Parameters:
      p - value for the field p
      notify - value for the field notify
      future - value for the field future
  • 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
    • readNotify

      public @Nullable DestroyNotify readNotify()
      Read the value of the field notify.
      Returns:
      The value of the field notify
    • writeNotify

      public void writeNotify(@Nullable DestroyNotify notify, Arena _arena)
      Write a value in the field notify.
      Parameters:
      notify - The new value for the field notify
      _arena - to control the memory allocation scope
    • readFuture

      public @Nullable MemorySegment @Nullable [] readFuture()
      Read the value of the field future.
      Returns:
      The value of the field future
    • writeFuture

      public void writeFuture(@Nullable MemorySegment @Nullable [] future, Arena _arena)
      Write a value in the field future.
      Parameters:
      future - The new value for the field future
    • new_

      @Deprecated public static Private new_()
      Deprecated.
      dynamic allocation of GPrivate is a bad idea. Use static storage and G_PRIVATE_INIT() instead.
      Creates a new GPrivate.
      Returns:
      a newly allocated GPrivate (which can never be destroyed)
    • get

      public @Nullable MemorySegment get()

      Returns the current value of the thread local variable key.

      If the value has not yet been set in this thread, null is returned. Values are never copied between threads (when a new thread is created, for example).

      Returns:
      the thread-local value
    • replace

      public void replace(@Nullable MemorySegment value)

      Sets the thread local variable this Private to have the value value in the current thread.

      This function differs from g_private_set() in the following way: if the previous value was non-null then the GDestroyNotify handler for this Private is run on it.

      Parameters:
      value - the new value
      Since:
      2.32
    • set

      public void set(@Nullable MemorySegment value)

      Sets the thread local variable this Private to have the value value in the current thread.

      This function differs from g_private_replace() in the following way: the GDestroyNotify for this Private is not called on the old value.

      Parameters:
      value - the new value