Commit Graph

152 Commits

Author SHA1 Message Date
Matthias Clasen
599f254066 Cleanups to debug env var handling 2011-11-12 19:13:44 -05:00
Simon McVittie
5dcc502f91 Document that types are limited to 64 KiB
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=659916
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2011-10-15 17:59:35 -04:00
Ryan Lortie
47444dacc0 Deprecate g_thread_init()
Move the last few things that needed thread-safe initialisation to a
global ctor.

https://bugzilla.gnome.org/show_bug.cgi?id=660744
2011-10-04 15:31:49 -04:00
Simon McVittie
5bed8317ea Warn when classes/instances exceed the allowed size, if possible
It's impossible to check this if the library user is using
g_type_register_static, but in that case their compiler should hopefully
warn about the truncation. This fixes it for G_DEFINE_TYPE and friends,
at least.

Bug: https://bugzilla.gnome.org/show_bug.cgi?id=659916
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Colin Walters <walters@verbum.org>
2011-10-04 09:35:54 +01:00
Ryan Lortie
2a677d1370 locks: drop _INIT macros
All locks are now zero-initialised, so we can drop the G_*_INIT macros
for them.

Adjust various users around GLib accordingly and change the docs.

https://bugzilla.gnome.org/show_bug.cgi?id=659866
2011-10-02 22:33:10 -04:00
Ryan Lortie
aecec33c49 gtype: port from GStaticRWLock to GRWLock 2011-09-21 16:09:05 -04:00
Ryan Lortie
b6140c2f89 Port internal GStaticRecMutex users to GRecMutex 2011-09-21 16:09:04 -04:00
Dan Winship
5bc7729d16 Make threads mandatory
G_THREADS_ENABLED still exists, but is always defined. It is still
possible to use libglib without threads, but gobject (and everything
above it) is now guaranteed to be using threads (as, in fact, it was
before, since it was accidentally impossible to compile with
--disable-threads).

https://bugzilla.gnome.org/show_bug.cgi?id=616754
2011-09-09 12:41:55 -04:00
Ryan Lortie
9829d04be8 GObject docs: resolve broken links
Some links were broken due to typos, because functionality was removed
in GLib 2.0 or for various other reasons.  Fix up as many of them as is
reasonable.
2011-09-05 18:46:59 -04:00
Matthias Clasen
1b28408b8b Spelling fixes
Spelling fixes in comments and docs, provided by
Kjartan Maraas in bug 657336.
2011-08-29 14:49:32 -04:00
Ryan Lortie
8073759f8c Remove all uses of G_CONST_RETURN
Just use 'const'.

https://bugzilla.gnome.org/show_bug.cgi?id=644611
2011-06-09 11:15:40 -04:00
Ryan Lortie
8f21e8145c gobject: remove -DG_DISABLE_CONST_RETURNS
GObject had a few cases of depending on G_CONST_RETURN not being defined
to 'const'.  Remove those in preparation for deprecation of
G_CONST_RETURN.
2011-06-09 11:11:30 -04:00
Colin Walters
3bd3067ffc gobject: Use _ prefixing in private headers over G_GNUC_INTERNAL in public headers
This helps out gtk-doc and g-ir-scanner, and also makes much clearer
what's private versus public.

https://bugzilla.gnome.org/show_bug.cgi?id=651745
2011-06-03 12:40:01 -04:00
Colin Walters
5645c7aa41 gtype: Remove unused variable 2011-05-18 11:57:21 -04:00
Benjamin Otte
d9440687ff gobject: Speed up g_type_from_name()
The hash table used exclusively for looking up types by name used to map
quarks => types. But we can easily make it map strings => types, which
avoids the quark lookup. And that in trun avoids taking a lock and
consulting another hash table. So this change should make
g_type_from_name() roughly twice as fast.
2011-05-17 15:01:36 +02:00
Emmanuele Bassi
08f0a31289 Revert "Remove all uses of G_CONST_RETURN"
This reverts commit 36741245cc.

The removal has not been discussed, except on Bugzilla:

