Commit Graph

736 Commits

Author SHA1 Message Date
Edward Hervey
40bf3aa5d2 gobject: Use new G_VALUE_COLLECT_INIT variant
Makes g_object_new_valist 20% to 30% faster (against 2321e5a).

Profiled against the pan newsreader which uses a variant of simple
and complex object creation.

https://bugzilla.gnome.org/show_bug.cgi?id=603590
2010-01-13 10:16:49 +01:00
Edward Hervey
0f25115ffc gsignal: Use new G_VALUE_COLLECT_INIT variant
Makes g_signal_emit_valist from 15% to 20% faster.

Results reported from profiling the pan newsreader which uses a variant
of simple and complex signal emissions (i.e no args or various args)

https://bugzilla.gnome.org/show_bug.cgi?id=603590
2010-01-13 10:16:48 +01:00
Edward Hervey
546fc0ca33 gvaluecollector: Add variant of G_VALUE_COLLECT for most used cases.
Most callers of G_VALUE_COLLECT previously had to initialize the GValue
and then G_VALUE_COLLECT would still go through a cleanup phase.

The new variant allows passing a unitialized GValue along with a GType
and speedup the initialization/collection process.

https://bugzilla.gnome.org/show_bug.cgi?id=603590
2010-01-13 10:16:46 +01:00
Alexander Larsson
94b8613b5f Use unconditional thread calls in gio and gobject
If threads are available we always enable threads in gobject, which
means all gio/gobject code can enable the unconditional thread calls.

This is a minor optimization since we avoid a bunch of unnecessary
is-threads-enabled checks.

https://bugzilla.gnome.org/show_bug.cgi?id=606775
2010-01-12 21:37:50 +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
Kamal Mostafa
f4ccd96ea1 g_object_new(): skip varargs for simple calls
g_object_new() avoids useless varargs processing for simple calls with no
properties.  Fixes https://bugzilla.gnome.org/show_bug.cgi?id=605883
2010-01-11 15:34:41 +01:00
Haakon Sporsheim
4c55b45162 Don't do pointer arithmetics on void*
For instance MSVC doesn't like that.

Signed-off-by: Tor Lillqvist <tml@iki.fi>
2010-01-07 10:14:24 +02:00
Javier Jardón
3f5fb1ee9c [docs] Fix @title usage in "Enumeration and flags types" section 2010-01-03 23:36:44 +01:00
Pablo Castellano
0542e6dbf9 Updated .gitignore files 2010-01-03 01:24:44 +01:00
Javier Jardón
dba6cef3c9 [docs] Fix G_DEFINE_INTERFACE "Since" tag
This symbol is available since Glib 2.24, not 2.20.
2009-12-21 23:07:13 +01:00
Behdad Esfahbod
e7488ca857 [gobject] Grow gvalue transform array exponentially
Bug 589176 - Grow gvalue transform array exponentially

Reduces about 180 realloc calls during g_type_init().
2009-12-21 17:12:17 +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
Javier Jardón
9917024949 G_DEFINE_INTERFACE_* documentation is not generated
Fix the documentation: Replace "@Since:" with "Since:"

https://bugzilla.gnome.org/show_bug.cgi?id=604645
2009-12-19 02:17:33 +01:00
Dan Winship
f74c0e257f update .gitignores 2009-12-18 12:27:36 +01:00
Dan Winship
91d96350a7 Add G_DEFINE_INTERFACE
This is a macro similar to G_DEFINE_TYPE but it lets you define
interfaces rather than classes.

For discussion, see bug #320482
2009-12-01 10:44:42 +01:00
Benjamin Otte
2a78adc5e3 Only add object to list new objects when it has a custom constructor
This works around the need to take a custom mutex twice and add the
object to a GSList of objects that are currently in construction for the
common case. Only when the constructor is overwritten do we use the
previous behavior and allow things like singleton objects.

The only slightly incompatible change is that previously, it was ok to
call g_object_set() on construct-only properties while the object was
initialized. This will now fail. If that behavior is needed, setting a
custom constructor that just chains up will reenable this functionality.

https://bugzilla.gnome.org/show_bug.cgi?id=557151
2009-11-30 20:52:33 +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
83ee0d947d gobject/tests: New test for dynamic class creation/destruction
Starts 100 threads which ref/unref a dynamic class to test the recent
changes to class init/uninit.
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
Alexander Larsson
75ce4741f9 Add GAtomicArray for RCU-style lockless updates
This adds supports for a lock-less a non-shrinking growable array.
You can use it to do reads using no locks, as long as your read-code
can handle that during the read transaction the object can be modified
by another writer (but it will not change size or be freed), and you
can only trust the result once the transaction has finished successfully.

