Commit Graph

21332 Commits

Author SHA1 Message Date
Sebastian Dröge
78bae85d21 Fix initialization logic of GThreadPool if the first created pool is an exclusive one
Previously we would only ever run the initialization code once, but part
of it only if a non-exclusive pool was created. This caused the shared
state to be inconsistent if the first pool to be created was exclusive
and the second non-exclusive.

Fixes https://gitlab.gnome.org/GNOME/glib/issues/2012
2020-01-25 11:08:22 +02:00
Philip Withnall
ac0c0b5b28 Merge branch '1925-network-monitor-performance' into 'master'
gnetworkmonitorbase: Use a hash table for storing networks

Closes #1925

See merge request GNOME/glib!1313
2020-01-22 16:47:54 +00:00
Philip Withnall
4a488ced5d gnetworkmonitorbase: Use a hash table for storing networks
Rather than using an array, which requires a lot of iteration over it to
check whether a particular network is present. Using a hash table only
requires iteration in the can_reach() case, where we need to match a
mask in the networks array, rather than equal it.

This should improve performance for large numbers of routes.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Fixes: #1925
2020-01-22 11:14:34 +00:00
Philip Withnall
0d9d548932 Merge branch 'sizeof-member' into 'master'
Add and use g_sizeof_member() macro

See merge request GNOME/glib!1333
2020-01-22 11:07:03 +00:00
Philip Withnall
ba4e5672ea Merge branch 'wip/seb128/skip-memory-tests-if-portal-missing' into 'master'
tests: Skip GMemoryMonitor tests if xdg-desktop-portal is not available

See merge request GNOME/glib!1338
2020-01-22 08:52:20 +00:00
Sebastien Bacher
422e861633 tests: Skip GMemoryMonitor tests if xdg-desktop-portal is not available
It's useful to have glib tests passing even if you don't have a full
desktop stack available
2020-01-22 10:19:03 +02:00
Iain Lane
b876325c5f Merge branch 'wip/laney/skip-memory-monitor-tests-if-dbusmock-is-too-old' into 'master'
tests: Skip GMemoryMonitor tests if the dbusmock template is not available

See merge request GNOME/glib!1296
2020-01-22 08:13:04 +00:00
Iain Lane
0d4f1a9b21
tests: Skip GMemoryMonitor tests if the dbusmock template is not available
This template is not currently in any released version of dbusmock.
2020-01-22 07:41:17 +00:00
Marc-André Lureau
fd61a21ecd Add and use G_SIZEOF_MEMBER() macro
A convenient macro present in the Linux kernel, named FIELD_SIZE() there.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2020-01-21 19:54:55 +04:00
Philip Withnall
b413c50dcd 2.63.4
Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-01-21 12:41:48 +00:00
Philip Withnall
4c1b675eac Merge branch '1232-object-manager-client-signal-race' into 'master'
gdbusobjectmanagerclient: Fix race in signal emission

Closes #1232

See merge request GNOME/glib!1335
2020-01-21 11:52:30 +00:00
Philip Withnall
5d32b99d0c Merge branch '604-dbus-name-watching-simplification' into 'master'
gdbusnamewatching: Check cancellation of a watch before calling back

Closes #604

See merge request GNOME/glib!1336
2020-01-21 11:15:36 +00:00
Philip Withnall
5853d5c8e4 gdbusobjectmanagerclient: Fix race in signal emission
Following on from #978, it seems that #1232 is another instance of the
same problem: signals emitted across threads can’t guarantee their user
data is kept alive between committing to emitting the signal and
actually invoking the callback in the relevant thread.

Fix that by using weak refs to the `GDBusObjectManagerClient` as the
user data for its signals, rather than no refs. Strong refs would create
an unbreakable reference count cycle.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Fixes: #1232
2020-01-21 11:07:21 +00:00
Philip Withnall
5c7a88e972 Merge branch '978-dbus-signal-emission-race' into 'master'
Fix race between D-Bus signal emission and unsubscription

Closes #978

