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

Side by Side Diff: chrome/browser/sync/syncable/syncable.h

Issue 2805095: Fix deadlock by introducing a new transaction event. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Created 10 years, 5 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 #ifndef CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_H_ 5 #ifndef CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_H_
6 #define CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_H_ 6 #define CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_H_
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <bitset> 9 #include <bitset>
10 #include <iosfwd> 10 #include <iosfwd>
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 579
580 // A separate Event type and channel for very frequent changes, caused 580 // A separate Event type and channel for very frequent changes, caused
581 // by anything, not just the user. 581 // by anything, not just the user.
582 struct DirectoryChangeEvent { 582 struct DirectoryChangeEvent {
583 enum { 583 enum {
584 // Means listener should go through list of original entries and 584 // Means listener should go through list of original entries and
585 // calculate what it needs to notify. It should *not* call any 585 // calculate what it needs to notify. It should *not* call any
586 // callbacks or attempt to lock anything because a 586 // callbacks or attempt to lock anything because a
587 // WriteTransaction is being held until the listener returns. 587 // WriteTransaction is being held until the listener returns.
588 CALCULATE_CHANGES, 588 CALCULATE_CHANGES,
589 // Means the WriteTransaction is ending, and this is the absolute
590 // last chance to perform any read operations in the current transaction.
591 // It is not recommended that the listener perform any writes.
592 TRANSACTION_ENDING,
589 // Means the WriteTransaction has been released and the listener 593 // Means the WriteTransaction has been released and the listener
590 // can now take action on the changes it calculated. 594 // can now take action on the changes it calculated.
591 TRANSACTION_COMPLETE, 595 TRANSACTION_COMPLETE,
592 // Channel is closing. 596 // Channel is closing.
593 SHUTDOWN 597 SHUTDOWN
594 } todo; 598 } todo;
595 // These members are only valid for CALCULATE_CHANGES. 599 // These members are only valid for CALCULATE_CHANGES.
596 const OriginalEntries* originals; 600 const OriginalEntries* originals;
597 BaseTransaction* trans; 601 BaseTransaction* trans; // This is valid also for TRANSACTION_ENDING
598 WriterTag writer; 602 WriterTag writer;
599 typedef DirectoryChangeEvent EventType; 603 typedef DirectoryChangeEvent EventType;
600 static inline bool IsChannelShutdownEvent(const EventType& e) { 604 static inline bool IsChannelShutdownEvent(const EventType& e) {
601 return SHUTDOWN == e.todo; 605 return SHUTDOWN == e.todo;
602 } 606 }
603 }; 607 };
604 608
605 // A list of metahandles whose metadata should not be purged. 609 // A list of metahandles whose metadata should not be purged.
606 typedef std::multiset<int64> Pegs; 610 typedef std::multiset<int64> Pegs;
607 611
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 DISALLOW_COPY_AND_ASSIGN(ScopedKernelLock); 1041 DISALLOW_COPY_AND_ASSIGN(ScopedKernelLock);
1038 }; 1042 };
1039 1043
1040 // Transactions are now processed FIFO with a straight lock 1044 // Transactions are now processed FIFO with a straight lock
1041 class BaseTransaction { 1045 class BaseTransaction {
1042 friend class Entry; 1046 friend class Entry;
1043 public: 1047 public:
1044 inline Directory* directory() const { return directory_; } 1048 inline Directory* directory() const { return directory_; }
1045 inline Id root_id() const { return Id(); } 1049 inline Id root_id() const { return Id(); }
1046 1050
1051 virtual ~BaseTransaction();
1052
1047 protected: 1053 protected:
1048 BaseTransaction(Directory* directory, const char* name, 1054 BaseTransaction(Directory* directory, const char* name,
1049 const char* source_file, int line, WriterTag writer); 1055 const char* source_file, int line, WriterTag writer);
1050 1056
1051 void UnlockAndLog(OriginalEntries* entries); 1057 void UnlockAndLog(OriginalEntries* entries);
1052 1058
1053 Directory* const directory_; 1059 Directory* const directory_;
1054 Directory::Kernel* const dirkernel_; // for brevity 1060 Directory::Kernel* const dirkernel_; // for brevity
1055 const char* const name_; 1061 const char* const name_;
1056 base::TimeTicks time_acquired_; 1062 base::TimeTicks time_acquired_;
1057 const char* const source_file_; 1063 const char* const source_file_;
1058 const int line_; 1064 const int line_;
1059 WriterTag writer_; 1065 WriterTag writer_;
1060 1066
1061 private: 1067 private:
1062 void Lock(); 1068 void Lock();
1063 1069
1064 DISALLOW_COPY_AND_ASSIGN(BaseTransaction); 1070 DISALLOW_COPY_AND_ASSIGN(BaseTransaction);
1065 }; 1071 };
1066 1072
1067 // Locks db in constructor, unlocks in destructor. 1073 // Locks db in constructor, unlocks in destructor.
1068 class ReadTransaction : public BaseTransaction { 1074 class ReadTransaction : public BaseTransaction {
1069 public: 1075 public:
1070 ReadTransaction(Directory* directory, const char* source_file, 1076 ReadTransaction(Directory* directory, const char* source_file,
1071 int line); 1077 int line);
1072 ReadTransaction(const ScopedDirLookup& scoped_dir, 1078 ReadTransaction(const ScopedDirLookup& scoped_dir,
1073 const char* source_file, int line); 1079 const char* source_file, int line);
1074 1080
1075 ~ReadTransaction(); 1081 virtual ~ReadTransaction();
1076 1082
1077 protected: // Don't allow creation on heap, except by sync API wrapper. 1083 protected: // Don't allow creation on heap, except by sync API wrapper.
1078 friend class sync_api::ReadTransaction; 1084 friend class sync_api::ReadTransaction;
1079 void* operator new(size_t size) { return (::operator new)(size); } 1085 void* operator new(size_t size) { return (::operator new)(size); }
1080 1086
1081 DISALLOW_COPY_AND_ASSIGN(ReadTransaction); 1087 DISALLOW_COPY_AND_ASSIGN(ReadTransaction);
1082 }; 1088 };
1083 1089
1084 // Locks db in constructor, unlocks in destructor. 1090 // Locks db in constructor, unlocks in destructor.
1085 class WriteTransaction : public BaseTransaction { 1091 class WriteTransaction : public BaseTransaction {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 void ZeroFields(EntryKernel* entry, int first_field); 1126 void ZeroFields(EntryKernel* entry, int first_field);
1121 1127
1122 } // namespace syncable 1128 } // namespace syncable
1123 1129
1124 std::ostream& operator <<(std::ostream&, const syncable::Blob&); 1130 std::ostream& operator <<(std::ostream&, const syncable::Blob&);
1125 1131
1126 browser_sync::FastDump& operator << 1132 browser_sync::FastDump& operator <<
1127 (browser_sync::FastDump&, const syncable::Blob&); 1133 (browser_sync::FastDump&, const syncable::Blob&);
1128 1134
1129 #endif // CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_H_ 1135 #endif // CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698