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
ConstructorDescriptionPrivate()
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 TypeMethodDescriptionget()
Returns the current value of the thread local variable this Private.static MemoryLayout
The memory layout of the native struct.static Private
new_()
Deprecated.Read the value of the fieldfuture
.Read the value of the fieldnotify
.readP()
Read the value of the fieldp
.void
replace
(@Nullable MemorySegment value) Sets the thread local variable this Private to have the valuevalue
in the current thread.void
set
(@Nullable MemorySegment value) Sets the thread local variable this Private to have the valuevalue
in the current thread.void
writeFuture
(MemorySegment[] future, Arena _arena) Write a value in the fieldfuture
.void
writeNotify
(DestroyNotify notify, Arena _arena) Write a value in the fieldnotify
.void
Write a value in the fieldp
.Methods inherited from class io.github.jwharm.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 fieldp
notify
- value for the fieldnotify
future
- value for the fieldfuture
arena
- 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 fieldp
notify
- value for the fieldnotify
future
- 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
_arena
- to control the memory allocation scope
-
new_
Deprecated.dynamic allocation ofGPrivate
is 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 variable this Private.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
Sets the thread local variable this Private to have the valuevalue
in the current thread.This function differs from g_private_set() in the following way: if the previous value was non-
null
then theGDestroyNotify
handler for this Private is run on it.- Parameters:
value
- the new value
-
set
Sets the thread local variable this Private to have the valuevalue
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
-
GPrivate
is a bad idea.