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

Side by Side Diff: third_party/re2/util/mutex.h

Issue 10873029: Migrate WebRequestRedirectByRegExAction to use RE2 and roll RE2 to revision 97:401ab4168e8e (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merged with ToT Created 8 years, 3 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 | « third_party/re2/util/logging.h ('k') | third_party/re2/util/sparse_array.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 2007 The RE2 Authors. All Rights Reserved. 1 // Copyright 2007 The RE2 Authors. All Rights Reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 /* 5 /*
6 * A simple mutex wrapper, supporting locks and read-write locks. 6 * A simple mutex wrapper, supporting locks and read-write locks.
7 * You should assume the locks are *not* re-entrant. 7 * You should assume the locks are *not* re-entrant.
8 */ 8 */
9 9
10 #ifndef RE2_UTIL_MUTEX_H_ 10 #ifndef RE2_UTIL_MUTEX_H_
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 inline void ReaderLock(); // Block until free or shared then acquire a share 69 inline void ReaderLock(); // Block until free or shared then acquire a share
70 inline void ReaderUnlock(); // Release a read share of this Mutex 70 inline void ReaderUnlock(); // Release a read share of this Mutex
71 inline void WriterLock() { Lock(); } // Acquire an exclusive lock 71 inline void WriterLock() { Lock(); } // Acquire an exclusive lock
72 inline void WriterUnlock() { Unlock(); } // Release a lock from WriterLock() 72 inline void WriterUnlock() { Unlock(); } // Release a lock from WriterLock()
73 inline void AssertHeld() { } 73 inline void AssertHeld() { }
74 74
75 private: 75 private:
76 MutexType mutex_; 76 MutexType mutex_;
77 77
78 // Catch the error of writing Mutex when intending MutexLock. 78 // Catch the error of writing Mutex when intending MutexLock.
79 Mutex(Mutex *ignored) {} 79 Mutex(Mutex *ignored);
80 // Disallow "evil" constructors 80 // Disallow "evil" constructors
81 Mutex(const Mutex&); 81 Mutex(const Mutex&);
82 void operator=(const Mutex&); 82 void operator=(const Mutex&);
83 }; 83 };
84 84
85 // Now the implementation of Mutex for various systems 85 // Now the implementation of Mutex for various systems
86 #if defined(NO_THREADS) 86 #if defined(NO_THREADS)
87 87
88 // When we don't have threads, we can be either reading or writing, 88 // When we don't have threads, we can be either reading or writing,
89 // but not both. We can have lots of readers at once (in no-threads 89 // but not both. We can have lots of readers at once (in no-threads
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 // Disallow "evil" constructors 182 // Disallow "evil" constructors
183 WriterMutexLock(const WriterMutexLock&); 183 WriterMutexLock(const WriterMutexLock&);
184 void operator=(const WriterMutexLock&); 184 void operator=(const WriterMutexLock&);
185 }; 185 };
186 186
187 // Catch bug where variable name is omitted, e.g. MutexLock (&mu); 187 // Catch bug where variable name is omitted, e.g. MutexLock (&mu);
188 #define MutexLock(x) COMPILE_ASSERT(0, mutex_lock_decl_missing_var_name) 188 #define MutexLock(x) COMPILE_ASSERT(0, mutex_lock_decl_missing_var_name)
189 #define ReaderMutexLock(x) COMPILE_ASSERT(0, rmutex_lock_decl_missing_var_name) 189 #define ReaderMutexLock(x) COMPILE_ASSERT(0, rmutex_lock_decl_missing_var_name)
190 #define WriterMutexLock(x) COMPILE_ASSERT(0, wmutex_lock_decl_missing_var_name) 190 #define WriterMutexLock(x) COMPILE_ASSERT(0, wmutex_lock_decl_missing_var_name)
191 191
192 // Provide safe way to declare and use global, linker-initialized mutex. Sigh.
193 #ifdef HAVE_PTHREAD
194
195 #define GLOBAL_MUTEX(name) \
196 static pthread_mutex_t (name) = PTHREAD_MUTEX_INITIALIZER
197 #define GLOBAL_MUTEX_LOCK(name) \
198 pthread_mutex_lock(&(name))
199 #define GLOBAL_MUTEX_UNLOCK(name) \
200 pthread_mutex_unlock(&(name))
201
202 #else
203
204 #define GLOBAL_MUTEX(name) \
205 static Mutex name
206 #define GLOBAL_MUTEX_LOCK(name) \
207 name.Lock()
208 #define GLOBAL_MUTEX_UNLOCK(name) \
209 name.Unlock()
210
211 #endif
212
192 } // namespace re2 213 } // namespace re2
193 214
194 #endif /* #define RE2_UTIL_MUTEX_H_ */ 215 #endif /* #define RE2_UTIL_MUTEX_H_ */
OLDNEW
« no previous file with comments | « third_party/re2/util/logging.h ('k') | third_party/re2/util/sparse_array.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698