Mir

Merge lp:~alan-griffiths/mir/fix-1514884 into lp:mir

Proposed by Alan Griffiths
Status: Merged
Approved by: Alberto Aguirre
Approved revision: no longer in the source branch.
Merged at revision: 3151
Proposed branch: lp:~alan-griffiths/mir/fix-1514884
Merge into: lp:mir
Diff against target: 63 lines (+17/-11)
2 files modified
include/test/mir/test/doubles/mock_egl.h (+10/-8)
tests/mir_test_doubles/mock_egl.cpp (+7/-3)
To merge this branch: bzr merge lp:~alan-griffiths/mir/fix-1514884
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Alexandros Frantzis (community) Approve
Review via email: mp+278961@code.launchpad.net

Commit message

tests: fix racy access to MockEGL::current_contexts

Description of the change

tests: fix racy access to MockEGL::current_contexts

To post a comment you must log in.
Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

Looks good.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Alberto Aguirre (albaguirre) wrote :

^-- Another instance of https://bugs.launchpad.net/mir/+bug/1520217

Top-approving again.

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'include/test/mir/test/doubles/mock_egl.h'
2--- include/test/mir/test/doubles/mock_egl.h 2015-11-13 19:46:42 +0000
3+++ include/test/mir/test/doubles/mock_egl.h 2015-11-30 13:56:32 +0000
4@@ -21,8 +21,9 @@
5
6 #include <gmock/gmock.h>
7
8+#include <mutex>
9+#include <thread>
10 #include <unordered_map>
11-#include <thread>
12
13 #define GL_GLEXT_PROTOTYPES
14 #define EGL_EGLEXT_PROTOTYPES
15@@ -150,13 +151,14 @@
16 MOCK_METHOD2(eglDestroySyncKHR, EGLBoolean(EGLDisplay, EGLSyncKHR));
17 MOCK_METHOD4(eglClientWaitSyncKHR, EGLint(EGLDisplay, EGLSyncKHR, EGLint, EGLTimeKHR));
18
19- EGLDisplay fake_egl_display;
20- EGLConfig* fake_configs;
21- EGLint fake_configs_num;
22- EGLSurface fake_egl_surface;
23- EGLContext fake_egl_context;
24- EGLImageKHR fake_egl_image;
25- int fake_visual_id;
26+ EGLDisplay const fake_egl_display;
27+ EGLConfig const* const fake_configs;
28+ EGLint const fake_configs_num;
29+ EGLSurface const fake_egl_surface;
30+ EGLContext const fake_egl_context;
31+ EGLImageKHR const fake_egl_image;
32+ int const fake_visual_id;
33+ std::mutex mutable current_contexts_mutex;
34 std::unordered_map<std::thread::id,EGLContext> current_contexts;
35 };
36
37
38=== modified file 'tests/mir_test_doubles/mock_egl.cpp'
39--- tests/mir_test_doubles/mock_egl.cpp 2015-11-13 19:46:42 +0000
40+++ tests/mir_test_doubles/mock_egl.cpp 2015-11-30 13:56:32 +0000
41@@ -108,15 +108,19 @@
42
43 ON_CALL(*this, eglMakeCurrent(_,_,_,_))
44 .WillByDefault(Invoke(
45- [&] (EGLDisplay, EGLSurface, EGLSurface, EGLContext context)
46+ [this] (EGLDisplay, EGLSurface, EGLSurface, EGLContext context)
47 {
48+ std::lock_guard<decltype(current_contexts_mutex)> lock{current_contexts_mutex};
49 current_contexts[std::this_thread::get_id()] = context;
50 return EGL_TRUE;
51 }));
52
53 ON_CALL(*this, eglGetCurrentContext())
54- .WillByDefault(Invoke(
55- [&] { return current_contexts[std::this_thread::get_id()]; }));
56+ .WillByDefault(Invoke([this]
57+ {
58+ std::lock_guard<decltype(current_contexts_mutex)> lock{current_contexts_mutex};
59+ return current_contexts[std::this_thread::get_id()];
60+ }));
61
62 ON_CALL(*this, eglSwapBuffers(_,_))
63 .WillByDefault(Return(EGL_TRUE));

Subscribers

People subscribed via source and target branches