This doesn't free things like RCU normally does, instead it pushes the
memory on a free list that is reused for other atomic arrays.
2009-11-30 20:48:50 +01:00
Alexander Larsson
b35fa1994d Cast iface_init to GInterfaceInitFunc
This is in line with what all other type define macros do.

https://bugzilla.gnome.org/show_bug.cgi?id=508157
2009-11-26 12:32:36 +01:00
Alexander Larsson
7d51c96e5e Add G_IMPLEMENT_INTERFACE_DYNAMIC
Convenience macro to easy interface addition for dynamic types.

https://bugzilla.gnome.org/show_bug.cgi?id=508157
2009-11-26 11:20:18 +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
Cody Russell
855deaa578 g_object_unref racy condition can lead to crash
Store whether the object has a toggleref before decrementing the
refcount to prevent race condition when two threads simultaneously
try to unref an object with a refcount of 2.
Patch by Antoine Tremblay.

https://bugzilla.gnome.org/show_bug.cgi?id=551706
2009-10-06 12:27:12 -04:00
Edward Hervey
68b1ca0443 gobject/gtype.h: Fix _G_TYPE_CVH macro. Fixes #597194
If __val doesn't exist, we shouldn't do any other checks.
2009-10-03 16:17:17 +02:00
Alexander Larsson
1937765f9f Add fast path for construction with no params
This avoids a bunch of code and makes construction of simple objects
faster.

Object construction performance improvement:
         Non-Threaded   Threaded
Simple:           14%         5%
Complex:        -1.1%      -2.2%

Other tests stable.

https://bugzilla.gnome.org/show_bug.cgi?id=557100
2009-10-02 21:02:48 +02:00
Alexander Larsson
ffc625ec9b Don't freeze/thaw notification during construction if no properties
If the class has no properties there could be no notification anyway.
This is an important optimization for construction of simple objects.

Object construction performance improvement:
         Non-Threaded   Threaded
Simple:           84%        91%
Complex:        -1.4%      -0.6%

Other tests stable.

https://bugzilla.gnome.org/show_bug.cgi?id=557100
2009-10-02 21:02:48 +02:00
Alexander Larsson
302d13a757 Add a check that no properties are added after a class is derived
We can't support that, because that would cause the CLASS_HAS_PROPS_FLAG
class flag to not be correct.
2009-10-02 21:02:48 +02:00
Alexander Larsson
39a1fe5782 Add GObjectClass flag CLASS_HAS_PROPS_FLAG
This is set if a class or any of its parents have installed any
properties.

https://bugzilla.gnome.org/show_bug.cgi?id=557100
2009-10-02 21:02:48 +02:00
Alexander Larsson
301d52d858 Add flags member for GObjectClass
https://bugzilla.gnome.org/show_bug.cgi?id=557100
2009-10-02 21:02:48 +02:00
Alexander Larsson
af017accc5 Allocate GObjectNotifyQueue with g_slice instead of abusing g_list
This is both cleaner and faster (it avoids function calls and
zeroing the memory twice).

Object construction performance improvement:
         Non-Threaded   Threaded
Simple:           11%       1.3%
Complex:           8%         6%

Other tests stable.

https://bugzilla.gnome.org/show_bug.cgi?id=557100
2009-10-02 21:02:48 +02:00
Matthias Clasen
e9fe53980b Fix --runtime-libdir option
For stable releases, it needs to take LT_REVISION into account, not
hardcode 0.
2009-09-29 23:08:03 -04:00
Alexander Larsson
e657dee578 Use right soname for gdb autoloaded python files
We need to look at LT_REVISION too to get the right filename.
This was just hardcoded to zero before which is obviously wrong.
2009-09-28 15:48:17 +02:00
Matthias Clasen
cc95c60c69 Fix location of gdb macros
These files need to be put in a location that corresponds to the
location of the libraries, so we need to take the runtime-libdir
path into account.
2009-09-24 10:26:46 -04:00
Matthias Clasen
4c633ff0b5 2.22.0 2009-09-22 16:57:08 -04:00
Mart Raudsepp
924f1bc528 Accept -? for glib-mkenums.
Commit 789e260638 tried to add support for -?, but there is a typo
and instead -h was added when already present instead of -? for one
of the cases.
It works without this corrections, because all unrecognized options
trigger usage showing as well, but this is more correct.

This was bug 556706 originally.
2009-09-22 11:22:44 +03:00
Alexander Larsson
efe9169234 Initial support for gdb python macros
This includes support for gobject pointer pretty printing and
signal frame compression in backtraces.

https://bugzilla.gnome.org/show_bug.cgi?id=595619
2009-09-21 15:39:00 +02:00