See merge request GNOME/glib!1332
2020-01-21 10:43:39 +00:00
Philip Withnall
73a33e5019 gdbusnamewatching: Check cancellation of a watch before calling back
It’s possible for `g_bus_unwatch_name()` to be called after a
name-appeared or name-vanished handler has been scheduled to be called
in another thread, but before that callback is actually invoked. If so,
the subscribing thread will receive a callback after it’s called
`g_bus_unwatch_name()`, which is unexpected and could cause bugs.

Double-check `client->cancelled` in the target thread before actually
invoking the callback.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Fixes: #604
2020-01-20 19:19:30 +00:00
Philip Withnall
79792574d4 gdbusnamewatching: Remove a redundant function argument
It was always set to `FALSE`. This introduces no functional changes.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #604
2020-01-20 19:19:30 +00:00
Sebastian Dröge
33ee190b3d Merge branch 'wip/pwithnall/thread-settings-fixes' into 'master'
gthread: Ensure GThreadSchedulerSettings is always defined

See merge request GNOME/glib!1334
2020-01-20 19:06:28 +00:00
Philip Withnall
df0610aa55 ci: Use --wrap-mode=default on macOS CI runner (only)
This is a partial revert of commit 595e12b5fb for macOS only, since we
can’t run a VM image on that CI runner, and hence can’t easily
pre-populate it with cached dependencies.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-01-20 15:30:44 +00:00
Philip Withnall
03380a4928 tests: Fix header inclusion in win32-appinfo.c
This fixes the following build failure on FreeBSD:
```
  In file included from ../gio/tests/win32-appinfo.c:24:
  /usr/include/malloc.h:3:2: error: "<malloc.h> has been replaced by <stdlib.h>"
  #error "<malloc.h> has been replaced by <stdlib.h>"
```

Hopefully it doesn’t break Windows.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-01-20 15:22:03 +00:00
Philip Withnall
37b1acdf8c gdbusconnection: Document threading and refcounting for signals
This is essentially a mini writeup of #978.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #978
2020-01-20 15:13:52 +00:00
Philip Withnall
a434bfbb3d gdbusnameowning: Fix race between connection shutdown and NameLost
As with all D-Bus signal subscriptions, it’s possible for a signal
callback to be invoked in one thread (T1) while another thread (T2) is
unsubscribing from that signal. In this case, T1 is the main thread, and
T2 is the D-Bus connection worker thread which is unsubscribing all
signals as it’s in the process of closing.

Due to this possibility, all `user_data` for signal callbacks needs to
be referenced outside the lifecycle of the code which
subscribes/unsubscribes the signal. In other words, it’s not safe to
subscribe to a signal, store the subscription ID in a struct,
unsubscribe from the signal when freeing the struct, and dereference the
struct in the signal callback. The data passed to the signal callback
has to have its own strong reference.

Instead, it’s safe to subscribe to a signal and add a strong reference
to the struct, store the subscription ID in that struct, and unsubscribe
from the signal when the last external reference to your struct is
dropped. That unsubscription should break the refcount cycle between the
signal connection and the struct, and allow the struct to be completely
freed. Only with that approach is it safe to dereference the struct in
the signal callback, if there’s any possibility that the signal might be
unsubscribed from a separate thread.

The tests need specific additional main loop cycles to completely emit
the NameLost signal callback. Ideally they need refactoring, but this
will do (1000 test cycles passed).

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Fixes: #978
2020-01-20 15:13:52 +00:00
Philip Withnall
4ec2175d21 gdbusconnection: Tidy up unsubscription code
This just removes a now-redundant intermediate array. This means that
the `SignalSubscriber` instances are now potentially freed a little
sooner, inside the locked segment, but they are already careful to only
call their `user_data_free_func` in the right thread. So that should not
deadlock.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #978
2020-01-20 15:13:52 +00:00
Philip Withnall
30c8eb85ab gthread: Ensure GThreadSchedulerSettings is always defined
It’s now used unconditionally for `shared_thread_scheduler_settings` in
`gthreadpool.c`, so it actually needs to have a storage definition.

Fixes a build failure on FreeBSD.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-01-20 14:39:52 +00:00
Philip Withnall
130455bbb2 gdbusconnection: Fix race when emitting D-Bus signal callbacks
Instead of storing a copy of the `callback` and `user_data` from a
`SignalSubscriber` in a `SignalInstance` struct (which is the closure
for signal callback data as it’s sent from the D-Bus worker thread to
the thread which originally subscribed to a signal), store a strong
reference to the `SignalSubscriber` struct itself.