https://bugzilla.gnome.org/show_bug.cgi?id=644611
2011-03-15 09:03:28 +00:00
Ryan Lortie
36741245cc Remove all uses of G_CONST_RETURN
Just use 'const'.
2011-03-15 01:32:22 -04:00
Matthias Clasen
2a1eed20b4 Expand the documentation of g_type_get_qdata()
https://bugzilla.gnome.org/show_bug.cgi?id=613269
2011-02-18 22:35:49 -05:00
Pavel Holejsovsky
422a76b3cd Fix typo in GI annotation 2010-12-29 11:42:14 +01:00
Pavel Holejsovsky
562a834328 Fix typo in function annotation. 2010-12-28 11:59:58 +01:00
Pavel Holejsovsky
3955bbfde0 Add GI annotations to GType 2010-12-27 20:56:58 +01:00
Matthias Clasen
42080449d0 Add a note about size limits of private structures
Also add some assertions to check these limits, instead of
failing silently.  Bug 604479.
2010-09-03 18:11:08 -04:00
Ryan Lortie
0fc50fa5f7 gobject/: fully remove gobjectalias hacks 2010-07-07 19:40:48 -04:00
Alexander Larsson
8e41be13ef Add dtrace and systemtap support for gobject
This adds static markers and systemtap tapsets for:

* type creation
* object lifetimes (creation, ref, unref, dispose, finalize)
* signal creation and emission

Signal emissions and finalization marker have a corresponding
*_end (or *-end in dtrace) version that is when the corresponding
operation is finished.

https://bugzilla.gnome.org/show_bug.cgi?id=606044
2010-05-27 14:51:41 -04:00
Javier Jardón
0f51e99565 Fix g_type_class_add_private() documentation
This fixes commit 81e2aa941b

Fixes https://bugzilla.gnome.org/show_bug.cgi?id=614185
2010-03-29 18:17:40 +02:00
Matthias Clasen
81e2aa941b Some more doc cleanups 2010-03-26 10:11:46 -04:00
Sebastian Dröge
41383b303c Bug 612502 - Add support for class private data
This adds the two new functions g_type_add_class_private()
and g_type_class_get_private() and a convenience macro
for the getter G_TYPE_CLASS_GET_PRIVATE().
2010-03-17 15:11:00 +01:00
Benjamin Otte
63a6666ab7 Make g_type_interface_prerequisites() only return one instantiable type
Previously, the code had a heisenbug and could potentially return
superclasses, too. In fact, it was based on the behavior of malloc.

https://bugzilla.redhat.com/show_bug.cgi?id=554678
2010-02-17 08:55:14 +01:00
Benjamin Otte
fd3923aba2 Move offsets array from interface data member to TypeNode
We need to assign offsets when the interface is not yet instantiated.
2010-02-11 21:10:19 +01:00
Benjamin Otte
61b649cffd Move prerequisites out of _prot struct
Also fix the naming (including typo)
2010-02-11 21:10:19 +01:00
Benjamin Otte
11d4e59712 Move the boxed private type data to TypeNode
This way we don't need to keep a custom array that we bsearch on (and
that isn't threadsafe) but can use the gtype.c machinery that is
threadsafe. And fast, too!

https://bugzilla.gnome.org/show_bug.cgi?id=554887
2010-01-25 15:30:38 +01:00
Alexander Larsson
fa2bced1f3 Enable threads in g_type_init()
This means threads will be supported for all gobject libraries/applications
and initialized early enough to not cause any problems.

This solves the problem of libraries needing threadsafety. Previosly
they just called g_threads_init() anyway, which often works but sometimes
breaks in unexpected ways.

See this thread for more details:
http://mail.gnome.org/archives/gtk-devel-list/2009-November/msg00208.html

https://bugzilla.gnome.org/show_bug.cgi?id=606775
2010-01-12 21:37:29 +01:00
Behdad Esfahbod
ccd33a4043 Bug 501166 - Warning message says IA__g_type_init instead of g_type_init 2009-12-19 11:46:19 +01:00
Benjamin Otte
f0f32a7ef0 Remove more read locks usage
g_type_default_interface_peek() and g_type_value_table_peek() don't need
to acquire read locks anymore when they test the refcount instead of
node->data.
2009-11-30 20:52:33 +01:00
Benjamin Otte
5cac5c828b Make g_type_class_peek[_static]() not take any locks
By replacing a check for node->data with a check for NODE_REFCOUNT(node)
these functions don't require a read lock anymore.
2009-11-30 20:52:33 +01:00
Edward Hervey
35c376a8a6 Add type_data_ref_U() and use it in g_type_class_ref()
The function returns TRUE if the type was previously initialized and can
be easily reused. It returns FALSE and does not take a reference if the
type is not referenced yet.

g_type_class_ref() uses this to avoid taking locks in the common path,
which speeds up object creation a lot - in particular in multithreaded
applications.

https://bugzilla.gnome.org/show_bug.cgi?id=585375
2009-11-30 20:52:33 +01:00
Edward Hervey
5160175656 Reorganize g_type_class_ref()
Moves the first check out of the lock, as it's not required.

