mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-10 12:55:48 +01:00
copyediting API docs
This commit is contained in:
parent
2edf2f2571
commit
3d4e51759a
@ -1,3 +1,8 @@
|
|||||||
|
2006-08-10 Josh Parsons <josh.parsons@stonebow.otago.ac.nz>
|
||||||
|
|
||||||
|
* gobject/tmpl/gtype.sgml:
|
||||||
|
* glib/tmpl/threads.sgml: Style and grammar fixes.
|
||||||
|
|
||||||
2006-08-05 Matthias Clasen <mclasen@redhat.com>
|
2006-08-05 Matthias Clasen <mclasen@redhat.com>
|
||||||
|
|
||||||
* glib/tmpl/messages.sgml: Add some hints
|
* glib/tmpl/messages.sgml: Add some hints
|
||||||
|
@ -13,11 +13,12 @@ and thread private data.
|
|||||||
Threads act almost like processes, but unlike processes all threads of
|
Threads act almost like processes, but unlike processes all threads of
|
||||||
one process share the same memory. This is good, as it provides easy
|
one process share the same memory. This is good, as it provides easy
|
||||||
communication between the involved threads via this shared memory, and
|
communication between the involved threads via this shared memory, and
|
||||||
it is bad, because strange things (so called Heisenbugs) might happen,
|
it is bad, because strange things (so called "Heisenbugs") might
|
||||||
when the program is not carefully designed. Especially bad is, that due
|
happen if the program is not carefully designed. In particular, due to
|
||||||
to the concurrent nature of threads no assumptions on the order of
|
the concurrent nature of threads, no assumptions on the order of
|
||||||
execution of different threads can be done unless explicitly forced by
|
execution of code running in different threads can be made, unless
|
||||||
the programmer through synchronization primitives.
|
order is explicitly forced by the programmer through synchronization
|
||||||
|
primitives.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
@ -25,20 +26,21 @@ The aim of the thread related functions in GLib is to provide a
|
|||||||
portable means for writing multi-threaded software. There are
|
portable means for writing multi-threaded software. There are
|
||||||
primitives for mutexes to protect the access to portions of memory
|
primitives for mutexes to protect the access to portions of memory
|
||||||
(#GMutex, #GStaticMutex, #G_LOCK_DEFINE, #GStaticRecMutex and
|
(#GMutex, #GStaticMutex, #G_LOCK_DEFINE, #GStaticRecMutex and
|
||||||
#GStaticRWLock), there are primitives for condition variables to allow
|
#GStaticRWLock). There are primitives for condition variables to allow
|
||||||
synchronization of threads (#GCond) and finally there are primitives
|
synchronization of threads (#GCond). There are primitives
|
||||||
for thread-private data, that every thread has a private instance of
|
for thread-private data - data that every thread has a private instance of
|
||||||
(#GPrivate, #GStaticPrivate). Last but definitely not least there are
|
(#GPrivate, #GStaticPrivate). Last but definitely not least there are
|
||||||
primitives to portably create and manage threads (#GThread).
|
primitives to portably create and manage threads (#GThread).
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
You must call g_thread_init() before executing any other GLib functions
|
You must call g_thread_init() before executing any other GLib
|
||||||
in a threaded GLib program. After that, GLib is completely thread safe
|
functions in a threaded GLib program. After that, GLib is completely
|
||||||
(all global data is automatically locked). But individual data structure
|
thread safe (all global data is automatically locked), but individual
|
||||||
instances are not automatically locked for performance reasons. So e.g.
|
data structure instances are not automatically locked for performance
|
||||||
you must coordinate accesses to the same #GHashTable from multiple threads.
|
reasons. So, for example you must coordinate accesses to the same
|
||||||
The two notable exceptions from this rule are #GMainLoop and #GAsyncQueue,
|
#GHashTable from multiple threads. The two notable exceptions from
|
||||||
|
this rule are #GMainLoop and #GAsyncQueue,
|
||||||
which <emphasis>are</emphasis> threadsafe and needs no further
|
which <emphasis>are</emphasis> threadsafe and needs no further
|
||||||
application-level locking to be accessed from multiple threads.
|
application-level locking to be accessed from multiple threads.
|
||||||
</para>
|
</para>
|
||||||
@ -66,11 +68,12 @@ application-level locking to be accessed from multiple threads.
|
|||||||
<!-- ##### MACRO G_THREADS_ENABLED ##### -->
|
<!-- ##### MACRO G_THREADS_ENABLED ##### -->
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
This macro is defined, if GLib was compiled with thread support. This
|
This macro is defined if GLib was compiled with thread support. This
|
||||||
does not necessarily mean, that there is a thread implementation
|
does not necessarily mean that there is a thread implementation
|
||||||
available, but the infrastructure is in place and once you provide a
|
available, but it does mean that the infrastructure is in place and
|
||||||
thread implementation to g_thread_init(), GLib will be multi-thread
|
that once you provide a thread implementation to g_thread_init(), GLib
|
||||||
safe. It isn't and cannot be, if #G_THREADS_ENABLED is not defined.
|
will be multi-thread safe. If #G_THREADS_ENABLED is not defined, then
|
||||||
|
Glib is not, and cannot be, multi-thread safe.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
|
||||||
@ -78,7 +81,7 @@ safe. It isn't and cannot be, if #G_THREADS_ENABLED is not defined.
|
|||||||
<!-- ##### MACRO G_THREADS_IMPL_POSIX ##### -->
|
<!-- ##### MACRO G_THREADS_IMPL_POSIX ##### -->
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
This macro is defined, if POSIX style threads are used.
|
This macro is defined if POSIX style threads are used.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
|
||||||
@ -86,8 +89,8 @@ This macro is defined, if POSIX style threads are used.
|
|||||||
<!-- ##### MACRO G_THREADS_IMPL_NONE ##### -->
|
<!-- ##### MACRO G_THREADS_IMPL_NONE ##### -->
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
This macro is defined, if no thread implementation is used. You can
|
This macro is defined if no thread implementation is used. You can,
|
||||||
however provide one to g_thread_init() to make GLib multi-thread safe.
|
however, provide one to g_thread_init() to make GLib multi-thread safe.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
|
||||||
@ -111,15 +114,15 @@ shortage. Try again later.
|
|||||||
|
|
||||||
<para>
|
<para>
|
||||||
This function table is used by g_thread_init() to initialize the
|
This function table is used by g_thread_init() to initialize the
|
||||||
thread system. The functions in that table are directly used by their
|
thread system. The functions in the table are directly used by their
|
||||||
g_* prepended counterparts, that are described here, e.g. if you call
|
g_* prepended counterparts (described in this document). For example,
|
||||||
g_mutex_new() then mutex_new() from the table provided to
|
if you call g_mutex_new() then mutex_new() from the table provided to
|
||||||
g_thread_init() will be called.
|
g_thread_init() will be called.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<note>
|
<note>
|
||||||
<para>
|
<para>
|
||||||
This struct should only be used, if you know, what you are doing.
|
Do not use this struct unless you know what you are doing.
|
||||||
</para>
|
</para>
|
||||||
</note>
|
</note>
|
||||||
|
|
||||||
@ -155,7 +158,7 @@ will only have to call <literal>g_thread_init (NULL)</literal>.
|
|||||||
|
|
||||||
<note>
|
<note>
|
||||||
<para>
|
<para>
|
||||||
You should only call g_thread_init() with a non-%NULL parameter if you
|
Do not call g_thread_init() with a non-%NULL parameter unless you
|
||||||
really know what you are doing.
|
really know what you are doing.
|
||||||
</para>
|
</para>
|
||||||
</note>
|
</note>
|
||||||
@ -163,15 +166,15 @@ really know what you are doing.
|
|||||||
<note>
|
<note>
|
||||||
<para>
|
<para>
|
||||||
g_thread_init() must not be called directly or indirectly as a
|
g_thread_init() must not be called directly or indirectly as a
|
||||||
callback from GLib. Also no mutexes may be currently locked, while
|
callback from GLib. Also no mutexes may be currently locked while
|
||||||
calling g_thread_init().
|
calling g_thread_init().
|
||||||
</para>
|
</para>
|
||||||
</note>
|
</note>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
g_thread_init() might only be called once. On the second call
|
g_thread_init() might only be called once. On the second call
|
||||||
it will abort with an error. If you want to make sure, that the thread
|
it will abort with an error. If you want to make sure that the thread
|
||||||
system is initialized, you can do that too:
|
system is initialized, you can do this:
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
@ -183,9 +186,10 @@ if (!g_thread_supported (<!-- -->)) g_thread_init (NULL);
|
|||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
After that line either the thread system is initialized or the program
|
After that line, either the thread system is initialized or, if no
|
||||||
will abort, if no thread system is available in GLib, i.e. either
|
thread system is available in GLib (i.e. either #G_THREADS_ENABLED is
|
||||||
#G_THREADS_ENABLED is not defined or #G_THREADS_IMPL_NONE is defined.
|
not defined or #G_THREADS_IMPL_NONE is defined), the program will
|
||||||
|
abort.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
@ -208,8 +212,8 @@ entry points to the thread system to be used.
|
|||||||
|
|
||||||
<!-- ##### FUNCTION g_thread_supported ##### -->
|
<!-- ##### FUNCTION g_thread_supported ##### -->
|
||||||
<para>
|
<para>
|
||||||
This function returns, whether the thread system is initialized or
|
This function returns %TRUE if the thread system is initialized, and
|
||||||
not.
|
%FALSE if it is not.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<note>
|
<note>
|
||||||
@ -240,7 +244,7 @@ Specifies the priority of a thread.
|
|||||||
|
|
||||||
<note>
|
<note>
|
||||||
<para>
|
<para>
|
||||||
It is not guaranteed, that threads with different priorities really
|
It is not guaranteed that threads with different priorities really
|
||||||
behave accordingly. On some systems (e.g. Linux) there are no thread
|
behave accordingly. On some systems (e.g. Linux) there are no thread
|
||||||
priorities. On other systems (e.g. Solaris) there doesn't seem to be
|
priorities. On other systems (e.g. Solaris) there doesn't seem to be
|
||||||
different scheduling for different priorities. All in all try to avoid
|
different scheduling for different priorities. All in all try to avoid
|
||||||
@ -275,8 +279,8 @@ This function creates a new thread with the default priority.
|
|||||||
|
|
||||||
<para>
|
<para>
|
||||||
If @joinable is %TRUE, you can wait for this threads termination
|
If @joinable is %TRUE, you can wait for this threads termination
|
||||||
calling g_thread_join(). Otherwise the thread will just disappear, when
|
calling g_thread_join(). Otherwise the thread will just disappear when
|
||||||
ready.
|
it terminates.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
@ -299,17 +303,19 @@ error is set, if and only if the function returns %NULL.
|
|||||||
<!-- ##### FUNCTION g_thread_create_full ##### -->
|
<!-- ##### FUNCTION g_thread_create_full ##### -->
|
||||||
<para>
|
<para>
|
||||||
This function creates a new thread with the priority @priority. If the
|
This function creates a new thread with the priority @priority. If the
|
||||||
underlying thread implementation supports it, the thread gets a stack size
|
underlying thread implementation supports it, the thread gets a stack
|
||||||
of @stack_size or the default value for the current platform, if @stack_size is 0.
|
size of @stack_size or the default value for the current platform, if
|
||||||
|
@stack_size is 0.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
If @joinable is %TRUE, you can wait for this threads termination
|
If @joinable is %TRUE, you can wait for this threads termination
|
||||||
calling g_thread_join(). Otherwise the thread will just disappear, when
|
calling g_thread_join(). Otherwise the thread will just disappear when
|
||||||
ready. If @bound is %TRUE, this thread will be scheduled in the system
|
it terminates. If @bound is %TRUE, this thread will be scheduled in
|
||||||
scope, otherwise the implementation is free to do scheduling in the
|
the system scope, otherwise the implementation is free to do
|
||||||
process scope. The first variant is more expensive resource-wise, but
|
scheduling in the process scope. The first variant is more expensive
|
||||||
generally faster. On some systems (e.g. Linux) all threads are bound.
|
resource-wise, but generally faster. On some systems (e.g. Linux) all
|
||||||
|
threads are bound.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
@ -324,7 +330,7 @@ error is set, if and only if the function returns %NULL.
|
|||||||
|
|
||||||
<note>
|
<note>
|
||||||
<para>
|
<para>
|
||||||
It is not guaranteed, that threads with different priorities really
|
It is not guaranteed that threads with different priorities really
|
||||||
behave accordingly. On some systems (e.g. Linux) there are no thread
|
behave accordingly. On some systems (e.g. Linux) there are no thread
|
||||||
priorities. On other systems (e.g. Solaris) there doesn't seem to be
|
priorities. On other systems (e.g. Solaris) there doesn't seem to be
|
||||||
different scheduling for different priorities. All in all try to avoid
|
different scheduling for different priorities. All in all try to avoid
|
||||||
@ -335,10 +341,10 @@ default.
|
|||||||
|
|
||||||
<note>
|
<note>
|
||||||
<para>
|
<para>
|
||||||
Only use g_thread_create_full(), when you really can't use
|
Only use g_thread_create_full() if you really can't use
|
||||||
g_thread_create() instead. g_thread_create() does not take
|
g_thread_create() instead. g_thread_create() does not take
|
||||||
@stack_size, @bound and @priority as arguments, as they should only be
|
@stack_size, @bound, and @priority as arguments, as they should only
|
||||||
used for cases, where it is inevitable.
|
be used in cases in which it is unavoidable.
|
||||||
</para>
|
</para>
|
||||||
</note>
|
</note>
|
||||||
|
|
||||||
@ -381,7 +387,7 @@ Changes the priority of @thread to @priority.
|
|||||||
|
|
||||||
<note>
|
<note>
|
||||||
<para>
|
<para>
|
||||||
It is not guaranteed, that threads with different priorities really
|
It is not guaranteed that threads with different priorities really
|
||||||
behave accordingly. On some systems (e.g. Linux) there are no thread
|
behave accordingly. On some systems (e.g. Linux) there are no thread
|
||||||
priorities. On other systems (e.g. Solaris) there doesn't seem to be
|
priorities. On other systems (e.g. Solaris) there doesn't seem to be
|
||||||
different scheduling for different priorities. All in all try to avoid
|
different scheduling for different priorities. All in all try to avoid
|
||||||
@ -400,8 +406,8 @@ Gives way to other threads waiting to be scheduled.
|
|||||||
|
|
||||||
<para>
|
<para>
|
||||||
This function is often used as a method to make busy wait less
|
This function is often used as a method to make busy wait less
|
||||||
evil. But in most cases, you will encounter, there are better methods
|
evil. But in most cases you will encounter, there are better methods
|
||||||
to do that. So in general you shouldn't use that function.
|
to do that. So in general you shouldn't use this function.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
|
||||||
@ -410,7 +416,7 @@ to do that. So in general you shouldn't use that function.
|
|||||||
<para>
|
<para>
|
||||||
Exits the current thread. If another thread is waiting for that thread
|
Exits the current thread. If another thread is waiting for that thread
|
||||||
using g_thread_join() and the current thread is joinable, the waiting
|
using g_thread_join() and the current thread is joinable, the waiting
|
||||||
thread will be woken up and getting @retval as the return value of
|
thread will be woken up and get @retval as the return value of
|
||||||
g_thread_join(). If the current thread is not joinable, @retval is
|
g_thread_join(). If the current thread is not joinable, @retval is
|
||||||
ignored. Calling
|
ignored. Calling
|
||||||
</para>
|
</para>
|
||||||
@ -482,7 +488,7 @@ access. Take for example the following function:
|
|||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
It is easy to see, that this won't work in a multi-threaded
|
It is easy to see that this won't work in a multi-threaded
|
||||||
application. There current_number must be protected against shared
|
application. There current_number must be protected against shared
|
||||||
access. A first naive implementation would be:
|
access. A first naive implementation would be:
|
||||||
</para>
|
</para>
|
||||||
@ -510,8 +516,8 @@ access. A first naive implementation would be:
|
|||||||
|
|
||||||
<para>
|
<para>
|
||||||
This looks like it would work, but there is a race condition while
|
This looks like it would work, but there is a race condition while
|
||||||
constructing the mutex and this code cannot work reliable. So please do
|
constructing the mutex and this code cannot work reliable. Please do
|
||||||
not use such constructs in your own programs. One working solution is:
|
not use such constructs in your own programs! One working solution is:
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
@ -547,9 +553,10 @@ not use such constructs in your own programs. One working solution is:
|
|||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
If you want to use a mutex, but your code should also work without
|
If you want to use a mutex, and your code should also work without
|
||||||
calling g_thread_init() first, you can not use a #GMutex, as
|
calling g_thread_init() first, then you can not use a #GMutex, as
|
||||||
g_mutex_new() requires that. Use a #GStaticMutex instead.
|
g_mutex_new() requires that the thread system be initialized. Use a
|
||||||
|
#GStaticMutex instead.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
@ -573,7 +580,7 @@ Creates a new #GMutex.
|
|||||||
|
|
||||||
<note>
|
<note>
|
||||||
<para>
|
<para>
|
||||||
This function will abort, if g_thread_init() has not been called yet.
|
This function will abort if g_thread_init() has not been called yet.
|
||||||
</para>
|
</para>
|
||||||
</note>
|
</note>
|
||||||
|
|
||||||
@ -589,8 +596,8 @@ thread.
|
|||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
This function can also be used, if g_thread_init() has not yet been
|
This function can be used even if g_thread_init() has not yet been
|
||||||
called and will do nothing then.
|
called, and, in that case, will do nothing.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<note>
|
<note>
|
||||||
@ -614,8 +621,8 @@ and returns %TRUE.
|
|||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
This function can also be used, if g_thread_init() has not yet been
|
This function can be used even if g_thread_init() has not yet been
|
||||||
called and will immediately return %TRUE then.
|
called, and, in that case, will immediately return %TRUE.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<note>
|
<note>
|
||||||
@ -639,8 +646,8 @@ for @mutex, it will be woken and can lock @mutex itself.
|
|||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
This function can also be used, if g_thread_init() has not yet been
|
This function can be used even if g_thread_init() has not yet been
|
||||||
called and will do nothing then.
|
called, and, in that case, will do nothing.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
@mutex: a #GMutex.
|
@mutex: a #GMutex.
|
||||||
@ -702,7 +709,7 @@ platforms.
|
|||||||
|
|
||||||
<para>
|
<para>
|
||||||
All of the <function>g_static_mutex_*</function> functions can also be
|
All of the <function>g_static_mutex_*</function> functions can also be
|
||||||
used, if g_thread_init() has not yet been called.
|
used even if g_thread_init() has not yet been called.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<note>
|
<note>
|
||||||
@ -802,11 +809,11 @@ you should also free the #GStaticMutex.
|
|||||||
The %G_LOCK_* macros provide a convenient interface to #GStaticMutex
|
The %G_LOCK_* macros provide a convenient interface to #GStaticMutex
|
||||||
with the advantage that they will expand to nothing in programs
|
with the advantage that they will expand to nothing in programs
|
||||||
compiled against a thread-disabled GLib, saving code and memory
|
compiled against a thread-disabled GLib, saving code and memory
|
||||||
there. #G_LOCK_DEFINE defines a lock. It can appear, where variable
|
there. #G_LOCK_DEFINE defines a lock. It can appear anywhere variable
|
||||||
definitions may appear in programs, i.e. in the first block of a
|
definitions may appear in programs, i.e. in the first block of a
|
||||||
function or outside of functions. The @name parameter will be mangled
|
function or outside of functions. The @name parameter will be mangled
|
||||||
to get the name of the #GStaticMutex. This means, that you can use
|
to get the name of the #GStaticMutex. This means that you can use
|
||||||
names of existing variables as the parameter, e.g. the name of the
|
names of existing variables as the parameter - e.g. the name of the
|
||||||
variable you intent to protect with the lock. Look at our
|
variable you intent to protect with the lock. Look at our
|
||||||
<function>give_me_next_number()</function> example using the %G_LOCK_* macros:
|
<function>give_me_next_number()</function> example using the %G_LOCK_* macros:
|
||||||
</para>
|
</para>
|
||||||
@ -883,12 +890,13 @@ Works like g_mutex_unlock(), but for a lock defined with #G_LOCK_DEFINE.
|
|||||||
<!-- ##### STRUCT GStaticRecMutex ##### -->
|
<!-- ##### STRUCT GStaticRecMutex ##### -->
|
||||||
<para>
|
<para>
|
||||||
A #GStaticRecMutex works like a #GStaticMutex, but it can be locked
|
A #GStaticRecMutex works like a #GStaticMutex, but it can be locked
|
||||||
multiple times by one thread. If you enter it n times, however, you
|
multiple times by one thread. If you enter it n times, you have to
|
||||||
have to unlock it n times again to let other threads lock it. An
|
unlock it n times again to let other threads lock it. An exception is
|
||||||
exception is the function g_static_rec_mutex_unlock_full(), that
|
the function g_static_rec_mutex_unlock_full(): that allows you to
|
||||||
allows you to unlock a #GStaticRecMutex completely returning the depth,
|
unlock a #GStaticRecMutex completely returning the depth, (i.e. the
|
||||||
i.e. the number of times this mutex was locked. The depth can later be
|
number of times this mutex was locked). The depth can later be used to
|
||||||
used to restore the state by calling g_static_rec_mutex_lock_full().
|
restore the state of the #GStaticRecMutex by calling
|
||||||
|
g_static_rec_mutex_lock_full().
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
@ -897,14 +905,14 @@ the following functions.
|
|||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
All of the <function>g_static_rec_mutex_*</function> functions can also
|
All of the <function>g_static_rec_mutex_*</function> functions can
|
||||||
be used, if g_thread_init() has not been called.
|
be used even if g_thread_init() has not been called.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
|
||||||
<!-- ##### MACRO G_STATIC_REC_MUTEX_INIT ##### -->
|
<!-- ##### MACRO G_STATIC_REC_MUTEX_INIT ##### -->
|
||||||
<para>
|
<para>
|
||||||
A #GStaticRecMutex must be initialized with this macro, before it can
|
A #GStaticRecMutex must be initialized with this macro before it can
|
||||||
be used. This macro can used be to initialize a variable, but it
|
be used. This macro can used be to initialize a variable, but it
|
||||||
cannot be assigned to a variable. In that case you have to use
|
cannot be assigned to a variable. In that case you have to use
|
||||||
g_static_rec_mutex_init().
|
g_static_rec_mutex_init().
|
||||||
@ -922,7 +930,7 @@ GStaticRecMutex my_mutex = G_STATIC_REC_MUTEX_INIT;
|
|||||||
|
|
||||||
<!-- ##### FUNCTION g_static_rec_mutex_init ##### -->
|
<!-- ##### FUNCTION g_static_rec_mutex_init ##### -->
|
||||||
<para>
|
<para>
|
||||||
A #GStaticRecMutex must be initialized with this function, before it
|
A #GStaticRecMutex must be initialized with this function before it
|
||||||
can be used. Alternatively you can initialize it with
|
can be used. Alternatively you can initialize it with
|
||||||
#G_STATIC_REC_MUTEX_INIT.
|
#G_STATIC_REC_MUTEX_INIT.
|
||||||
</para>
|
</para>
|
||||||
@ -955,11 +963,11 @@ functions increases the depth of @mutex and immediately returns %TRUE.
|
|||||||
|
|
||||||
<!-- ##### FUNCTION g_static_rec_mutex_unlock ##### -->
|
<!-- ##### FUNCTION g_static_rec_mutex_unlock ##### -->
|
||||||
<para>
|
<para>
|
||||||
Unlocks @mutex. Another threads can, however, only lock @mutex when it
|
Unlocks @mutex. Another thread can will be allowed to lock @mutex only
|
||||||
has been unlocked as many times, as it had been locked before. If
|
when it has been unlocked as many times as it had been locked
|
||||||
@mutex is completely unlocked and another thread is blocked in a
|
before. If @mutex is completely unlocked and another thread is blocked
|
||||||
g_static_rec_mutex_lock() call for @mutex, it will be woken and can
|
in a g_static_rec_mutex_lock() call for @mutex, it will be woken and
|
||||||
lock @mutex itself.
|
can lock @mutex itself.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
@mutex: a #GStaticRecMutex to unlock.
|
@mutex: a #GStaticRecMutex to unlock.
|
||||||
@ -978,7 +986,7 @@ Works like calling g_static_rec_mutex_lock() for @mutex @depth times.
|
|||||||
<para>
|
<para>
|
||||||
Completely unlocks @mutex. If another thread is blocked in a
|
Completely unlocks @mutex. If another thread is blocked in a
|
||||||
g_static_rec_mutex_lock() call for @mutex, it will be woken and can
|
g_static_rec_mutex_lock() call for @mutex, it will be woken and can
|
||||||
lock @mutex itself. This function returns the number of times, that
|
lock @mutex itself. This function returns the number of times that
|
||||||
@mutex has been locked by the current thread. To restore the state
|
@mutex has been locked by the current thread. To restore the state
|
||||||
before the call to g_static_rec_mutex_unlock_full() you can call
|
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
|
g_static_rec_mutex_lock_full() with the depth returned by this
|
||||||
@ -1007,9 +1015,9 @@ freed, you should also free the #GStaticRecMutex.
|
|||||||
<!-- ##### STRUCT GStaticRWLock ##### -->
|
<!-- ##### STRUCT GStaticRWLock ##### -->
|
||||||
<para>
|
<para>
|
||||||
The #GStaticRWLock struct represents a read-write lock. A read-write
|
The #GStaticRWLock struct represents a read-write lock. A read-write
|
||||||
lock can be used for protecting data, that some portions of code only
|
lock can be used for protecting data that some portions of code only
|
||||||
read from, while others also write. In such situations it is
|
read from, while others also write. In such situations it is
|
||||||
desirable, that several readers can read at once, whereas of course
|
desirable that several readers can read at once, whereas of course
|
||||||
only one writer may write at a time. Take a look at the following
|
only one writer may write at a time. Take a look at the following
|
||||||
example:
|
example:
|
||||||
|
|
||||||
@ -1056,19 +1064,19 @@ example:
|
|||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
This example shows an array, which can be accessed by many readers
|
This example shows an array which can be accessed by many readers
|
||||||
(the <function>my_array_get()</function> function) simultaneously,
|
(the <function>my_array_get()</function> function) simultaneously,
|
||||||
whereas the writers (the <function>my_array_set()</function> function)
|
whereas the writers (the <function>my_array_set()</function> function)
|
||||||
will only be allowed once a time and only if no readers currently access
|
will only be allowed once at a time and only if no readers currently access
|
||||||
the array. This is because of the potentially dangerous resizing of the
|
the array. This is because of the potentially dangerous resizing of the
|
||||||
array. Using these functions is fully multi-thread safe now.
|
array. Using these functions is fully multi-thread safe now.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
Most of the time the writers should have precedence of readers. That
|
Most of the time, writers should have precedence over readers. That
|
||||||
means for this implementation, that as soon as a writer wants to lock
|
means, for this implementation, that as soon as a writer wants to lock
|
||||||
the data, no other reader is allowed to lock the data, whereas of
|
the data, no other reader is allowed to lock the data, whereas, of
|
||||||
course the readers, that already have locked the data are allowed to
|
course, the readers that already have locked the data are allowed to
|
||||||
finish their operation. As soon as the last reader unlocks the data,
|
finish their operation. As soon as the last reader unlocks the data,
|
||||||
the writer will lock it.
|
the writer will lock it.
|
||||||
</para>
|
</para>
|
||||||
@ -1079,18 +1087,18 @@ the following functions.
|
|||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
All of the <function>g_static_rw_lock_*</function> functions can also be
|
All of the <function>g_static_rw_lock_*</function> functions can be
|
||||||
used, if g_thread_init() has not been called.
|
used even if g_thread_init() has not been called.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<note>
|
<note>
|
||||||
<para>
|
<para>
|
||||||
A read-write lock has a higher overhead as a mutex. For example both
|
A read-write lock has a higher overhead than a mutex. For example, both
|
||||||
g_static_rw_lock_reader_lock() and g_static_rw_lock_reader_unlock()
|
g_static_rw_lock_reader_lock() and g_static_rw_lock_reader_unlock()
|
||||||
have to lock and unlock a #GStaticMutex, so it takes at least twice the
|
have to lock and unlock a #GStaticMutex, so it takes at least twice the
|
||||||
time to lock and unlock a #GStaticRWLock than to lock and unlock a
|
time to lock and unlock a #GStaticRWLock that it does to lock and unlock a
|
||||||
#GStaticMutex. So only data structures, that are accessed by multiple
|
#GStaticMutex. So only data structures that are accessed by multiple
|
||||||
readers, which keep the lock for a considerable time justify a
|
readers, and which keep the lock for a considerable time justify a
|
||||||
#GStaticRWLock. The above example most probably would fare better with
|
#GStaticRWLock. The above example most probably would fare better with
|
||||||
a #GStaticMutex.
|
a #GStaticMutex.
|
||||||
</para>
|
</para>
|
||||||
@ -1099,7 +1107,7 @@ a #GStaticMutex.
|
|||||||
|
|
||||||
<!-- ##### MACRO G_STATIC_RW_LOCK_INIT ##### -->
|
<!-- ##### MACRO G_STATIC_RW_LOCK_INIT ##### -->
|
||||||
<para>
|
<para>
|
||||||
A #GStaticRWLock must be initialized with this macro, before it can
|
A #GStaticRWLock must be initialized with this macro before it can
|
||||||
be used. This macro can used be to initialize a variable, but it
|
be used. This macro can used be to initialize a variable, but it
|
||||||
cannot be assigned to a variable. In that case you have to use
|
cannot be assigned to a variable. In that case you have to use
|
||||||
g_static_rw_lock_init().
|
g_static_rw_lock_init().
|
||||||
@ -1117,7 +1125,7 @@ GStaticRWLock my_lock = G_STATIC_RW_LOCK_INIT;
|
|||||||
|
|
||||||
<!-- ##### FUNCTION g_static_rw_lock_init ##### -->
|
<!-- ##### FUNCTION g_static_rw_lock_init ##### -->
|
||||||
<para>
|
<para>
|
||||||
A #GStaticRWLock must be initialized with this function, before it can
|
A #GStaticRWLock must be initialized with this function before it can
|
||||||
be used. Alternatively you can initialize it with
|
be used. Alternatively you can initialize it with
|
||||||
#G_STATIC_RW_LOCK_INIT.
|
#G_STATIC_RW_LOCK_INIT.
|
||||||
</para>
|
</para>
|
||||||
@ -1138,8 +1146,8 @@ g_static_rw_lock_reader_unlock().
|
|||||||
|
|
||||||
<para>
|
<para>
|
||||||
#GStaticRWLock is not recursive. It might seem to be possible to
|
#GStaticRWLock is not recursive. It might seem to be possible to
|
||||||
recursively lock for reading, but that can result in a deadlock as
|
recursively lock for reading, but that can result in a deadlock, due
|
||||||
well, due to writer preference.
|
to writer preference.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
@lock: a #GStaticRWLock to lock for reading.
|
@lock: a #GStaticRWLock to lock for reading.
|
||||||
@ -1149,9 +1157,9 @@ well, due to writer preference.
|
|||||||
<para>
|
<para>
|
||||||
Tries to lock @lock for reading. If @lock is already locked for
|
Tries to lock @lock for reading. If @lock is already locked for
|
||||||
writing by another thread or if another thread is already waiting to
|
writing by another thread or if another thread is already waiting to
|
||||||
lock @lock for writing, it immediately returns %FALSE. Otherwise it
|
lock @lock for writing, immediately returns %FALSE. Otherwise locks
|
||||||
locks @lock for reading and returns %TRUE. This lock has to be unlocked
|
@lock for reading and returns %TRUE. This lock has to be unlocked by
|
||||||
by g_static_rw_lock_reader_unlock().
|
g_static_rw_lock_reader_unlock().
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
@lock: a #GStaticRWLock to lock for reading.
|
@lock: a #GStaticRWLock to lock for reading.
|
||||||
@ -1196,11 +1204,12 @@ lock has to be unlocked by g_static_rw_lock_writer_unlock().
|
|||||||
|
|
||||||
<!-- ##### FUNCTION g_static_rw_lock_writer_unlock ##### -->
|
<!-- ##### FUNCTION g_static_rw_lock_writer_unlock ##### -->
|
||||||
<para>
|
<para>
|
||||||
Unlocks @lock. If a thread waits to lock @lock for writing and all
|
Unlocks @lock. If a thread is waiting to lock @lock for writing and
|
||||||
locks for reading have been unlocked, the waiting thread is woken up
|
all locks for reading have been unlocked, the waiting thread is woken
|
||||||
and can lock @lock for writing. If no thread waits to lock @lock for
|
up and can lock @lock for writing. If no thread is waiting to lock
|
||||||
writing and threads wait to lock @lock for reading, the waiting
|
@lock for writing, and some thread or threads are waiting to lock @lock
|
||||||
threads are woken up and can lock @lock for reading.
|
for reading, the waiting threads are woken up and can lock @lock for
|
||||||
|
reading.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
@lock: a #GStaticRWLock to unlock after writing.
|
@lock: a #GStaticRWLock to unlock after writing.
|
||||||
@ -1214,7 +1223,7 @@ Releases all resources allocated to @lock.
|
|||||||
<para>
|
<para>
|
||||||
You don't have to call this functions for a #GStaticRWLock with an
|
You don't have to call this functions for a #GStaticRWLock with an
|
||||||
unbounded lifetime, i.e. objects declared 'static', but if you have a
|
unbounded lifetime, i.e. objects declared 'static', but if you have a
|
||||||
#GStaticRWLock as a member of a structure and the structure is freed,
|
#GStaticRWLock as a member of a structure, and the structure is freed,
|
||||||
you should also free the #GStaticRWLock.
|
you should also free the #GStaticRWLock.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
@ -1224,11 +1233,11 @@ you should also free the #GStaticRWLock.
|
|||||||
<!-- ##### STRUCT GCond ##### -->
|
<!-- ##### STRUCT GCond ##### -->
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
The #GCond struct is an opaque data structure to represent a
|
The #GCond struct is an opaque data structure that represents a
|
||||||
condition. A #GCond is an object, that threads can block on, if they
|
condition. Threads can block on a #GCond if they find a certain
|
||||||
find a certain condition to be false. If other threads change the
|
condition to be false. If other threads change the state of this
|
||||||
state of this condition they can signal the #GCond, such that the
|
condition they signal the #GCond, and that causes the waiting threads
|
||||||
waiting thread is woken up.
|
to be woken up.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
@ -1272,11 +1281,11 @@ has called <function>push_data()</function>.
|
|||||||
<note>
|
<note>
|
||||||
<para>
|
<para>
|
||||||
It is important to use the g_cond_wait() and g_cond_timed_wait()
|
It is important to use the g_cond_wait() and g_cond_timed_wait()
|
||||||
functions only inside a loop, which checks for the condition to be
|
functions only inside a loop which checks for the condition to be
|
||||||
true as it is not guaranteed that the waiting thread will find it
|
true. It is not guaranteed that the waiting thread will find the
|
||||||
fulfilled, even if the signaling thread left the condition
|
condition fulfilled after it wakes up, even if the signaling thread
|
||||||
in that state. This is because another thread can have altered the
|
left the condition in that state: another thread may have altered the
|
||||||
condition, before the waiting thread got the chance to be woken up,
|
condition before the waiting thread got the chance to be woken up,
|
||||||
even if the condition itself is protected by a #GMutex, like above.
|
even if the condition itself is protected by a #GMutex, like above.
|
||||||
</para>
|
</para>
|
||||||
</note>
|
</note>
|
||||||
@ -1307,13 +1316,13 @@ has not been called yet.
|
|||||||
<!-- ##### FUNCTION g_cond_signal ##### -->
|
<!-- ##### FUNCTION g_cond_signal ##### -->
|
||||||
<para>
|
<para>
|
||||||
If threads are waiting for @cond, exactly one of them is woken up. It
|
If threads are waiting for @cond, exactly one of them is woken up. It
|
||||||
is good practice to hold the same lock as the waiting thread, while
|
is good practice to hold the same lock as the waiting thread while
|
||||||
calling this function, though not required.
|
calling this function, though not required.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
This function can also be used, if g_thread_init() has
|
This function can be used even if g_thread_init() has not yet been called,
|
||||||
not yet been called and will do nothing then.
|
and, in that case, will do nothing.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
@cond: a #GCond.
|
@cond: a #GCond.
|
||||||
@ -1328,8 +1337,8 @@ this function, though not required.
|
|||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
This function can also be used, if g_thread_init() has
|
This function can be used even if g_thread_init() has not yet been called,
|
||||||
not yet been called and will do nothing then.
|
and, in that case, will do nothing.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
@cond: a #GCond.
|
@cond: a #GCond.
|
||||||
@ -1343,8 +1352,8 @@ before falling asleep and locked again before resuming.
|
|||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
This function can also be used, if g_thread_init() has not yet been
|
This function can be used even if g_thread_init() has not yet been
|
||||||
called and will immediately return then.
|
called, and, in that case, will immediately return.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
@cond: a #GCond.
|
@cond: a #GCond.
|
||||||
@ -1355,7 +1364,7 @@ called and will immediately return then.
|
|||||||
|
|
||||||
<para>
|
<para>
|
||||||
Waits until this thread is woken up on @cond, but not longer than
|
Waits until this thread is woken up on @cond, but not longer than
|
||||||
until the time, that is specified by @abs_time. The @mutex is
|
until the time specified by @abs_time. The @mutex is
|
||||||
unlocked before falling asleep and locked again before resuming.
|
unlocked before falling asleep and locked again before resuming.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
@ -1364,8 +1373,8 @@ If @abs_time is %NULL, g_cond_timed_wait() acts like g_cond_wait().
|
|||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
This function can also be used, if g_thread_init() has not yet been
|
This function can be used even if g_thread_init() has not yet been
|
||||||
called and will immediately return %TRUE then.
|
called, and, in that case, will immediately return %TRUE.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
@ -1374,9 +1383,9 @@ and g_time_val_add() can be used.
|
|||||||
</para>
|
</para>
|
||||||
|
|
||||||
@cond: a #GCond.
|
@cond: a #GCond.
|
||||||
@mutex: a #GMutex, that is currently locked.
|
@mutex: a #GMutex that is currently locked.
|
||||||
@abs_time: a #GTimeVal, determining the final time.
|
@abs_time: a #GTimeVal, determining the final time.
|
||||||
@Returns: %TRUE, if the thread is woken up in time.
|
@Returns: %TRUE if @cond was signalled, or %FALSE on timeout.
|
||||||
|
|
||||||
|
|
||||||
<!-- ##### FUNCTION g_cond_free ##### -->
|
<!-- ##### FUNCTION g_cond_free ##### -->
|
||||||
@ -1391,11 +1400,11 @@ Destroys the #GCond.
|
|||||||
<!-- ##### STRUCT GPrivate ##### -->
|
<!-- ##### STRUCT GPrivate ##### -->
|
||||||
<para>
|
<para>
|
||||||
The #GPrivate struct is an opaque data structure to represent a thread
|
The #GPrivate struct is an opaque data structure to represent a thread
|
||||||
private data key. Threads can thereby obtain and set a pointer, which
|
private data key. Threads can thereby obtain and set a pointer which
|
||||||
is private to the current thread.
|
is private to the current thread.
|
||||||
Take our <function>give_me_next_number()</function> example from above.
|
Take our <function>give_me_next_number()</function> example from above.
|
||||||
Now we don't want <literal>current_number</literal> to be shared
|
Suppose we don't want <literal>current_number</literal> to be shared
|
||||||
between the threads, but to be private to each thread. This can be
|
between the threads, but instead to be private to each thread. This can be
|
||||||
done as follows:
|
done as follows:
|
||||||
|
|
||||||
<example>
|
<example>
|
||||||
@ -1425,7 +1434,7 @@ done as follows:
|
|||||||
Here the pointer belonging to the key <literal>current_number_key</literal>
|
Here the pointer belonging to the key <literal>current_number_key</literal>
|
||||||
is read. If it is %NULL, it has not been set yet. Then get memory for an
|
is read. If it is %NULL, it has not been set yet. Then get memory for an
|
||||||
integer value, assign this memory to the pointer and write the pointer
|
integer value, assign this memory to the pointer and write the pointer
|
||||||
back. Now we have an integer value, that is private to the current thread.
|
back. Now we have an integer value that is private to the current thread.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
@ -1452,25 +1461,25 @@ destructor is called with this pointer as the argument.
|
|||||||
|
|
||||||
<note>
|
<note>
|
||||||
<para>
|
<para>
|
||||||
@destructor is working quite differently from @notify in
|
@destructor is used quite differently from @notify in
|
||||||
g_static_private_set().
|
g_static_private_set().
|
||||||
</para>
|
</para>
|
||||||
</note>
|
</note>
|
||||||
|
|
||||||
<note>
|
<note>
|
||||||
<para>
|
<para>
|
||||||
A #GPrivate can not be freed. Reuse it instead, if you can to avoid
|
A #GPrivate can not be freed. Reuse it instead, if you can, to avoid
|
||||||
shortage or use #GStaticPrivate.
|
shortage, or use #GStaticPrivate.
|
||||||
</para>
|
</para>
|
||||||
</note>
|
</note>
|
||||||
|
|
||||||
<note>
|
<note>
|
||||||
<para>
|
<para>
|
||||||
This function will abort, if g_thread_init() has not been called yet.
|
This function will abort if g_thread_init() has not been called yet.
|
||||||
</para>
|
</para>
|
||||||
</note>
|
</note>
|
||||||
|
|
||||||
@destructor: a function to handle the data keyed to #GPrivate, when a
|
@destructor: a function to destroy the data keyed to #GPrivate when a
|
||||||
thread ends.
|
thread ends.
|
||||||
@Returns: a new #GPrivate.
|
@Returns: a new #GPrivate.
|
||||||
|
|
||||||
@ -1478,14 +1487,14 @@ thread ends.
|
|||||||
<!-- ##### FUNCTION g_private_get ##### -->
|
<!-- ##### FUNCTION g_private_get ##### -->
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
Returns the pointer keyed to @private_key for the current thread. This
|
Returns the pointer keyed to @private_key for the current thread.
|
||||||
pointer is %NULL, when g_private_set() hasn't been called for the
|
If g_private_set() hasn't been called for the
|
||||||
current @private_key and thread yet.
|
current @private_key and thread yet, this pointer will be %NULL.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
This function can also be used, if g_thread_init() has not yet been
|
This function can be used even if g_thread_init() has not yet been
|
||||||
called and will return the value of @private_key casted to #gpointer then.
|
called, and, in that case, will return the value of @private_key casted to #gpointer.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
@private_key: a #GPrivate.
|
@private_key: a #GPrivate.
|
||||||
@ -1499,8 +1508,8 @@ Sets the pointer keyed to @private_key for the current thread.
|
|||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
This function can also be used, if g_thread_init() has not yet been
|
This function can be used even if g_thread_init() has not yet been
|
||||||
called and will set @private_key to @data casted to #GPrivate* then.
|
called, and, in that case, will set @private_key to @data casted to #GPrivate*.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
@private_key: a #GPrivate.
|
@private_key: a #GPrivate.
|
||||||
@ -1571,7 +1580,7 @@ Works like g_private_get() only for a #GStaticPrivate.
|
|||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
This function also works, if g_thread_init() has not yet been called.
|
This function works even if g_thread_init() has not yet been called.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
@private_key: a #GStaticPrivate.
|
@private_key: a #GStaticPrivate.
|
||||||
@ -1586,7 +1595,7 @@ whenever the pointer is set again or whenever the current thread ends.
|
|||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
This function also works, if g_thread_init() has not yet been
|
This function works even if g_thread_init() has not yet been
|
||||||
called. If g_thread_init() is called later, the @data keyed to
|
called. If g_thread_init() is called later, the @data keyed to
|
||||||
@private_key will be inherited only by the main thread, i.e. the one that
|
@private_key will be inherited only by the main thread, i.e. the one that
|
||||||
called g_thread_init().
|
called g_thread_init().
|
||||||
@ -1594,14 +1603,14 @@ called g_thread_init().
|
|||||||
|
|
||||||
<note>
|
<note>
|
||||||
<para>
|
<para>
|
||||||
@notify is working quite differently from @destructor in
|
@notify is used quite differently from @destructor in
|
||||||
g_private_new().
|
g_private_new().
|
||||||
</para>
|
</para>
|
||||||
</note>
|
</note>
|
||||||
|
|
||||||
@private_key: a #GStaticPrivate.
|
@private_key: a #GStaticPrivate.
|
||||||
@data: the new pointer.
|
@data: the new pointer.
|
||||||
@notify: a function to be called with the pointer, whenever the
|
@notify: a function to be called with the pointer whenever the
|
||||||
current thread ends or sets this pointer again.
|
current thread ends or sets this pointer again.
|
||||||
|
|
||||||
|
|
||||||
@ -1634,7 +1643,7 @@ function. Any one-time initialization function must have its own unique
|
|||||||
|
|
||||||
<!-- ##### ENUM GOnceStatus ##### -->
|
<!-- ##### ENUM GOnceStatus ##### -->
|
||||||
<para>
|
<para>
|
||||||
The possible stati of a one-time initialization function controlled by a #GOnce struct.
|
The possible statuses of a one-time initialization function controlled by a #GOnce struct.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
@G_ONCE_STATUS_NOTCALLED: the function has not been called yet.
|
@G_ONCE_STATUS_NOTCALLED: the function has not been called yet.
|
||||||
@ -1644,7 +1653,7 @@ The possible stati of a one-time initialization function controlled by a #GOnce
|
|||||||
|
|
||||||
<!-- ##### MACRO G_ONCE_INIT ##### -->
|
<!-- ##### MACRO G_ONCE_INIT ##### -->
|
||||||
<para>
|
<para>
|
||||||
A #GOnce must be initialized with this macro, before it can be used.
|
A #GOnce must be initialized with this macro before it can be used.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
<informalexample>
|
<informalexample>
|
||||||
|
@ -58,7 +58,7 @@ type.
|
|||||||
<!-- ##### MACRO G_TYPE_FUNDAMENTAL ##### -->
|
<!-- ##### MACRO G_TYPE_FUNDAMENTAL ##### -->
|
||||||
<para>
|
<para>
|
||||||
Returns the fundamental type which is the ancestor of @type.
|
Returns the fundamental type which is the ancestor of @type.
|
||||||
Fundamental types are types that serve as fundaments for the derived types,
|
Fundamental types are types that serve as ultimate bases for the derived types,
|
||||||
thus they are the roots of distinct inheritance hierarchies.
|
thus they are the roots of distinct inheritance hierarchies.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
@ -113,7 +113,7 @@ Returns %TRUE if @type is a fundamental type.
|
|||||||
|
|
||||||
<!-- ##### MACRO G_TYPE_IS_VALUE_TYPE ##### -->
|
<!-- ##### MACRO G_TYPE_IS_VALUE_TYPE ##### -->
|
||||||
<para>
|
<para>
|
||||||
Returns %TRUE if @type is a value type which can be used for
|
Returns %TRUE if @type is a value type and can be used with
|
||||||
g_value_init().
|
g_value_init().
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
@ -166,7 +166,7 @@ can be used as the base class of a deep (multi-level) class hierarchy.
|
|||||||
<!-- ##### MACRO G_TYPE_IS_INTERFACE ##### -->
|
<!-- ##### MACRO G_TYPE_IS_INTERFACE ##### -->
|
||||||
<para>
|
<para>
|
||||||
Returns %TRUE if @type is an interface type.
|
Returns %TRUE if @type is an interface type.
|
||||||
Interface types are types that provide pure APIs, the implementation
|
An interface type provides a pure API, the implementation
|
||||||
of which is provided by another type (which is then said to conform
|
of which is provided by another type (which is then said to conform
|
||||||
to the interface). GLib interfaces are somewhat analogous to Java
|
to the interface). GLib interfaces are somewhat analogous to Java
|
||||||
interfaces and C++ classes containing only pure virtual functions,
|
interfaces and C++ classes containing only pure virtual functions,
|
||||||
@ -199,11 +199,11 @@ An opaque structure used as the base of all classes.
|
|||||||
<para>
|
<para>
|
||||||
This structure is used to provide the type system with the information
|
This structure is used to provide the type system with the information
|
||||||
required to initialize and destruct (finalize) a type's class and
|
required to initialize and destruct (finalize) a type's class and
|
||||||
instances thereof.
|
its instances.
|
||||||
The initialized structure is passed to the g_type_register_static() function
|
The initialized structure is passed to the g_type_register_static() function
|
||||||
(or is copied into the provided #GTypeInfo structure in the
|
(or is copied into the provided #GTypeInfo structure in the
|
||||||
g_type_plugin_complete_type_info()). The type system will perform a deep
|
g_type_plugin_complete_type_info()). The type system will perform a deep
|
||||||
copy of this structure, so it's memory does not need to be persistent
|
copy of this structure, so its memory does not need to be persistent
|
||||||
across invocation of g_type_register_static().
|
across invocation of g_type_register_static().
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
@ -295,8 +295,8 @@ to serve as a container for values of a type.
|
|||||||
}
|
}
|
||||||
</programlisting>
|
</programlisting>
|
||||||
@collect_format: A string format describing how to collect the contents of
|
@collect_format: A string format describing how to collect the contents of
|
||||||
this value, bit-by-bit. Each character in the format represents
|
this value bit-by-bit. Each character in the format represents
|
||||||
an argument to be collected, the characters themselves indicate
|
an argument to be collected, and the characters themselves indicate
|
||||||
the type of the argument. Currently supported arguments are:
|
the type of the argument. Currently supported arguments are:
|
||||||
<variablelist>
|
<variablelist>
|
||||||
<varlistentry><term></term><listitem><para>
|
<varlistentry><term></term><listitem><para>
|
||||||
@ -312,14 +312,14 @@ to serve as a container for values of a type.
|
|||||||
'p' - Pointers. passed as collect_values[].v_pointer.
|
'p' - Pointers. passed as collect_values[].v_pointer.
|
||||||
</para></listitem></varlistentry>
|
</para></listitem></varlistentry>
|
||||||
</variablelist>
|
</variablelist>
|
||||||
It should be noted, that for variable argument list construction,
|
It should be noted that for variable argument list construction,
|
||||||
ANSI C promotes every type smaller than an integer to an int, and
|
ANSI C promotes every type smaller than an integer to an int, and
|
||||||
floats to doubles. So for collection of short int or char, 'i'
|
floats to doubles. So for collection of short int or char, 'i'
|
||||||
needs to be used, and for collection of floats 'd'.
|
needs to be used, and for collection of floats 'd'.
|
||||||
@collect_value: The collect_value() function is responsible for converting the
|
@collect_value: The collect_value() function is responsible for converting the
|
||||||
values collected from a variable argument list into contents
|
values collected from a variable argument list into contents
|
||||||
suitable for storage in a GValue. This function should setup
|
suitable for storage in a GValue. This function should setup
|
||||||
@value similar to value_init(), e.g. for a string value that
|
@value similar to value_init(); e.g. for a string value that
|
||||||
does not allow %NULL pointers, it needs to either spew an error,
|
does not allow %NULL pointers, it needs to either spew an error,
|
||||||
or do an implicit conversion by storing an empty string.
|
or do an implicit conversion by storing an empty string.
|
||||||
The @value passed in to this function has a zero-filled data
|
The @value passed in to this function has a zero-filled data
|
||||||
@ -329,8 +329,8 @@ to serve as a container for values of a type.
|
|||||||
and @collect_values is an array of unions #GTypeCValue with
|
and @collect_values is an array of unions #GTypeCValue with
|
||||||
length @n_collect_values, containing the collected values
|
length @n_collect_values, containing the collected values
|
||||||
according to @collect_format.
|
according to @collect_format.
|
||||||
@collect_flags is an argument provided as a hint by the caller,
|
@collect_flags is an argument provided as a hint by the caller.
|
||||||
which may contain the flag #G_VALUE_NOCOPY_CONTENTS indicating,
|
It may contain the flag #G_VALUE_NOCOPY_CONTENTS indicating,
|
||||||
that the collected value contents may be considered "static"
|
that the collected value contents may be considered "static"
|
||||||
for the duration of the @value lifetime.
|
for the duration of the @value lifetime.
|
||||||
Thus an extra copy of the contents stored in @collect_values is
|
Thus an extra copy of the contents stored in @collect_values is
|
||||||
@ -376,8 +376,8 @@ to serve as a container for values of a type.
|
|||||||
The reference count for valid objects is always incremented,
|
The reference count for valid objects is always incremented,
|
||||||
regardless of @collect_flags. For invalid objects, the example
|
regardless of @collect_flags. For invalid objects, the example
|
||||||
returns a newly allocated string without altering @value.
|
returns a newly allocated string without altering @value.
|
||||||
Upon success, collect_value() needs to return %NULL, if however
|
Upon success, collect_value() needs to return %NULL. If, however,
|
||||||
a malicious condition occurred, collect_value() may spew an
|
an error condition occurred, collect_value() may spew an
|
||||||
error by returning a newly allocated non-%NULL string, giving
|
error by returning a newly allocated non-%NULL string, giving
|
||||||
a suitable description of the error condition.
|
a suitable description of the error condition.
|
||||||
The calling code makes no assumptions about the @value
|
The calling code makes no assumptions about the @value
|
||||||
@ -415,7 +415,7 @@ to serve as a container for values of a type.
|
|||||||
|
|
||||||
}
|
}
|
||||||
</programlisting>
|
</programlisting>
|
||||||
And an exemplary version of lcopy_value() for
|
And an illustrative version of lcopy_value() for
|
||||||
reference-counted types:
|
reference-counted types:
|
||||||
<programlisting>
|
<programlisting>
|
||||||
{
|
{
|
||||||
@ -666,7 +666,7 @@ Return the corresponding quark of the type IDs name.
|
|||||||
|
|
||||||
<!-- ##### FUNCTION g_type_from_name ##### -->
|
<!-- ##### FUNCTION g_type_from_name ##### -->
|
||||||
<para>
|
<para>
|
||||||
Lookup the type ID from a given type name, returns 0 if no type has been registered under this name
|
Lookup the type ID from a given type name, returning 0 if no type has been registered under this name
|
||||||
(this is the preferred method to find out by name whether a specific type has been registered yet).
|
(this is the preferred method to find out by name whether a specific type has been registered yet).
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
@ -734,7 +734,7 @@ exist already.
|
|||||||
<!-- ##### FUNCTION g_type_class_peek ##### -->
|
<!-- ##### FUNCTION g_type_class_peek ##### -->
|
||||||
<para>
|
<para>
|
||||||
This function is essentially the same as g_type_class_ref(), except that
|
This function is essentially the same as g_type_class_ref(), except that
|
||||||
the classes reference count isn't incremented. Therefore, this function
|
the classes reference count isn't incremented. As a consequence, this function
|
||||||
may return %NULL if the class of the type passed in does not currently
|
may return %NULL if the class of the type passed in does not currently
|
||||||
exist (hasn't been referenced before).
|
exist (hasn't been referenced before).
|
||||||
</para>
|
</para>
|
||||||
@ -769,9 +769,9 @@ class pointer after g_type_class_unref() are invalid.
|
|||||||
|
|
||||||
<!-- ##### FUNCTION g_type_class_peek_parent ##### -->
|
<!-- ##### FUNCTION g_type_class_peek_parent ##### -->
|
||||||
<para>
|
<para>
|
||||||
This is a convenience function, often needed in class initializers.
|
This is a convenience function often needed in class initializers.
|
||||||
It essentially takes the immediate parent type of the class passed in,
|
It returns the class structure of the immediate parent type of the class passed in.
|
||||||
and returns the class structure thereof. Since derived classes hold
|
Since derived classes hold
|
||||||
a reference count on their parent classes as long as they are instantiated,
|
a reference count on their parent classes as long as they are instantiated,
|
||||||
the returned class will always exist. This function is essentially
|
the returned class will always exist. This function is essentially
|
||||||
equivalent to:
|
equivalent to:
|
||||||
@ -886,7 +886,7 @@ its default interface vtable.
|
|||||||
</para>
|
</para>
|
||||||
|
|
||||||
@g_type: an interface type
|
@g_type: an interface type
|
||||||
@Returns: the default vtable for the interface; or %NULL
|
@Returns: the default vtable for the interface, or %NULL
|
||||||
if the type is not currently in use.
|
if the type is not currently in use.
|
||||||
@Since: 2.4
|
@Since: 2.4
|
||||||
|
|
||||||
@ -993,7 +993,7 @@ A callback function used by the type system to do base initialization
|
|||||||
of the class structures of derived types. It is called as part of the
|
of the class structures of derived types. It is called as part of the
|
||||||
initialization process of all derived classes and should reallocate
|
initialization process of all derived classes and should reallocate
|
||||||
or reset all dynamic class members copied over from the parent class.
|
or reset all dynamic class members copied over from the parent class.
|
||||||
Therefore class members, e.g. strings, that are not sufficiently
|
For example, class members (such as strings) that are not sufficiently
|
||||||
handled by a plain memory copy of the parent class into the derived class
|
handled by a plain memory copy of the parent class into the derived class
|
||||||
have to be altered. See GClassInitFunc() for a discussion of the class
|
have to be altered. See GClassInitFunc() for a discussion of the class
|
||||||
intialization process.
|
intialization process.
|
||||||
@ -1097,8 +1097,8 @@ Initialization of TypeBClass will first cause initialization of
|
|||||||
TypeAClass (derived classes reference their parent classes, see
|
TypeAClass (derived classes reference their parent classes, see
|
||||||
g_type_class_ref() on this).
|
g_type_class_ref() on this).
|
||||||
Initialization of TypeAClass roughly involves zero-initializing its fields,
|
Initialization of TypeAClass roughly involves zero-initializing its fields,
|
||||||
then calling its GBaseInitFunc() type_a_base_class_init() that allocates
|
then calling its GBaseInitFunc() type_a_base_class_init() to allocate
|
||||||
its dynamic members (dynamic_string) and finally calling its GClassInitFunc()
|
its dynamic members (dynamic_string), and finally calling its GClassInitFunc()
|
||||||
type_a_class_init() to initialize its static members (static_integer).
|
type_a_class_init() to initialize its static members (static_integer).
|
||||||
The first step in the initialization process of TypeBClass is then
|
The first step in the initialization process of TypeBClass is then
|
||||||
a plain memory copy of the contents of TypeAClass into TypeBClass and
|
a plain memory copy of the contents of TypeAClass into TypeBClass and
|
||||||
@ -1141,7 +1141,7 @@ A callback function used by the type system to initialize a new
|
|||||||
instance of a type. This function initializes all instance members and
|
instance of a type. This function initializes all instance members and
|
||||||
allocates any resources required by it.
|
allocates any resources required by it.
|
||||||
Initialization of a derived instance involves calling all its parent
|
Initialization of a derived instance involves calling all its parent
|
||||||
types instance initializers, therefore the class member of the instance
|
types instance initializers, so the class member of the instance
|
||||||
is altered during its initialization to always point to the class that
|
is altered during its initialization to always point to the class that
|
||||||
belongs to the type the current initializer was introduced for.
|
belongs to the type the current initializer was introduced for.
|
||||||
</para>
|
</para>
|
||||||
@ -1223,7 +1223,7 @@ instances (if not abstract). The value of @flags determines the nature
|
|||||||
(e.g. abstract or not) of the type.
|
(e.g. abstract or not) of the type.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
@parent_type: Type which this type will be derived from.
|
@parent_type: Type from which this type will be derived.
|
||||||
@type_name: 0-terminated string used as the name of the new type.
|
@type_name: 0-terminated string used as the name of the new type.
|
||||||
@info: The #GTypeInfo structure for this type.
|
@info: The #GTypeInfo structure for this type.
|
||||||
@flags: Bitwise combination of #GTypeFlags values.
|
@flags: Bitwise combination of #GTypeFlags values.
|
||||||
@ -1238,7 +1238,7 @@ abstract or not) of the type. It works by filling a #GTypeInfo
|
|||||||
struct and calling g_type_info_register_static().
|
struct and calling g_type_info_register_static().
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
@parent_type: Type which this type will be derived from.
|
@parent_type: Type from which this type will be derived.
|
||||||
@type_name: 0-terminated string used as the name of the new type.
|
@type_name: 0-terminated string used as the name of the new type.
|
||||||
@class_size: Size of the class structure (see #GTypeInfo)
|
@class_size: Size of the class structure (see #GTypeInfo)
|
||||||
@class_init: Location of the class initialization function (see #GTypeInfo)
|
@class_init: Location of the class initialization function (see #GTypeInfo)
|
||||||
@ -1258,7 +1258,7 @@ instances (if not abstract). The value of @flags determines the nature
|
|||||||
(e.g. abstract or not) of the type.
|
(e.g. abstract or not) of the type.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
@parent_type: Type which this type will be derived from.
|
@parent_type: Type from which this type will be derived.
|
||||||
@type_name: 0-terminated string used as the name of the new type.
|
@type_name: 0-terminated string used as the name of the new type.
|
||||||
@plugin: The #GTypePlugin structure to retrieve the #GTypeInfo from.
|
@plugin: The #GTypePlugin structure to retrieve the #GTypeInfo from.
|
||||||
@flags: Bitwise combination of #GTypeFlags values.
|
@flags: Bitwise combination of #GTypeFlags values.
|
||||||
@ -1373,7 +1373,7 @@ use G_TYPE_FUNDAMENTAL() instead.
|
|||||||
<para>
|
<para>
|
||||||
Creates and initializes an instance of @type if @type is valid and can
|
Creates and initializes an instance of @type if @type is valid and can
|
||||||
be instantiated. The type system only performs basic allocation and
|
be instantiated. The type system only performs basic allocation and
|
||||||
structure setups for instances, actual instance creation should happen
|
structure setups for instances: actual instance creation should happen
|
||||||
through functions supplied by the type's fundamental type implementation.
|
through functions supplied by the type's fundamental type implementation.
|
||||||
So use of g_type_create_instance() is reserved for implementators of
|
So use of g_type_create_instance() is reserved for implementators of
|
||||||
fundamental types only. E.g. instances of the #GObject hierarchy
|
fundamental types only. E.g. instances of the #GObject hierarchy
|
||||||
@ -1442,8 +1442,8 @@ otherwise.
|
|||||||
<!-- ##### FUNCTION g_type_add_interface_check ##### -->
|
<!-- ##### FUNCTION g_type_add_interface_check ##### -->
|
||||||
<para>
|
<para>
|
||||||
Adds a function to be called after an interface vtable is
|
Adds a function to be called after an interface vtable is
|
||||||
initialized for any class. That is, after the @interface_init
|
initialized for any class (i.e. after the @interface_init
|
||||||
member of #GInterfaceInfo has been called.
|
member of #GInterfaceInfo has been called).
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
This function is useful when you want to check an invariant
|
This function is useful when you want to check an invariant
|
||||||
@ -1484,7 +1484,7 @@ See g_type_add_interface_check().
|
|||||||
<!-- ##### FUNCTION g_type_value_table_peek ##### -->
|
<!-- ##### FUNCTION g_type_value_table_peek ##### -->
|
||||||
<para>
|
<para>
|
||||||
Returns the location of the #GTypeValueTable associated with @type.
|
Returns the location of the #GTypeValueTable associated with @type.
|
||||||
<emphasis>Note, this function should only be used from source code
|
<emphasis>Note that this function should only be used from source code
|
||||||
that implements or has internal knowledge of the implementation of
|
that implements or has internal knowledge of the implementation of
|
||||||
@type.</emphasis>
|
@type.</emphasis>
|
||||||
</para>
|
</para>
|
||||||
@ -1644,7 +1644,7 @@ init functions.
|
|||||||
|
|
||||||
<!-- ##### MACRO G_TYPE_INVALID ##### -->
|
<!-- ##### MACRO G_TYPE_INVALID ##### -->
|
||||||
<para>
|
<para>
|
||||||
An invalid #GType, used as error return value in some functions which return
|
An invalid #GType used as error return value in some functions which return
|
||||||
a #GType.
|
a #GType.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user