Merge lp:~raof/mir/make-default-surface-store-threadsafe into lp:mir
- make-default-surface-store-threadsafe
- Merge into development-branch
Status: | Merged |
---|---|
Approved by: | Alan Griffiths |
Approved revision: | no longer in the source branch. |
Merged at revision: | 4226 |
Proposed branch: | lp:~raof/mir/make-default-surface-store-threadsafe |
Merge into: | lp:mir |
Diff against target: |
39 lines (+4/-0) 2 files modified
src/server/shell/default_persistent_surface_store.cpp (+2/-0) src/server/shell/default_persistent_surface_store.h (+2/-0) |
To merge this branch: | bzr merge lp:~raof/mir/make-default-surface-store-threadsafe |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Alan Griffiths | Approve | ||
Mir CI Bot | continuous-integration | Approve | |
Review via email: mp+328705@code.launchpad.net |
Commit message
DefaultPersiste
The surface store may be accessed from multiple threads (it's accessed from each
sessions SessionMediator, for example), so it should probably have some sort of
locking around its underlying datastore.
Description of the change
Mir CI Bot (mir-ci-bot) wrote : | # |
Alan Griffiths (alan-griffiths) wrote : | # |
The motivation isn't quite as clear as commit message implies: the SessionMediator instances are all acting on the IPC thread. But it does make sense to make this threadsafe.
However, if we're going to introduce a smart RAII based lock (instead of sprinkling a few lock_guards in the access methods) I'd prefer the code using it to look nicer than:
return (**(store.
If you can make that, for example: "return (*store)[id]" I'll go along.
Alan Griffiths (alan-griffiths) wrote : | # |
It is just possible this is a fix for lp:1629553
Chris Halse Rogers (raof) wrote : | # |
It's not quite (*store)[id], but (**store)[id] is much nicer than (**(store.
Mir CI Bot (mir-ci-bot) wrote : | # |
PASSED: Continuous integration, rev:4221
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
Alan Griffiths (alan-griffiths) wrote : | # |
OK, so there are a few issues and ideas:
1. the licence should (now) be GPL2 or GPL3
2. I'm not convinced by the user defined operators in MutexGuard they make it hard to use seamlessly with smart pointers.
3. Here's a sketch of an alternative approach:
=== modified file 'src/include/
--- src/include/
+++ src/include/
@@ -62,6 +62,35 @@
std:
};
+template<typename GuardedPtr>
+class MutexPtrGuard
+{
+public:
+
+ using GuardedPtrValue = typename std::pointer_
+
+ MutexPtrGuard(
+ : value{value},
+ lock{std:
+ {
+ }
+ MutexPtrGuard(
+ ~MutexPtrGuard() noexcept(false)
+ {
+ if (lock.owns_lock())
+ {
+ lock.unlock();
+ }
+ }
+
+ GuardedPtrValue& operator*() const { return *value; }
+ GuardedPtrValue* operator->() const { return value.operator->(); }
+
+private:
+ GuardedPtr& value;
+ std::unique_
+};
+
/**
* A data-locking mutex
*
@@ -106,11 +135,11 @@
* While code has access to the MutexGuard it is guaranteed to have exclusive
* access to the contained data.
*/
- MutexGuard<typename std::pointer_
+ MutexPtrGuard<
{
- return MutexGuard<typename std::pointer_
+ return MutexPtrGuard<
- *value
+ value
};
}
=== modified file 'src/server/
--- src/server/
+++ src/server/
@@ -82,14 +82,14 @@
auto msh::DefaultPer
-> Id
{
- return (*store)
+ return store->
}
std::shared_
{
try
{
- return (**store)[id];
+ return store->
}
catch (std::out_of_range& err)
{
(Yes I know that's not "(*store)[id]" either, but renaming SurfaceIdBimap:
Mir CI Bot (mir-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:4222
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
FAILURE: https:/
Click here to trigger a rebuild:
https:/
Chris Halse Rogers (raof) wrote : | # |
mir::Mutex might make an appearance on other merge proposals; particularly if I need to touch some of our classes with tens of members and multiple different mutexes protecting different subsets of them.
But for this one it is, indee, overkill.
Mir CI Bot (mir-ci-bot) wrote : | # |
PASSED: Continuous integration, rev:4222
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
Preview Diff
1 | === modified file 'src/server/shell/default_persistent_surface_store.cpp' | |||
2 | --- src/server/shell/default_persistent_surface_store.cpp 2017-07-28 17:00:43 +0000 | |||
3 | +++ src/server/shell/default_persistent_surface_store.cpp 2017-08-14 02:49:35 +0000 | |||
4 | @@ -82,6 +82,7 @@ | |||
5 | 82 | auto msh::DefaultPersistentSurfaceStore::id_for_surface(std::shared_ptr<scene::Surface> const& surface) | 82 | auto msh::DefaultPersistentSurfaceStore::id_for_surface(std::shared_ptr<scene::Surface> const& surface) |
6 | 83 | -> Id | 83 | -> Id |
7 | 84 | { | 84 | { |
8 | 85 | std::lock_guard<std::mutex> lock{mutex}; | ||
9 | 85 | return store->insert_or_retrieve(surface); | 86 | return store->insert_or_retrieve(surface); |
10 | 86 | } | 87 | } |
11 | 87 | 88 | ||
12 | @@ -89,6 +90,7 @@ | |||
13 | 89 | { | 90 | { |
14 | 90 | try | 91 | try |
15 | 91 | { | 92 | { |
16 | 93 | std::lock_guard<std::mutex> lock{mutex}; | ||
17 | 92 | return (*store)[id]; | 94 | return (*store)[id]; |
18 | 93 | } | 95 | } |
19 | 94 | catch (std::out_of_range& err) | 96 | catch (std::out_of_range& err) |
20 | 95 | 97 | ||
21 | === modified file 'src/server/shell/default_persistent_surface_store.h' | |||
22 | --- src/server/shell/default_persistent_surface_store.h 2017-07-28 17:00:43 +0000 | |||
23 | +++ src/server/shell/default_persistent_surface_store.h 2017-08-14 02:49:35 +0000 | |||
24 | @@ -20,6 +20,7 @@ | |||
25 | 20 | #define MIR_SHELL_DEFAULT_PERSISTENT_SURFACE_STORE_H_ | 20 | #define MIR_SHELL_DEFAULT_PERSISTENT_SURFACE_STORE_H_ |
26 | 21 | 21 | ||
27 | 22 | #include "mir/shell/persistent_surface_store.h" | 22 | #include "mir/shell/persistent_surface_store.h" |
28 | 23 | #include <mutex> | ||
29 | 23 | 24 | ||
30 | 24 | namespace mir | 25 | namespace mir |
31 | 25 | { | 26 | { |
32 | @@ -36,6 +37,7 @@ | |||
33 | 36 | 37 | ||
34 | 37 | private: | 38 | private: |
35 | 38 | class SurfaceIdBimap; | 39 | class SurfaceIdBimap; |
36 | 40 | std::mutex mutable mutex; | ||
37 | 39 | std::unique_ptr<SurfaceIdBimap> const store; | 41 | std::unique_ptr<SurfaceIdBimap> const store; |
38 | 40 | }; | 42 | }; |
39 | 41 | } | 43 | } |
PASSED: Continuous integration, rev:4220 /mir-jenkins. ubuntu. com/job/ mir-ci/ 3541/ /mir-jenkins. ubuntu. com/job/ build-mir/ 4845 /mir-jenkins. ubuntu. com/job/ build-0- fetch/5046 /mir-jenkins. ubuntu. com/job/ build-1- sourcepkg/ release= artful/ 5035 /mir-jenkins. ubuntu. com/job/ build-1- sourcepkg/ release= xenial/ 5035 /mir-jenkins. ubuntu. com/job/ build-1- sourcepkg/ release= zesty/5035 /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= amd64,compiler= clang,platform= mesa,release= artful/ 4882 /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= amd64,compiler= clang,platform= mesa,release= artful/ 4882/artifact/ output/ *zip*/output. zip /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= amd64,compiler= clang,platform= mesa,release= zesty/4882 /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= amd64,compiler= clang,platform= mesa,release= zesty/4882/ artifact/ output/ *zip*/output. zip /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= amd64,compiler= gcc,platform= mesa,release= artful/ 4882 /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= amd64,compiler= gcc,platform= mesa,release= artful/ 4882/artifact/ output/ *zip*/output. zip /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= amd64,compiler= gcc,platform= mesa,release= xenial/ 4882 /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= amd64,compiler= gcc,platform= mesa,release= xenial/ 4882/artifact/ output/ *zip*/output. zip /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= amd64,compiler= gcc,platform= mesa,release= zesty/4882 /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= amd64,compiler= gcc,platform= mesa,release= zesty/4882/ artifact/ output/ *zip*/output. zip /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= cross-armhf, compiler= gcc,platform= mesa,release= artful/ 4882 /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= cross-armhf, compiler= gcc,platform= mesa,release= artful/ 4882/artifact/ output/ *zip*/output. zip /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= cross-armhf, compiler= gcc,platform= mesa,release= zesty/4882 /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= cross-armhf, compiler= gcc,platform= mesa,release= zesty/4882/ artifact/ output/ *zip*/output. zip /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= i386,compiler= gcc,platform= mesa,release= xenial/ 4882 /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= i386,compiler= gcc,platform= mesa,release= xenial/ 4882/artifact/ output/ *zip*/output. zip
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild: /mir-jenkins. ubuntu. com/job/ mir-ci/ 3541/rebuild
https:/