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

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

Issue 12163003: Add FilePath to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « remoting/host/win/wts_session_process_delegate.cc ('k') | rlz/lib/rlz_value_store.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 RLZ_LIB_RECURSIVE_CROSS_PROCESS_LOCK_POSIX_H_ 5 #ifndef RLZ_LIB_RECURSIVE_CROSS_PROCESS_LOCK_POSIX_H_
6 #define RLZ_LIB_RECURSIVE_CROSS_PROCESS_LOCK_POSIX_H_ 6 #define RLZ_LIB_RECURSIVE_CROSS_PROCESS_LOCK_POSIX_H_
7 7
8 #include <pthread.h> 8 #include <pthread.h>
9 9
10 namespace base {
10 class FilePath; 11 class FilePath;
12 }
11 13
12 namespace rlz_lib { 14 namespace rlz_lib {
13 15
14 // Creating a recursive cross-process mutex on Windows is one line. On POSIX, 16 // 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 17 // 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 18 // mutex to get the recursive part, followed by a cross-process lock for the
17 // cross-process part. 19 // cross-process part.
18 // This is a struct so that it doesn't need a static initializer. 20 // This is a struct so that it doesn't need a static initializer.
19 struct RecursiveCrossProcessLock { 21 struct RecursiveCrossProcessLock {
20 // Tries to acquire a recursive cross-process lock. Note that this _always_ 22 // 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 23 // acquires the in-process lock (if it wasn't already acquired). The parent
22 // directory of |lock_file| must exist. 24 // directory of |lock_file| must exist.
23 bool TryGetCrossProcessLock(const FilePath& lock_filename); 25 bool TryGetCrossProcessLock(const base::FilePath& lock_filename);
24 26
25 // Releases the lock. Should always be called, even if 27 // Releases the lock. Should always be called, even if
26 // TryGetCrossProcessLock() returned |false|. 28 // TryGetCrossProcessLock() returned |false|.
27 void ReleaseLock(); 29 void ReleaseLock();
28 30
29 pthread_mutex_t recursive_lock_; 31 pthread_mutex_t recursive_lock_;
30 pthread_t locking_thread_; 32 pthread_t locking_thread_;
31 33
32 int file_lock_; 34 int file_lock_;
33 }; 35 };
34 36
35 // On Mac, PTHREAD_RECURSIVE_MUTEX_INITIALIZER doesn't exist before 10.7 and 37 // 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), 38 // 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. 39 // so emulate recursive locking with a normal non-recursive mutex.
38 #define RECURSIVE_CROSS_PROCESS_LOCK_INITIALIZER \ 40 #define RECURSIVE_CROSS_PROCESS_LOCK_INITIALIZER \
39 { PTHREAD_MUTEX_INITIALIZER, 0, -1 } 41 { PTHREAD_MUTEX_INITIALIZER, 0, -1 }
40 42
41 } // namespace rlz_lib 43 } // namespace rlz_lib
42 44
43 #endif // RLZ_LIB_RECURSIVE_CROSS_PROCESS_LOCK_POSIX_H_ 45 #endif // RLZ_LIB_RECURSIVE_CROSS_PROCESS_LOCK_POSIX_H_
OLDNEW
« no previous file with comments | « remoting/host/win/wts_session_process_delegate.cc ('k') | rlz/lib/rlz_value_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698