https://bugzilla.gnome.org/show_bug.cgi?id=585375
2009-11-30 20:52:33 +01:00
Benjamin Otte
00a4470ad0 Make ClassData->init_state atomic
This is necessary to make g_type_class_ref() lockless.

https://bugzilla.gnome.org/show_bug.cgi?id=585375

Also includes fix for:

https://bugzilla.gnome.org/show_bug.cgi?id=587892
2009-11-30 20:52:33 +01:00
Edward Hervey
4c243b1cba Make type_data_unref_U not take locks in the common case
https://bugzilla.gnome.org/show_bug.cgi?id=585375
2009-11-30 20:52:32 +01:00
Edward Hervey
5e7dba0501 Make all accesses of Node->ref_count atomic
This does not change any locking behavior at all, it just replaces
simple getters/setters of the variable with atomic versions.

The ref_count variable was kept as unsigned, even though that requires
casting for all operations, to mirror GObject->refcount.

https://bugzilla.gnome.org/show_bug.cgi?id=585375
2009-11-30 20:52:32 +01:00
Edward Hervey
2ec989902b type_data_unref_Wm => type_data_unref_U
Make the type unref function not hold any locks when called. This
makes it easier to optimize it to be atomic later.

https://bugzilla.gnome.org/show_bug.cgi?id=585375
2009-11-30 20:52:32 +01:00
Benjamin Otte
b163759320 Add a NODE_REFCOUNT getter
This is useful when moving the code to be atomic.
It also will make that patch smaller.

https://bugzilla.gnome.org/show_bug.cgi?id=585375
2009-11-30 20:52:32 +01:00
Edward Hervey
170423f924 Move setting the refcount to the end of the function
This is a safety feature for when making it atomic later.

https://bugzilla.gnome.org/show_bug.cgi?id=585375
2009-11-30 20:52:32 +01:00
Edward Hervey
f8d24e8495 Pass the TypeNode to type_data_last_unref_Wm()
Previously the GType was looked up just for calling the function
Also moves the unref functions together in the code.

https://bugzilla.gnome.org/show_bug.cgi?id=585375
2009-11-30 20:52:32 +01:00
Edward Hervey
718b476c44 Move ref_count from TypeNode->data to TypeNode
https://bugzilla.gnome.org/show_bug.cgi?id=585375
2009-11-30 20:52:32 +01:00
Alexander Larsson
69961d27a1 Implement O(1) interface lookups
Currently interface lookups are do a binary search over all the interfaces
an object implements. Its possible to do this lookup in constant time using for
instance the gcj algorighm described at:
http://gcc.gnu.org/ml/java/1999-q3/msg00377.html

This is an implementation of that based on GAtomicArray.
2009-11-30 20:52:29 +01:00
Alexander Larsson
8f27a5e621 Implement lock free interface lookup
We implement lock free interface lookup by moving the n_ifaces
counter into memory pointed to by TypeNode->iface_entries, and
then updating this in RCU-style by always copying it, modifying
the copy and then when the modification is done replace the old
pointer with g_atomic_pointer_set.

There is one additional complexity when freeing the old memory,
since the old memory region can be in use. To handle this we
don't free such memory, but put it on a free list and reuse it
later. This means that lock-free lookups must be able to
handle the memory being modified in random ways without crashing,
and at the end we verify that the memory didn't change and the
transaction is ok.

With this infrastructure the patch then implements a lock-free
version of type_lookup_iface_entry_L called type_lookup_iface_vtable_I
and use it in: g_type_interface_peek, g_type_interface_peek_parent
and type_node_check_conformities_UorL.

Using the performance tests from bug 557100 shows that the general
performance difference is negligible, but the lack of a lock for each
type check and interface vfunc call should greatly enhance threaded
scalability.
2009-11-30 20:50:21 +01:00
Benjamin Otte
ec79146572 Fix thread-safety
The n_children variable can be written when locked, while the n_supers
variable is read at any time. As they both share the same bytes,
accessing them is not threadsafe.
This patch puts them into different bytes.

Thanks to Xan Lopez and valgrind for noticing this.
2009-11-20 16:49:47 +01:00
Cody Russell
8eebc18944 GTypeModule derived class unref does not unload plugin
Correctly unref the pclass. Patch by Chris Wilson and Tim Janik.

https://bugzilla.gnome.org/show_bug.cgi?id=350200
2009-10-14 21:24:30 -05:00
Matthias Clasen
7ba9674d71 Avoid some compiler warnings. 2009-07-10 13:13:18 -04:00