This keeps the `SignalSubscriber` alive until the emission is
complete, which ensures that the `user_data` is not freed prematurely.
It also slightly reduces the allocation size of `SignalInstance` (not
that it matters).

This is threadsafe because the fields in `SignalSubscriber` are all
immutable after construction.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #978
2020-01-20 14:30:39 +00:00
Philip Withnall
bee27dd9f0 gdbusconnection: Tidy up destroy notification for signal subscriptions
Tie the destruction of the `user_data` to the destruction of the
`SignalSubscriber` struct. This is tidier, and ensures that the fields
in `SignalSubscriber` are all immutable after being set, so the
structure can safely be used across threads without locking.

It doesn’t matter which thread we call `call_destroy_notify()` in, since
it always defers calling `user_data_free_func` to the user-provided
`GMainContext`.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #978
2020-01-20 14:30:39 +00:00
Philip Withnall
9b1c8d7dd5 gdbusconnection: Allocate SignalSubscriber structs individually
The `SignalSubscriber` structs contain the callback and `user_data` of each
subscriber to a signal, along with the `guint id` token held by that
subscriber to identify their subscription. There are one or more
`SignalSubscriber` structs for a given signal match rule, which is
represented as a `SignalData` struct.

Previously, the `SignalSubscriber` structs were stored in a `GArray` in
the `SignalData` struct, to reduce the number of allocations needed
when subscribing to a signal.

However, this means that a `SignalSubscriber` struct cannot have a
lifetime which exceeds the `SignalData` which contains it. In order to
fix the race in #978, one thread needs to be able to unsubscribe from a
signal (destroying the `SignalData` struct) while zero or more other
threads are in the process of calling the callbacks from a previous
emission of that signal (using the callback and `user_data` from zero or
more `SignalSubscriber` structs). Multiple threads could be calling
callbacks because callbacks are invoked in the `GMainContext` which
originally made a subscription, and GDBus supports subscribing to a
signal from multiple threads. In that case, the callbacks are dispatched
to multiple threads.

In order to allow the `SignalSubscriber` structs to outlive the
`SignalData` which contained their old match rule, store them in a
`GPtrArray` in the `SignalData` struct, and refcount them individually.

This commit in itself should make no functional changes to how GDBus
works, but will allow following commits to do so.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #978
2020-01-20 14:30:39 +00:00
Philip Withnall
e1cf40a6b2 glib.supp: Ignore the one-off GTask thread pool allocation
Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-01-20 11:24:15 +00:00
Philip Withnall
fda1c651d5 Merge branch 'w32-gstat-ino-master' into 'master'
W32: Correctly set st_ino when doing private stat()

See merge request GNOME/glib!1330
2020-01-20 10:49:23 +00:00
Philip Withnall
adee3b31dc Merge branch 'appinfo-rundll32' into 'master'
Add rundll32 support to GAppInfo

Closes #1932

See merge request GNOME/glib!1259
2020-01-20 10:36:29 +00:00
Philip Withnall
2a0b1d8ba0 Merge branch 'threadpool-sched-getattr-runtime-check' into 'master'
Add runtime checks and a fallback if we can't get the thread scheduler settings

Closes #2007

See merge request GNOME/glib!1327
2020-01-20 10:14:11 +00:00
Jordi Mas
3fd06991df Update Catalan translation 2020-01-19 22:20:27 +01:00
Руслан Ижбулатов
9b232fa743 W32: Correctly set st_ino when doing private stat() 2020-01-19 16:57:39 +00:00
Sebastian Dröge
d1a3be5605 Remove trailing comma from SYS_sched_getattr meson check 2020-01-19 10:48:33 +02:00
Sebastian Dröge
012660b8fa Add runtime checks and a fallback if we can't get the thread scheduler settings
On Linux the sched_getattr syscall might be available at compile-time
but not actually work at runtime (e.g. because an older kernel is
running or valgrind is used). Instead of killing the process, return
FALSE and handle this gracefully at runtime with some fallback code.

