Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/directory_watcher.h" | 5 #include "base/directory_watcher.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 #include <sys/ioctl.h> | 9 #include <sys/ioctl.h> |
| 10 #include <sys/inotify.h> | 10 #include <sys/inotify.h> |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 179 shutdown_pipe_[1] = -1; | 179 shutdown_pipe_[1] = -1; |
| 180 if (inotify_fd_ >= 0 && pipe(shutdown_pipe_) == 0 && thread_.Start()) { | 180 if (inotify_fd_ >= 0 && pipe(shutdown_pipe_) == 0 && thread_.Start()) { |
| 181 thread_.message_loop()->PostTask( | 181 thread_.message_loop()->PostTask( |
| 182 FROM_HERE, new InotifyReaderTask(this, inotify_fd_, shutdown_pipe_[0])); | 182 FROM_HERE, new InotifyReaderTask(this, inotify_fd_, shutdown_pipe_[0])); |
| 183 valid_ = true; | 183 valid_ = true; |
| 184 } | 184 } |
| 185 } | 185 } |
| 186 | 186 |
| 187 InotifyReader::~InotifyReader() { | 187 InotifyReader::~InotifyReader() { |
| 188 if (valid_) { | 188 if (valid_) { |
| 189 // Write to the self-pipe so that the select call in InotifyReaderTask retur ns. | 189 // Write to the self-pipe so that the select call in InotifyReaderTask |
| 190 write(shutdown_pipe_[1], "", 1); | 190 // returns. |
| 191 ssize_t bytes_written; | |
| 192 do { | |
| 193 bytes_written = write(shutdown_pipe_[1], "", 1); | |
| 194 if (bytes_written == 0) | |
| 195 continue; | |
| 196 } while (bytes_written == -1 && errno == EINTR); | |
| 191 thread_.Stop(); | 197 thread_.Stop(); |
|
Mark Mentovai
2009/03/19 19:01:57
You can keep the DCHECK that you had in the last v
| |
| 192 } | 198 } |
| 193 if (inotify_fd_ >= 0) | 199 if (inotify_fd_ >= 0) |
| 194 close(inotify_fd_); | 200 close(inotify_fd_); |
| 195 if (shutdown_pipe_[0] >= 0) | 201 if (shutdown_pipe_[0] >= 0) |
| 196 close(shutdown_pipe_[0]); | 202 close(shutdown_pipe_[0]); |
| 197 if (shutdown_pipe_[1] >= 0) | 203 if (shutdown_pipe_[1] >= 0) |
| 198 close(shutdown_pipe_[1]); | 204 close(shutdown_pipe_[1]); |
| 199 } | 205 } |
| 200 | 206 |
| 201 InotifyReader::Watch InotifyReader::AddWatch( | 207 InotifyReader::Watch InotifyReader::AddWatch( |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 312 watch_ = Singleton<InotifyReader>::get()->AddWatch(path, delegate_); | 318 watch_ = Singleton<InotifyReader>::get()->AddWatch(path, delegate_); |
| 313 | 319 |
| 314 return watch_ != InotifyReader::kInvalidWatch; | 320 return watch_ != InotifyReader::kInvalidWatch; |
| 315 } | 321 } |
| 316 | 322 |
| 317 } // namespace | 323 } // namespace |
| 318 | 324 |
| 319 DirectoryWatcher::DirectoryWatcher() { | 325 DirectoryWatcher::DirectoryWatcher() { |
| 320 impl_ = new DirectoryWatcherImpl(); | 326 impl_ = new DirectoryWatcherImpl(); |
| 321 } | 327 } |
| OLD | NEW |