Merge lp:~marcustomlinson/unity-scopes-api/lp-1325633 into lp:unity-scopes-api/devel

Proposed by Marcus Tomlinson
Status: Merged
Approved by: Michal Hruby
Approved revision: 368
Merged at revision: 367
Proposed branch: lp:~marcustomlinson/unity-scopes-api/lp-1325633
Merge into: lp:unity-scopes-api/devel
Diff against target: 156 lines (+55/-40)
4 files modified
scoperegistry/DirWatcher.cpp (+43/-38)
scoperegistry/DirWatcher.h (+5/-2)
scoperegistry/ScopesWatcher.cpp (+5/-0)
scoperegistry/ScopesWatcher.h (+2/-0)
To merge this branch: bzr merge lp:~marcustomlinson/unity-scopes-api/lp-1325633
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Michal Hruby (community) Approve
Pete Woods (community) Approve
Review via email: mp+221829@code.launchpad.net

Commit message

Modified watch_event() method to be virtual rather than pure virtual as it is possible for this method to be called from watch_thread during destruction of DirWatcher.

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
Pete Woods (pete-woods) wrote :

This looks like it'll fix the issue to me

review: Approve
367. By Marcus Tomlinson

Allow child class of DirWatcher (ScopesWatcher) to call cleanup() from destructor in order to join with watch_thread.

Revision history for this message
Michal Hruby (mhr3) wrote :

98 + // Close the file descriptor
99 + close(fd_);

This will be called twice now, perhaps move to DirWatcher's destructor only?

review: Needs Fixing
368. By Marcus Tomlinson

Moved close(fd_); to DirWatcher destructor

Revision history for this message
Marcus Tomlinson (marcustomlinson) wrote :

> 98 + // Close the file descriptor
> 99 + close(fd_);
>
> This will be called twice now, perhaps move to DirWatcher's destructor only?

Good catch! Thanks man.

Revision history for this message
Michal Hruby (mhr3) wrote :

/me happy

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'scoperegistry/DirWatcher.cpp'
2--- scoperegistry/DirWatcher.cpp 2014-05-27 12:46:25 +0000
3+++ scoperegistry/DirWatcher.cpp 2014-06-03 09:07:37 +0000
4@@ -45,44 +45,7 @@
5
6 DirWatcher::~DirWatcher()
7 {
8- {
9- std::lock_guard<std::mutex> lock(mutex_);
10-
11- if (thread_state_ == Failed)
12- {
13- try
14- {
15- std::rethrow_exception(thread_exception_);
16- }
17- catch (std::exception const& e)
18- {
19- std::cerr << "~DirWatcher(): " << e.what() << std::endl;
20- }
21- catch (...)
22- {
23- std::cerr << "~DirWatcher(): watch_thread was aborted due to an unknown exception"
24- << std::endl;
25- }
26- }
27- else
28- {
29- // Set state to Stopping
30- thread_state_ = Stopping;
31-
32- // Remove watches (causes read to return)
33- for (auto& wd : wds_)
34- {
35- inotify_rm_watch(fd_, wd.first);
36- }
37- wds_.clear();
38- }
39- }
40-
41- // Wait for thread to terminate
42- if (thread_.joinable())
43- {
44- thread_.join();
45- }
46+ cleanup();
47
48 // Close the file descriptor
49 close(fd_);
50@@ -152,6 +115,48 @@
51 }
52 }
53
54+void DirWatcher::cleanup()
55+{
56+ {
57+ std::lock_guard<std::mutex> lock(mutex_);
58+
59+ if (thread_state_ == Failed)
60+ {
61+ try
62+ {
63+ std::rethrow_exception(thread_exception_);
64+ }
65+ catch (std::exception const& e)
66+ {
67+ std::cerr << "~DirWatcher(): " << e.what() << std::endl;
68+ }
69+ catch (...)
70+ {
71+ std::cerr << "~DirWatcher(): watch_thread was aborted due to an unknown exception"
72+ << std::endl;
73+ }
74+ }
75+ else
76+ {
77+ // Set state to Stopping
78+ thread_state_ = Stopping;
79+
80+ // Remove watches (causes read to return)
81+ for (auto& wd : wds_)
82+ {
83+ inotify_rm_watch(fd_, wd.first);
84+ }
85+ wds_.clear();
86+ }
87+ }
88+
89+ // Wait for thread to terminate
90+ if (thread_.joinable())
91+ {
92+ thread_.join();
93+ }
94+}
95+
96 void DirWatcher::watch_thread()
97 {
98 try
99
100=== modified file 'scoperegistry/DirWatcher.h'
101--- scoperegistry/DirWatcher.h 2014-05-22 05:57:31 +0000
102+++ scoperegistry/DirWatcher.h 2014-06-03 09:07:37 +0000
103@@ -48,11 +48,14 @@
104 };
105
106 DirWatcher();
107- ~DirWatcher();
108+ virtual ~DirWatcher();
109
110 void add_watch(std::string const& path);
111 void remove_watch(std::string const& path);
112
113+protected:
114+ void cleanup();
115+
116 private:
117 enum ThreadState
118 {
119@@ -71,7 +74,7 @@
120 std::exception_ptr thread_exception_;
121
122 void watch_thread();
123- virtual void watch_event(EventType event_type, FileType file_type, std::string const& path) = 0;
124+ virtual void watch_event(EventType, FileType, std::string const&) {}
125 };
126
127 } // namespace scoperegistry
128
129=== modified file 'scoperegistry/ScopesWatcher.cpp'
130--- scoperegistry/ScopesWatcher.cpp 2014-05-27 09:54:38 +0000
131+++ scoperegistry/ScopesWatcher.cpp 2014-06-03 09:07:37 +0000
132@@ -35,6 +35,11 @@
133 {
134 }
135
136+ScopesWatcher::~ScopesWatcher()
137+{
138+ cleanup();
139+}
140+
141 void ScopesWatcher::add_install_dir(std::string const& dir)
142 {
143 try
144
145=== modified file 'scoperegistry/ScopesWatcher.h'
146--- scoperegistry/ScopesWatcher.h 2014-05-27 09:54:38 +0000
147+++ scoperegistry/ScopesWatcher.h 2014-06-03 09:07:37 +0000
148@@ -36,6 +36,8 @@
149 ScopesWatcher(unity::scopes::internal::RegistryObject::SPtr registry,
150 std::function<void(std::pair<std::string, std::string> const&)> ini_added_callback);
151
152+ ~ScopesWatcher();
153+
154 void add_install_dir(std::string const& dir);
155
156 private:

Subscribers

People subscribed via source and target branches

to all changes: