Commit Graph

60 Commits

Author SHA1 Message Date
Руслан Ижбулатов
e47904a26f Use g_abort() instead of abort() where possible
https://bugzilla.gnome.org/show_bug.cgi?id=665446
2016-04-27 13:17:28 +00:00
Руслан Ижбулатов
e118856430 Add g_system_thread_set_name() implementation for W32 threads
This works by using semi-documented[1] exception to tell the debugger
that a thread needs to have its name changed.

If this exception is not caught and handled by something, it will crash
the process, so we need to set up our own handler in case there's no
debugger attached or the debugger can't handle this type of exception.

Since SEH is not supported by gcc on i686 (at the moment), we need to use VEH
instead. For completeness the MSVC-oriented code still uses SEH, although
there is no reason why it shouldn't work with the VEH variant used by MinGW.

VEH handler has to be set up somewhere (g_thread_win32_init () works nicely)
and removed once it's not needed (g_thread_win32_process_detach () is added
expressly for that purpose). Note that g_thread_win32_process_detach() is
only called when glib is unloaded by FreeLibrary(), not when glib-using
process is terminating.

This exception is known to work with WinDbg, and adding support for it into
GDB proved to be feasible (GDB patch will be sent upstream, eventually).

[1] https://msdn.microsoft.com/en-us/library/xcb2z8hs%28v=vs.71%29.aspx

https://bugzilla.gnome.org/show_bug.cgi?id=747478
2016-04-26 10:40:07 +00:00
Daniel Mustieles
078dbda148 Updated FSF's address 2014-01-31 14:31:55 +01:00
Ryan Lortie
3cefb7248a Revert two errant commits to GMutex, etc.
This reverts commits dfbac178bd and
56348210f3.

These two commits introduce undesirable behaviour and were made with no
apparent approval from anybody at all, and without reference to a bug or
mailing list discussion.
2013-07-01 23:30:47 -04:00
Jeffrey Stedfast
dfbac178bd Finish the previous fix for GMutex, GRecMutex, GRWLock and GCond 2013-06-30 14:02:38 -04: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
Dan Winship
b8c13a01b6 win32: misc warning fixes
https://bugzilla.gnome.org/show_bug.cgi?id=688109
2012-11-15 14:19:06 -05:00
Dan Winship
daf78764e5 gthread-win32: update for g_get_monotonic_time() changes
g_cond_wait_until() was calling GetSystemTimeAsFileTime() to get the
current time, which is no longer what g_get_monotonic_time() returns.

https://bugzilla.gnome.org/show_bug.cgi?id=669329
2012-02-09 06:48:12 -05:00
rodrigorivascosta
1b03377442 Bug 666551-Fix a few dangling pointers
When removing an item from the list, check the next one's my_owner,
and fix it accordingly. And take this case into account when last
of the list is deleted.

Also, assign NULL to 'my_owner' in g_thread_xp_WakeConditionVariable.
2011-12-22 10:51:31 +08:00
Ryan Lortie
541693f42d winxp threads: fix some condition variable races
There are some races in the condition variable emulation code for
Windows XP with respect to timeouts while waiting.

First, in the event of a timeout, we never remove the waiter from the
condition variable.  This can cause crashes later.  That problem was
found by Rodrigo Rivas Costa.

Second, if the waiting thread times out and exits just as we were about
to call SetEvent() on its waiter event, we could end up trying to access
the waiter after it was closed/freed.  We need to hold on to the lock a
little bit longer to ensure that that's not possible.

https://bugzilla.gnome.org/show_bug.cgi?id=666551
2011-12-19 17:40:08 -05:00
Ryan Lortie
11015f1652 windows XP threads: fix hilariously obvious race
I tried to do a double-checked lock without the double check.

Rodrigo Rivas Costa caught the problem and suggested the (obviously
correct) fix.

https://bugzilla.gnome.org/show_bug.cgi?id=666296
2011-12-16 10:54:42 -05:00
Alexander Larsson
41b8ce7100 win32: Remove some debug spew on startup
This is not needed anymore and was causing problems for pkg-config.
2011-11-03 17:27:08 +01:00
Alexander Larsson
cf3f1b026b Actually Don't define GLIB_COMPILATION in libgthread
Last commit was wrong, fixing it up
2011-10-18 14:15:07 +02:00
Alexander Larsson
be770969e9 Don't define GLIB_COMPILATION in libgthread
This was turning all the GLIB_VARs in the glib headers into
dllexports on windows, causing all sort of nastiness. libgthread is
mostly empty now anyway, so we don't need any GLIB_COMPILATION like
flag.
2011-10-18 13:34:06 +02:00
Matthias Clasen
2f71118e78 More include cleanups 2011-10-17 02:14:39 -04:00
Ryan Lortie
4033c616ff GCond: use monotonic time for timed waits
Switch GCond to using monotonic time for timed waits by introducing a
new API based on monotonic time in a gint64: g_cond_wait_until().

Deprecate the old API based on wallclock time in a GTimeVal.

Fix up the gtk-doc for GCond while we're at it: update the examples to
use static-allocated GCond and GMutex and clarify some things a bit.
Also explain the rationale behind using an absolute time instead of a
relative time.
2011-10-13 23:44: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
45736d33bb win32 threads: simplify
Merge the GThreadData with the GThreadWin32 struct.  Drop the extra TLS
variable.

Close the handle on _free(), which means that there is no leak if
g_system_thread_join() isn't called.

Remove all internal concept of joinability.
2011-10-12 23:22:31 -04:00
Ryan Lortie
e0c9757b9b win32 threads: use our own data, not system_thread
Stop using the generic system_thread field in GRealThread.  Use our own
pointer instead.
2011-10-12 22:53:52 -04:00
Ryan Lortie
67e28068e1 win32: fix function name clash 2011-10-12 22:49:39 -04:00
Ryan Lortie
2f5486f020 thread creation: Simplify error handling
Instead of always returning non-NULL and finding out about errors via
the GError*, return NULL from the backend in the event of an error.
2011-10-12 22:43:22 -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
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
47e20ed3ac thread: remove GSystemThread assign/equal
These are no longer in use.
2011-10-12 18:24:48 -04:00
Ryan Lortie
f1512917e6 win32: stop leaking GPrivate data
Instead of running the GPrivate destructors from our thread proxy code,
run it from the DllMain handler for the DLL_THREAD_DETACH case.

This should ensure that thread-local data is free at the exit of all
threads -- not just the ones we created for ourselves.

https://bugzilla.gnome.org/show_bug.cgi?id=660745
2011-10-04 16:08:27 -04:00
Ryan Lortie
2e5cb6f522 win32 fixes from g_thread_init() deprecation
I can't even begin to imagine how these fell through the cracks...
2011-10-04 15:44:48 -04:00
Ryan Lortie
c5634df6d3 locks: change the ABI just a bit
Add a little bit more room in the ABI for our synchronisation primatives
since we're going to need it when we add native implementations on
Linux.

Also: rename the pointer field and add /*< private >*/ annotations.
2011-10-02 22:33:11 -04: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
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
6f71151823 win32: fix GPrivate fallout
Fix minor mistake in win32 GPrivate code.
2011-10-02 21:31:45 -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
Ryan Lortie
fdc594e963 winxp threads: detect SRWLock emulation reentrancy
We lack SRWLock on Windows XP, so we use CRITICAL_SECTION to emulate it
there.  SRWLock is non-recursive, but CRITICAL_SECTION will happily
allow itself to be acquired multiple times by the same thread.

We need to detect if our second acquire succeeded because of the
recursive nature of CRITICAL_SECTION.  In the case of a _lock()
operation, we would normally have deadlocked, so abort.  In the case of
a _trylock() operation, we need to ensure that FALSE is properly
returned.

Problem caught by Matthias Clasen and Chun-wei Fan.

https://bugzilla.gnome.org/show_bug.cgi?id=660096
2011-09-26 08:54:51 -04:00
Ryan Lortie
ad187e3a9b Add a new recursive mutex type, GRecMutex
This is implemented using the native facilities of each platform instead
of manually.
2011-09-21 16:09:04 -04:00
Ryan Lortie
3d4102776e Add GRWLock 2011-09-21 16:09:03 -04:00
Ryan Lortie
42af8eb39d gthread: remove impl init functions 2011-09-21 16:06:56 -04:00
Ryan Lortie
2539bd007d win32: Add 'shared' support to SRWLock emulation 2011-09-21 16:06:56 -04:00
Ryan Lortie
9f42e3be1b gthread-win32: trivial condition change
Make another do-nothing change to the SRWLock emulation.
2011-09-21 16:06:56 -04:00
Ryan Lortie
391aea32f3 gthread-win32: rename a struct member
Our SRWLock is about to become a real reader/writer lock, so rename an
instance variable to prepare for that.
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
6972ed340b Merge g_thread_functions_for_glib_use
Move the now-identical copies of g_thread_functions_for_glib_use from
gthread-{posix,win32}.c back into gthread.c.
2011-09-21 16:06:55 -04:00
Ryan Lortie
3422dcfd28 NULL g_system_thread_{exit,equal} in the vtable
These were never used from gthread.h and are no longer used from
gthread.c.
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
Ryan Lortie
51d92adeee GThread: deprecate thread priorities
Thread priorities were already documented as not working on Solaris, and
they are meaningless on Linux unless the process separately requests
realtime scheduling (and even then, it appears only to work as root).

We can safely put a NULL into the vtable for set_priority since nothing
outside of gthread.c ever calls this (and that call is gone).
2011-09-21 16:06:54 -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