Fixes https://gitlab.gnome.org/GNOME/glib/issues/2007
2020-01-19 10:47:52 +02:00
Sebastian Dröge
457ea97c75 Merge branch 'threadpool-sched-getattr' into 'master'
Check for SYS_sched_getattr before using it unconditionally

See merge request GNOME/glib!1325
2020-01-17 07:40:38 +00:00
Emmanuele Bassi
60dc7e612d Merge branch 'style-check-docs' into 'master'
ci: Add some documentation to the style check CI test

See merge request GNOME/glib!1324
2020-01-16 14:19:27 +00:00
Sebastian Dröge
8b1f24f658 Check for SYS_sched_getattr before using it unconditionally
Really old versions of Linux don't have yet. In that case fall back to
the fallback code.

See 8aeca4fa64 (note_686823)
2020-01-16 16:02:39 +02:00
Xavier Claessens
bc77510b67 Merge branch 'ci-nodownload' into 'master'
ci: Avoid downloading subprojects for each job

See merge request GNOME/glib!388
2020-01-16 13:54:24 +00:00
Philip Withnall
65541f1ad6 ci: Add some documentation to the style check CI test
Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-01-16 13:48:56 +00:00
Philip Withnall
3499bd7713 Merge branch 'issue-1998-gsettings-schema-dir-env-var-multiple-dirs' into 'master'
Support multiple directories in GSETTINGS_SCHEMA_DIR

Closes #1998

See merge request GNOME/glib!1315
2020-01-16 11:16:13 +00:00
wouter bolsterlee
809a9210c3 Support multiple directories in GSETTINGS_SCHEMA_DIR
This adds support for specifying multiple directories in the
GSETTINGS_SCHEMA_DIR environment variable by separating the values
using G_SEARCHPATH_SEPARATOR_S (colon on UNIX-like systems).

While programs could already register multiple custom GSettings schema
directories, it was not possible to achieve the same without writing
custom code, e.g. when using the gsettings command line tool.

Fixes #1998.
2020-01-16 10:20:34 +00:00
Philip Withnall
321fea1c5e Merge branch 'wip/muktupavels/notifications' into 'master'
gfdonotificationbackend: remove notifications when bus name vanishes

See merge request GNOME/glib!1317
2020-01-16 06:52:16 +00:00
Xavier Claessens
595e12b5fb ci: Pass --wrap-mode=nodownload to every task
The CI should not waste resources in downloading subprojects for each
task. It should also not rely on external hosts to be available.

Windows case will be handled in MR #402 by migrating to docker.
2020-01-15 21:36:57 -05:00
Xavier Claessens
5f99781d70 ci: Update all docker images 2020-01-15 21:36:57 -05:00
Xavier Claessens
b077c1403e ci: Cache subprojects in docker images 2020-01-15 21:36:57 -05:00
Xavier Claessens
8661d94c3e ci: Install some missing packages in fedora docker image 2020-01-15 21:36:57 -05:00
Xavier Claessens
5daad373a3 ci: Use variables for docker images 2020-01-15 21:36:57 -05:00
Philip Withnall
c0a019c293 Merge branch 'threadpool-inherit-prio' into 'master'
GThreadPool - Don't inherit thread priorities when creating new threads

Closes #1834

See merge request GNOME/glib!1113
2020-01-15 21:56:26 +00:00
Sebastian Dröge
8aeca4fa64 GThreadPool - Don't inherit thread priorities when creating new threads
By default (on POSIX) we would be inheriting thread priorities from the
thread that pushed a new task on non-exclusive thread pools and causes a
new thread to be created. This can cause any non-exclusive thread pool
to accidentally contain threads of different priorities, or e.g. threads
with real-time priority.

To prevent this, custom handling for setting the scheduler settings for
Linux and Windows is added and as a fallback for other platforms a new
thread is added that is responsible for spawning threads for
non-exclusive thread pools.

Fixes https://gitlab.gnome.org/GNOME/glib/issues/1834
2020-01-15 23:18:33 +02:00
Philip Withnall
8e82d549ee Merge branch 'gutils-crash' into 'master'
Fix crash in gutils when application is prevented access to passwd file

See merge request GNOME/glib!1309
2020-01-15 18:14:00 +00:00