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

Side by Side Diff: rlz/lib/recursive_cross_process_lock_posix.h

Issue 11308196: [cros] RlzValueStore made protected by a cross-process lock and not persisted over browser lifetime… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comment Created 8 years 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef RLZ_LIB_RECURSIVE_CROSS_PROCESS_LOCK_POSIX_H_
6 #define RLZ_LIB_RECURSIVE_CROSS_PROCESS_LOCK_POSIX_H_
7
8 #include <pthread.h>
9
10 class FilePath;
11
12 namespace rlz_lib {
13
14 // Creating a recursive cross-process mutex on Windows is one line. On POSIX,
15 // there's no primitive for that, so this lock is emulated by an in-process
16 // mutex to get the recursive part, followed by a cross-process lock for the
17 // cross-process part.
18 // This is a struct so that it doesn't need a static initializer.
19 struct RecursiveCrossProcessLock {
20 // Tries to acquire a recursive cross-process lock. Note that this _always_
21 // acquires the in-process lock (if it wasn't already acquired). The parent
22 // directory of |lock_file| must exist.
23 bool TryGetCrossProcessLock(const FilePath& lock_filename);
24
25 // Releases the lock. Should always be called, even if
26 // TryGetCrossProcessLock() returned |false|.
27 void ReleaseLock();
28
29 pthread_mutex_t recursive_lock_;
Roger Tawa OOO till Jul 10th 2012/11/26 19:16:51 should these members be made private?
Ivan Korotkov 2012/11/27 11:37:25 Nah, unfortunately, that would make the RCPLock no
30 pthread_t locking_thread_;
31
32 int file_lock_;
33 };
34
35 // On Mac, PTHREAD_RECURSIVE_MUTEX_INITIALIZER doesn't exist before 10.7 and
36 // is buggy on 10.7 (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51906#c34),
37 // so emulate recursive locking with a normal non-recursive mutex.
38 #define RECURSIVE_CROSS_PROCESS_LOCK_INITIALIZER \
39 { PTHREAD_MUTEX_INITIALIZER, 0, -1 }
40
41 } // namespace rlz_lib
42
43 #endif // RLZ_LIB_RECURSIVE_CROSS_PROCESS_LOCK_POSIX_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698