Commit Graph

60 Commits

Author SHA1 Message Date
Colin Walters
630fa82ed0 gthread: Rework to avoid holding a mutex half the time
This code was a persistent source of `-fsanitize=thread` errors
when I was trying to use it on OSTree.

The problem is that while I think this code is functionally correct,
we hold a mutex during the writes, but not the reads, and TSAN (IMO
correctly) flags that.

Reading this, I don't see a reason we need a mutex at all.  At the
cost of some small code duplication between posix/win32, we can just
pass the data we need down into each implementation.  This ends up
being notably cleaner I think than the awkward "lock/unlock to
serialize" dance.

(Minor review changes made by Philip Withnall <withnall@endlessm.com>.)

https://gitlab.gnome.org/GNOME/glib/issues/1224
2019-01-31 13:19:29 +00:00
Philip Withnall
f6caeb6d1a gthread: Add g_private_set_alloc0() internal convenience API
This is a wrapper around g_private_set() which allocates the desired
amount of memory for the caller and calls g_private_set() on it.

This is intended to make it easier to suppress Valgrind warnings about
leaked memory, since g_private_set() is typically used to make one-time
per-thread allocations. We can now just add a blanket suppression rule
for any allocations inside g_private_set_alloc0().

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-01-07 18:54:17 +00:00
Sébastien Wilmet
f9faac7661 glib/: LGPLv2+ -> LGPLv2.1+
All glib/*.{c,h} files have been processed, as well as gtester-report.

12 of those files are not licensed under LGPL:

	gbsearcharray.h
	gconstructor.h
	glibintl.h
	gmirroringtable.h
	gscripttable.h
	gtranslit-data.h
	gunibreak.h
	gunichartables.h
	gunicomp.h
	gunidecomp.h
	valgrind.h
	win_iconv.c

Some of them are generated files, some are licensed under a BSD-style
license and win_iconv.c is in the public domain.

Sub-directories inside glib/:

	deprecated/: processed in a previous commit
	glib-mirroring-tab/: already LGPLv2.1+
	gnulib/: not modified, the code is copied from gnulib
	libcharset/: a copy
	pcre/: a copy
	tests/: processed in a previous commit

https://bugzilla.gnome.org/show_bug.cgi?id=776504
2017-05-24 11:58:19 +02:00
Sébastien Wilmet
f60590534d License headers: "the Gnome Library" -> "this library"
Harmonize a little the license headers. In most of the license headers
in GLib, it is "this library".

It is also what is explained at:
https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html#SEC4
"How to Apply These Terms to Your New Libraries"

https://bugzilla.gnome.org/show_bug.cgi?id=776586
2017-01-04 19:12:56 +01:00
Daniel Mustieles
078dbda148 Updated FSF's address 2014-01-31 14:31:55 +01:00
Colin Walters
6f8f1f7097 Remove most use of G_GNUC_INTERNAL
Now that we use an explicit list of symbols to export, the
G_GNUC_INTERNAL is redundant.

https://bugzilla.gnome.org/show_bug.cgi?id=688681
2013-01-18 13:03:28 -05:00
Matthias Clasen
7c0ee79e34 GThread: handle thread names safely
Avoid a race condition where the string may be freed before
the new thread got around to using it. Also add a test for
thread names.

https://bugzilla.gnome.org/show_bug.cgi?id=663381
2011-11-14 22:18:13 -05:00
Ryan Lortie
62fe053268 Revert "make struct _GThread private"
This reverts commit d904612100.

glibmm touches the contents of GThread, so this broke their build.
2011-10-13 09:00:54 -04:00
Ryan Lortie
d904612100 make struct _GThread private
Hide the definition of struct _GThread in gthreadprivate.h for now.

This is possibly an API break -- although the structure contents were
undocumented and it was not safe to access them in a meaningful way,
someone may have tried to do it anyway.  We'll leave it here for a while
to see if it causes any problems.

Avoid merging its contents with GRealThread for now, just incase we need
to expose it again.
2011-10-13 01:34:08 -04:00
Ryan Lortie
b1cc2579c1 tidy up gthreadprivate.h
Remove some unused includes, too.
2011-10-13 01:22:51 -04:00
Ryan Lortie
015f4b4513 thread: nuke the concept of 'joinable'
And remove the 'joinable' argument from g_thread_new() and
g_thread_new_full().

Change the wording in the docs.  Clarify expectations for
(deprecated) g_thread_create().
2011-10-13 00:43:33 -04:00
Ryan Lortie
62be9365d9 thread: simplify 'free' process
GThread is freed using some very slightly confusing logic: if the thread
was created 'joinable', then the structure is freed after the join()
call succeeds (since we know the thread has exited).  If the thread was
not created 'joinable' then the free is when the thread quits (since we
know 'join' will not be called later).

Move to a straight ref-counting system: 1 ref owned by the thread and 1
extra ref if the thread is joinable.  Both thread quit and joining will
decrease the refcount by 1.
2011-10-13 00:18:17 -04:00
Ryan Lortie
becb4b820f remove 'joinable' parameter to backends
Both backends are now oblivious to the concept of joinability, so don't
bother passing the parameter.
2011-10-13 00:01:28 -04:00
Ryan Lortie
dfd466979b Only g_system_thread_free() our own threads
Keep track of if we created a thread for ourselves or if the GThread*
was allocated in response to g_thread_self() on a previously-unknown
thread.

Only call g_system_thread_free() in the first case.
2011-10-12 23:19:06 -04:00
Ryan Lortie
a5800ef336 Finish killing off GSystemThread 2011-10-12 23:04:15 -04:00
Ryan Lortie
e14a3746db Combine g_sytem_thread_{new,create}() 2011-10-12 22:43:22 -04:00
Ryan Lortie
a3f82c847f g_system_thread_create: drop 'data' arg
Since it's now always the same as the 'thread' arg.
2011-10-12 22:43:22 -04:00
Ryan Lortie
3237eaf5d5 g_system_thread_create: SystemThread -> RealThread
Just like g_system_thread_wait().
2011-10-12 22:43:22 -04:00
Ryan Lortie
dc3727cc5f g_system_thread_join: rename to _wait() 2011-10-12 22:15:46 -04:00
Ryan Lortie
4bb968e335 g_system_thread_join: take GRealThread *
Make g_system_thread_join take the GRealThread* instead of a
GSystemThread.
2011-10-12 22:14:38 -04:00
Ryan Lortie
e064c9bfec thread: delegate allocation of GThread to backends
Add g_system_thread_new() and g_system_thread_free(), implemented with
GSlice.  Use those instead of g_new() and g_free().

Presently, the backends are both doing the same thing.  This will change
soon.
2011-10-12 22:04:39 -04:00
Ryan Lortie
d537726ded thread: stop sharing g_once_mutex
Unrelated code shouldn't be sharing the same mutex for no good reason --
particularly not across a file boundary.
2011-10-12 21:48:02 -04:00
Ryan Lortie
8cff9c57b1 thread: drop thread setup function hackery
Use a custom proxy function for the deprecated case instead.

Now GRealThread has strictly zero members dedicated to deprecated
functionality.
2011-10-12 21:48:02 -04:00
Ryan Lortie
39ae59c47e thread: Delete g_system_thread_self()
It's no longer used for anything at all.
2011-10-12 18:35:45 -04:00
Ryan Lortie
1f34ef4117 missed from last commit 2011-10-12 18:25:40 -04:00
Ryan Lortie
47e20ed3ac thread: remove GSystemThread assign/equal
These are no longer in use.
2011-10-12 18:24:48 -04:00
Ryan Lortie
903705edf2 thread: remove dead decl from gthreadprivate.h
This function hasn't existed for a while...
2011-10-12 18:23:20 -04:00
Ryan Lortie
ed35d2719b thread: Remove the zero_thread
This was only used for redundant assertion checks.
2011-10-12 18:22:31 -04:00
Ryan Lortie
96904b6790 thread: use GSList for g_thread_foreach list
...instead of having a 'next' pointer in the GThread struct.

Now GThread contains no fields used only by deprecated code (except for
the rather generic setup function field).
2011-10-12 17:05:50 -04:00
Ryan Lortie
9ca4f14264 thread: call g_enumerable_thread_add via callback
There are no longer any functions defined in gthread-deprecated.c called
from gthread.c.
2011-10-12 17:05:50 -04:00
Ryan Lortie
f788a2e5e1 thread: use GPrivate for enumerable threads
Use a GPrivate to track the destruction of enumerable threads and remove
them from the list.
2011-10-12 17:05:50 -04:00
Ryan Lortie
9bb5a55bda GStaticPrivate: implement via GPrivate
Thanks to the modifications in 3d4846d923,
GStaticPrivate is not so directly tied in with GThread anymore.  It is
now a simple matter to cut it out completely by using a GPrivate to
store the GArray instead of storing it in the GThread.
2011-10-12 00:17:49 -04:00
John Ralls
edcac1ee41 Bug 661129: Duplicate symbols zero_thread and g_once_mutex on OSX 2011-10-07 09:51:12 -07: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
Matthias Clasen
3d4846d923 Deprecate GStaticPrivate and g_thread_foreach
This commit moves GStaticPrivate, g_thread_foreach and all
related functions and variables to gthread-deprecated.c. We
introduce some internal API to make this possible.

g_thread_foreach is not a very useful function, since there is
virtually nothing you can do with a GThread*, and implementing
it requires us to keep a list of threads around.

GStaticPrivate has been made redundant by adding comparable
capabilities to GPrivate.

https://bugzilla.gnome.org/show_bug.cgi?id=660635
2011-10-02 22:11:59 -04:00
Matthias Clasen
12287c8cc7 Don't put threads created with g_thread_new() on the list
This lets us avoid the overhead of maintaining the global
list in the non-deprecated case.

https://bugzilla.gnome.org/show_bug.cgi?id=660635
2011-10-02 22:11:58 -04:00
Matthias Clasen
1909d2398a Make thread names useful in a debugger
Associate the name with the system thread, so that debuggers
can see it. This is currently only implemented for Linux, using
prctl.

https://bugzilla.gnome.org/show_bug.cgi?id=660635
2011-10-02 22:11:58 -04:00
Ryan Lortie
8e43470c38 Stop dithering over GPrivate
Take out the half-private g_private_init() stuff and replace it with a
G_PRIVATE_INIT macro that allows specifying a GDestroyNotify.

Expose the GPrivate structure in a public header.

Add a g_private_replace() to (sort of) match the functionality of
g_static_mutex_set().

Improve the documentation.

Deprecate g_private_new().
2011-10-02 20:04:03 -04:00
Matthias Clasen
0ea89987e2 Move deprecated GThread functions to a separate file 2011-09-25 01:01:00 -04:00
Chun-wei Fan
8f340e2d75 Fix warning/error C4013 (implicit declarations)
-Include gthread.h in gregex.c as g_once_init_enter and g_once_init_leave
 are used.
-Define prototype for g_thread_DllMain in gthreadprivate.h for Windows
2011-09-25 09:07:59 +08:00
Ryan Lortie
42af8eb39d gthread: remove impl init functions 2011-09-21 16:06:56 -04:00
Ryan Lortie
b2c1364ab2 g_system_thread_create: drop unused args
The 'bound' and 'priority' arguments are no longer in use, so drop them.
2011-09-21 16:06:55 -04:00
Ryan Lortie
7a69d46dc5 GSystemThread: port 'self' 'join' and 'create'
Switch 'self' 'join' and 'create' from using the vtable to being called
via normal g_system_thread_* internal API (implemented in each of
gthread-{posix,win32}.c).

Again, we can put NULL in the vtable since these were never used from
gthread.h.
2011-09-21 16:06:55 -04:00
Matthias Clasen
a10306060c Don't use the thread_exit vfunc
Instead, just have the backends implement an internal function
named g_system_thread_exit.
2011-09-21 16:06:54 -04:00
Matthias Clasen
cc7631cd19 Don't use the thread_equal vfunc anymore
Just move the g_system_thread_equal implementation into
the posix and win32 implementations, and drop some micro macro
optimization.
2011-09-21 16:06:54 -04:00
Ryan Lortie
c4a69e784e gmem: move to glib-ctor 2011-09-21 16:06:54 -04:00
Ryan Lortie
ae4419610c gslice: move initialisation to glib-ctor 2011-09-21 16:06:53 -04:00
Ryan Lortie
90679997ec Continue GPrivate rework
We remove the macros while at the same time switching all libglib users
from g_private_new() to g_private_init().  We deal with the strange
expectations of the libglib code that g_private_* should work before the
GPrivate has been initialised with a temporary shim.
2011-09-21 16:06:53 -04:00
Ryan Lortie
b0d83576e2 Rework GPrivate
- expose the structure types for GLib internal use only

 - avoid infinite recursion hazards by ensuring that GPrivate never
   calls back into any other part of GLib

 - substantially rework the Windows implementation so that it never
   holds locks, contains no arbitrary limits and doesn't waste
   100*sizeof(void*) per thread

We have to keep the macro hacks for the time being since some code
inside libglib depends on it.
2011-09-21 16:06:53 -04:00
Ryan Lortie
f1494c156d Clean up l10n threading stuff
Remove the explicit thread initialisation functions for g_get_charset(),
g_get_filename_charsets() and g_get_language_names().

Add a lock around one remaining case of access to libcharset (the other
2 cases already have the lock).

Do a proper g_once_init_enter() style initialisation for the GLib
gettext functions.

https://bugzilla.gnome.org/show_bug.cgi?id=658683
2011-09-09 19:50:55 -04:00