Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1981)

Unified Diff: sync/internal_api/public/engine/model_safe_worker.cc

Issue 14046031: Worker changes to prepare for lock-free shutdown. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sync/internal_api/public/engine/model_safe_worker.cc
diff --git a/sync/internal_api/public/engine/model_safe_worker.cc b/sync/internal_api/public/engine/model_safe_worker.cc
index d7bf906ef9f007feec43925789b22a3367a3e15c..4b69425d35610296ae6582fee1dc5b6763516066 100644
--- a/sync/internal_api/public/engine/model_safe_worker.cc
+++ b/sync/internal_api/public/engine/model_safe_worker.cc
@@ -80,6 +80,56 @@ std::string ModelSafeGroupToString(ModelSafeGroup group) {
}
}
+ModelSafeWorker::ModelSafeWorker(WorkerLoopDestructionObserver* observer)
+ : stopped_(false),
+ work_done_or_stopped_(false, false),
+ observer_(observer) {}
+
ModelSafeWorker::~ModelSafeWorker() {}
+void ModelSafeWorker::RequestStop() {
+ base::AutoLock al(stopped_lock_);
+
+ // Set stop flag but don't signal work_done_or_stopped_ to unblock sync loop
+ // because the worker may be working and depending on sync command object
+ // living on sync thread.
tim (not reviewing) 2013/05/20 17:22:39 Add to comment: "This prevents any *further* task
haitaol1 2013/05/23 16:07:29 Done.
+ stopped_ = true;
+}
+
+SyncerError ModelSafeWorker::DoWorkAndWaitUntilDone(const WorkCallback& work) {
+ {
+ base::AutoLock al(stopped_lock_);
+ if (stopped_)
+ return CANNOT_DO_WORK;
+
+ CHECK(!work_done_or_stopped_.IsSignaled());
+ }
+
+ return DoWorkAndWaitUntilDoneImpl(work);
+}
+
+bool ModelSafeWorker::IsStopped() {
+ base::AutoLock al(stopped_lock_);
+ return stopped_;
+}
+
+void ModelSafeWorker::WillDestroyCurrentMessageLoop() {
+ {
+ base::AutoLock al(stopped_lock_);
+ stopped_ = true;
+
+ // Safe to signal because pending work (if any) will not be executed. So
+ // there should be no harm even the work holds a pointer to the
+ // ModelChangingSyncerCommand that will be destroyed on sync loop after
+ // the signal is set.
tim (not reviewing) 2013/05/20 17:22:39 This is a subtle expectation. For example, it's n
haitaol1 2013/05/23 16:07:29 Resolved per offline discussion. Updated comments.
+ work_done_or_stopped_.Signal();
+
+ DVLOG(1) << ModelSafeGroupToString(GetModelSafeGroup())
+ << " worker stops on destruction of its working thread.";
+ }
+
+ if (observer_)
+ observer_->OnWorkerLoopDestroyed(GetModelSafeGroup());
+}
+
} // namespace syncer
« no previous file with comments | « sync/internal_api/public/engine/model_safe_worker.h ('k') | sync/internal_api/public/engine/passive_model_worker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698