diff options
author | ivankr@chromium.org <ivankr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-29 14:00:12 +0000 |
---|---|---|
committer | ivankr@chromium.org <ivankr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-29 14:00:12 +0000 |
commit | 95b42e2745a2380a16112a059bd0e842d81f0c0a (patch) | |
tree | 8715285e587b94807bcc70cf135d99bdbec662fb /rlz/lib/recursive_cross_process_lock_posix.h | |
parent | 1b14a45ac508a066cc3c060dd37327c3a13a6fda (diff) | |
download | chromium_src-95b42e2745a2380a16112a059bd0e842d81f0c0a.zip chromium_src-95b42e2745a2380a16112a059bd0e842d81f0c0a.tar.gz chromium_src-95b42e2745a2380a16112a059bd0e842d81f0c0a.tar.bz2 |
[cros] RlzValueStore made protected by a cross-process lock and not persisted over browser lifetime (like on Mac).
*) Moved RecursiveCrossProcessLock out of .mm file to a common _posix file.
*) Added static method to ImportantFileWriter that does blocking write on the current thread.
*) Dedicated RLZ thread gone, replaced back with shutdown-blocking worker pool.
BUG=157348,62328
Review URL: https://chromiumcodereview.appspot.com/11308196
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@170179 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'rlz/lib/recursive_cross_process_lock_posix.h')
-rw-r--r-- | rlz/lib/recursive_cross_process_lock_posix.h | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/rlz/lib/recursive_cross_process_lock_posix.h b/rlz/lib/recursive_cross_process_lock_posix.h new file mode 100644 index 0000000..a39d473 --- /dev/null +++ b/rlz/lib/recursive_cross_process_lock_posix.h @@ -0,0 +1,43 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef RLZ_LIB_RECURSIVE_CROSS_PROCESS_LOCK_POSIX_H_ +#define RLZ_LIB_RECURSIVE_CROSS_PROCESS_LOCK_POSIX_H_ + +#include <pthread.h> + +class FilePath; + +namespace rlz_lib { + +// Creating a recursive cross-process mutex on Windows is one line. On POSIX, +// there's no primitive for that, so this lock is emulated by an in-process +// mutex to get the recursive part, followed by a cross-process lock for the +// cross-process part. +// This is a struct so that it doesn't need a static initializer. +struct RecursiveCrossProcessLock { + // Tries to acquire a recursive cross-process lock. Note that this _always_ + // acquires the in-process lock (if it wasn't already acquired). The parent + // directory of |lock_file| must exist. + bool TryGetCrossProcessLock(const FilePath& lock_filename); + + // Releases the lock. Should always be called, even if + // TryGetCrossProcessLock() returned |false|. + void ReleaseLock(); + + pthread_mutex_t recursive_lock_; + pthread_t locking_thread_; + + int file_lock_; +}; + +// On Mac, PTHREAD_RECURSIVE_MUTEX_INITIALIZER doesn't exist before 10.7 and +// is buggy on 10.7 (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51906#c34), +// so emulate recursive locking with a normal non-recursive mutex. +#define RECURSIVE_CROSS_PROCESS_LOCK_INITIALIZER \ + { PTHREAD_MUTEX_INITIALIZER, 0, -1 } + +} // namespace rlz_lib + +#endif // RLZ_LIB_RECURSIVE_CROSS_PROCESS_LOCK_POSIX_H_ |