Class Private
- All Implemented Interfaces:
Proxy
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 Summary
ConstructorsConstructorDescriptionPrivate()Allocate a new Private.Allocate a new Private.Private(MemorySegment address) Create a Private proxy instance for the provided memory address.Private(MemorySegment p, DestroyNotify notify, MemorySegment[] future) Allocate a new Private with the fields set to the provided values.Private(MemorySegment p, DestroyNotify notify, MemorySegment[] future, Arena arena) Allocate a new Private with the fields set to the provided values. -
Method Summary
Modifier and TypeMethodDescription@Nullable MemorySegmentget()Returns the current value of the thread local variablekey.static MemoryLayoutThe memory layout of the native struct.static Privatenew_()Deprecated.@Nullable MemorySegment @Nullable []Read the value of the fieldfuture.@Nullable DestroyNotifyRead the value of the fieldnotify.readP()Read the value of the fieldp.voidreplace(@Nullable MemorySegment value) Sets the thread local variable this Private to have the valuevaluein the current thread.voidset(@Nullable MemorySegment value) Sets the thread local variable this Private to have the valuevaluein the current thread.voidwriteFuture(@Nullable MemorySegment @Nullable [] future, Arena _arena) Write a value in the fieldfuture.voidwriteNotify(@Nullable DestroyNotify notify, Arena _arena) Write a value in the fieldnotify.voidWrite a value in the fieldp.Methods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
Private
Create a Private proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
Private
Allocate a new Private.- Parameters:
arena- to control the memory allocation scope
-
Private
public Private()Allocate a new Private. The memory is allocated withArena.ofAuto(). -
Private
Allocate a new Private with the fields set to the provided values.- Parameters:
p- value for the fieldpnotify- value for the fieldnotifyfuture- value for the fieldfuturearena- to control the memory allocation scope
-
Private
Allocate a new Private with the fields set to the provided values. The memory is allocated withArena.ofAuto().- Parameters:
p- value for the fieldpnotify- value for the fieldnotifyfuture- value for the fieldfuture
-
-
Method Details
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
readP
-
writeP
Write a value in the fieldp.- Parameters:
p- The new value for the fieldp
-
readNotify
Read the value of the fieldnotify.- Returns:
- The value of the field
notify
-
writeNotify
Write a value in the fieldnotify.- Parameters:
notify- The new value for the fieldnotify_arena- to control the memory allocation scope
-
readFuture
Read the value of the fieldfuture.- Returns:
- The value of the field
future
-
writeFuture
Write a value in the fieldfuture.- Parameters:
future- The new value for the fieldfuture
-
new_
Deprecated.dynamic allocation ofGPrivateis a bad idea. Use static storage and G_PRIVATE_INIT() instead.Creates a newGPrivate.- Returns:
- a newly allocated
GPrivate(which can never be destroyed)
-
get
Returns the current value of the thread local variablekey.If the value has not yet been set in this thread,
nullis returned. Values are never copied between threads (when a new thread is created, for example).- Returns:
- the thread-local value
-
replace
Sets the thread local variable this Private to have the valuevaluein the current thread.This function differs from g_private_set() in the following way: if the previous value was non-
nullthen theGDestroyNotifyhandler for this Private is run on it.- Parameters:
value- the new value- Since:
- 2.32
-
set
Sets the thread local variable this Private to have the valuevaluein the current thread.This function differs from g_private_replace() in the following way: the
GDestroyNotifyfor this Private is not called on the old value.- Parameters:
value- the new value
-
GPrivateis a bad idea.