summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/sync/syncable/syncable.cc24
-rw-r--r--chrome/browser/sync/syncable/syncable.h20
2 files changed, 34 insertions, 10 deletions
diff --git a/chrome/browser/sync/syncable/syncable.cc b/chrome/browser/sync/syncable/syncable.cc
index 3f0c65b..e8373a88 100644
--- a/chrome/browser/sync/syncable/syncable.cc
+++ b/chrome/browser/sync/syncable/syncable.cc
@@ -202,6 +202,7 @@ Directory::Kernel::Kernel(const PathString& db_path,
next_metahandle(info.max_metahandle + 1),
next_id(info.kernel_info.next_id) {
info_status_ = Directory::KERNEL_SHARE_INFO_VALID;
+ CHECK(0 == pthread_mutex_init(&mutex, NULL));
}
inline void DeleteEntry(EntryKernel* kernel) {
@@ -221,6 +222,7 @@ Directory::Kernel::~Kernel() {
CHECK(0 == refcount);
delete channel;
delete changes_channel;
+ CHECK(0 == pthread_mutex_destroy(&mutex));
delete unsynced_metahandles;
delete unapplied_update_metahandles;
delete extended_attributes;
@@ -762,9 +764,7 @@ void Directory::TakeSnapshotForSaveChanges(SaveChangesSnapshot* snapshot) {
bool Directory::SaveChanges() {
bool success = false;
DCHECK(store_);
-
- AutoLock(kernel_->save_changes_mutex);
-
+ PThreadScopedLock<PThreadMutex> lock(&kernel_->save_changes_mutex);
// Snapshot and save.
SaveChangesSnapshot snapshot;
TakeSnapshotForSaveChanges(&snapshot);
@@ -1104,9 +1104,22 @@ void Directory::CheckTreeInvariants(syncable::BaseTransaction* trans,
// ScopedKernelLocks
ScopedKernelLock::ScopedKernelLock(const Directory* dir)
- : dir_(const_cast<Directory*>(dir)), scoped_lock_(dir_->kernel_->mutex) {
+ : dir_(const_cast<Directory*>(dir)) {
// Swap out the dbhandle to enforce the "No IO while holding kernel
// lock" rule.
+ // HA!! Yeah right. What about your pre-cached queries :P
+ pthread_mutex_lock(&dir->kernel_->mutex);
+}
+ScopedKernelLock::~ScopedKernelLock() {
+ pthread_mutex_unlock(&dir_->kernel_->mutex);
+}
+
+ScopedKernelUnlock::ScopedKernelUnlock(ScopedKernelLock* lock)
+ : lock_(lock) {
+ pthread_mutex_unlock(&lock->dir_->kernel_->mutex);
+}
+ScopedKernelUnlock::~ScopedKernelUnlock() {
+ pthread_mutex_lock(&lock_->dir_->kernel_->mutex);
}
///////////////////////////////////////////////////////////////////////////
@@ -1154,7 +1167,7 @@ void BaseTransaction::UnlockAndLog(OriginalEntries* originals_arg) {
return;
}
- AutoLock(dirkernel_->changes_channel_mutex);
+ dirkernel_->changes_channel_mutex.Lock();
// Tell listeners to calculate changes while we still have the mutex.
DirectoryChangeEvent event = { DirectoryChangeEvent::CALCULATE_CHANGES,
originals.get(), this, writer_ };
@@ -1166,6 +1179,7 @@ void BaseTransaction::UnlockAndLog(OriginalEntries* originals_arg) {
{ DirectoryChangeEvent::TRANSACTION_COMPLETE,
NULL, NULL, INVALID };
dirkernel_->changes_channel->NotifyListeners(complete_event);
+ dirkernel_->changes_channel_mutex.Unlock();
}
ReadTransaction::ReadTransaction(Directory* directory, const char* file,
diff --git a/chrome/browser/sync/syncable/syncable.h b/chrome/browser/sync/syncable/syncable.h
index 7ab804e..9af42f2 100644
--- a/chrome/browser/sync/syncable/syncable.h
+++ b/chrome/browser/sync/syncable/syncable.h
@@ -23,9 +23,11 @@
#include "chrome/browser/sync/syncable/path_name_cmp.h"
#include "chrome/browser/sync/syncable/syncable_id.h"
#include "chrome/browser/sync/util/compat_file.h"
+#include "chrome/browser/sync/util/compat_pthread.h"
#include "chrome/browser/sync/util/dbgq.h"
#include "chrome/browser/sync/util/event_sys.h"
#include "chrome/browser/sync/util/path_helpers.h"
+#include "chrome/browser/sync/util/pthread_helpers.h"
#include "chrome/browser/sync/util/row_iterator.h"
#include "chrome/browser/sync/util/sync_types.h"
@@ -808,6 +810,7 @@ struct ExtendedAttributeValue {
typedef std::map<ExtendedAttributeKey, ExtendedAttributeValue>
ExtendedAttributes;
+typedef PThreadScopedLock<PThreadMutex> ScopedTransactionLock;
typedef std::set<int64> MetahandleSet;
// A list of metahandles whose metadata should not be purged.
@@ -1124,7 +1127,7 @@ class Directory {
//
// Never hold the mutex and do anything with the database or any
// other buffered IO. Violating this rule will result in deadlock.
- Lock mutex;
+ pthread_mutex_t mutex; // TODO(chron): Swap this out for Chrome Lock
MetahandlesIndex* metahandles_index; // Entries indexed by metahandle
IdsIndex* ids_index; // Entries indexed by id
ParentIdAndNamesIndex* parent_id_and_names_index;
@@ -1147,7 +1150,7 @@ class Directory {
// while holding the transaction mutex and released after
// releasing the transaction mutex.
ChangesChannel* const changes_channel;
- Lock changes_channel_mutex;
+ PThreadMutex changes_channel_mutex;
KernelShareInfoStatus info_status_;
// These 5 members are backed in the share_info table, and
// their state is marked by the flag above.
@@ -1164,7 +1167,7 @@ class Directory {
// It doesn't make sense for two threads to run SaveChanges at the same
// time; this mutex protects that activity.
- Lock save_changes_mutex;
+ PThreadMutex save_changes_mutex;
// The next metahandle and id are protected by kernel mutex.
int64 next_metahandle;
@@ -1183,13 +1186,20 @@ class Directory {
class ScopedKernelLock {
public:
explicit ScopedKernelLock(const Directory*);
- ~ScopedKernelLock() {}
+ ~ScopedKernelLock();
- AutoLock scoped_lock_;
Directory* const dir_;
DISALLOW_COPY_AND_ASSIGN(ScopedKernelLock);
};
+class ScopedKernelUnlock {
+ public:
+ explicit ScopedKernelUnlock(ScopedKernelLock* lock);
+ ~ScopedKernelUnlock();
+ ScopedKernelLock* const lock_;
+ DISALLOW_COPY_AND_ASSIGN(ScopedKernelUnlock);
+};
+
// Transactions are now processed FIFO (+overlapping reads).
class BaseTransaction {
friend class Entry;