Mir

Merge lp:~robertcarr/mir/fix-shell-focus-locking into lp:~mir-team/mir/trunk

Proposed by Robert Carr
Status: Merged
Approved by: Alexandros Frantzis
Approved revision: no longer in the source branch.
Merged at revision: 579
Proposed branch: lp:~robertcarr/mir/fix-shell-focus-locking
Merge into: lp:~mir-team/mir/trunk
Diff against target: 78 lines (+10/-13)
2 files modified
include/server/mir/shell/session_manager.h (+1/-1)
src/server/shell/session_manager.cpp (+9/-12)
To merge this branch: bzr merge lp:~robertcarr/mir/fix-shell-focus-locking
Reviewer Review Type Date Requested Status
Alan Griffiths Approve
Alexandros Frantzis (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+156638@code.launchpad.net

Commit message

Fix multiple race conditions in SessionManager

Description of the change

Fix multiple race conditions in SessionManager

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

Would it be worth giving set_focus_to_locked() a "std::unique_lock<std::mutex> const&" parameter so that it explicitly requires the surrounding lock to make the call? (No need for the parameter in the function body of course.)

Hmm...then we wouldn't need two functions - a temporary could be used for the call sites that don't have an existing lock.

Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

> Would it be worth giving set_focus_to_locked() a "std::unique_lock<std::mutex>
> const&" parameter so that it explicitly requires the surrounding lock to make
> the call? (No need for the parameter in the function body of course.)

The idea is that then the lock can't be accidentally deleted in maintenance.

Revision history for this message
Robert Carr (robertcarr) wrote :

Didn't realize there were comments here! Nice idea. Iterated!

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

Looks good.

review: Approve
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'include/server/mir/shell/session_manager.h'
2--- include/server/mir/shell/session_manager.h 2013-03-29 16:51:35 +0000
3+++ include/server/mir/shell/session_manager.h 2013-04-09 16:57:22 +0000
4@@ -77,7 +77,7 @@
5 typedef std::vector<std::pair<int, std::shared_ptr<frontend::Session>>> Tags;
6 Tags tags;
7
8- void set_focus_to(std::shared_ptr<frontend::Session> const& next_focus);
9+ void set_focus_to_locked(std::unique_lock<std::mutex> const& lock, std::shared_ptr<frontend::Session> const& next_focus);
10 };
11
12 }
13
14=== modified file 'src/server/shell/session_manager.cpp'
15--- src/server/shell/session_manager.cpp 2013-03-29 16:51:35 +0000
16+++ src/server/shell/session_manager.cpp 2013-04-09 16:57:22 +0000
17@@ -57,28 +57,25 @@
18
19 app_container->insert_session(new_session);
20
21- {
22- std::unique_lock<std::mutex> lock(mutex);
23- focus_application = new_session;
24- }
25- focus_setter->set_focus_to(new_session);
26+ set_focus_to_locked(std::unique_lock<std::mutex>(mutex), new_session);
27
28 return new_session;
29 }
30
31-inline void msh::SessionManager::set_focus_to(std::shared_ptr<mf::Session> const& next_focus)
32+inline void msh::SessionManager::set_focus_to_locked(std::unique_lock<std::mutex> const&, std::shared_ptr<mf::Session> const& next_focus)
33 {
34 auto shell_session = std::dynamic_pointer_cast<msh::Session>(next_focus);
35+
36 focus_application = shell_session;
37 focus_setter->set_focus_to(shell_session);
38 }
39
40 void msh::SessionManager::close_session(std::shared_ptr<mf::Session> const& session)
41 {
42- std::unique_lock<std::mutex> lock(mutex);
43-
44 app_container->remove_session(session);
45- set_focus_to(focus_sequence->default_focus());
46+
47+ std::unique_lock<std::mutex> lock(mutex);
48+ set_focus_to_locked(lock, focus_sequence->default_focus());
49
50 typedef Tags::value_type Pair;
51
52@@ -100,7 +97,7 @@
53 {
54 focus = focus_sequence->successor_of(focus);
55 }
56- set_focus_to(focus);
57+ set_focus_to_locked(lock, focus);
58 }
59
60 void msh::SessionManager::shutdown()
61@@ -134,7 +131,7 @@
62
63 if (tags.end() != match)
64 {
65- set_focus_to(match->second);
66+ set_focus_to_locked(lock, match->second);
67 }
68 }
69
70@@ -142,7 +139,7 @@
71 mf::SurfaceCreationParameters const& params)
72 {
73 auto id = session->create_surface(params);
74- set_focus_to(session);
75+ set_focus_to_locked(std::unique_lock<std::mutex>(mutex), session);
76
77 return id;
78 }

Subscribers

People subscribed via source and target branches